diff options
author | Santo Cariotti <santo@dcariotti.me> | 2025-04-24 13:53:54 +0200 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2025-04-24 13:53:54 +0200 |
commit | b35829071ab0d0f3479021eac151b90e49a2fca5 (patch) | |
tree | 0e2af88ed2732e2211ffbf5689488e010174783a /pkg/ui/views/game_util.go | |
parent | 4ae96a216eb50ccec7712fa9ed0d4dc8d9950f68 (diff) |
Play co-op 2 vs 2
Diffstat (limited to 'pkg/ui/views/game_util.go')
-rw-r--r-- | pkg/ui/views/game_util.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/pkg/ui/views/game_util.go b/pkg/ui/views/game_util.go index f5e4a5d..8b8c658 100644 --- a/pkg/ui/views/game_util.go +++ b/pkg/ui/views/game_util.go @@ -3,6 +3,7 @@ package views import ( "fmt" + "github.com/boozec/rahanna/internal/api/database" "github.com/boozec/rahanna/pkg/p2p" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" @@ -27,7 +28,22 @@ func (m GameModel) buildWindowContent(content string, formWidth int) string { } func (m GameModel) isMyTurn() bool { - return m.turn%2 == 0 && m.network.Me() == m.playerPeer(1) || m.turn%2 == 1 && m.network.Me() == m.playerPeer(2) + if m.game == nil { + return false + } + + var totalPlayers int + + switch m.game.Type { + case database.SingleGameType: + totalPlayers = 2 + case database.PairGameType: + totalPlayers = 4 + } + + moves := len(m.chessGame.Moves()) + currentPlayer := (moves % totalPlayers) + 1 + return m.network.Me() == m.playerPeer(currentPlayer) } func (m GameModel) playerPeer(n int) p2p.NetworkID { |