summaryrefslogtreecommitdiff
path: root/pkg/ui/views/game.go
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2025-04-27 11:15:11 +0200
committerSanto Cariotti <santo@dcariotti.me>2025-04-27 12:24:40 +0200
commit85a6b4c2915fbfb42978fd7d2e3f7bd67e650314 (patch)
treeeb705d5b97bb515d806049176df149890355e6e9 /pkg/ui/views/game.go
parent6a60cc1c133ccf42dae8498fc40cc3276fc91561 (diff)
Co-op mode with next player randomly
Diffstat (limited to 'pkg/ui/views/game.go')
-rw-r--r--pkg/ui/views/game.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/pkg/ui/views/game.go b/pkg/ui/views/game.go
index 64e463b..12f4fcb 100644
--- a/pkg/ui/views/game.go
+++ b/pkg/ui/views/game.go
@@ -32,7 +32,7 @@ type GameModel struct {
network *multiplayer.GameNetwork
chessGame *chess.Game
incomingMoves chan multiplayer.GameMove
- turn int
+ turn p2p.NetworkID
availableMovesList list.Model
}
@@ -61,7 +61,6 @@ func NewGameModel(width, height int, currentGameID int, network *multiplayer.Gam
network: network,
chessGame: chess.NewGame(chess.UseNotation(chess.UCINotation{})),
incomingMoves: make(chan multiplayer.GameMove),
- turn: 0,
availableMovesList: moveList,
restore: restore,
}
@@ -104,6 +103,12 @@ func (m GameModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.userID, m.err = getUserID()
m, cmd = m.handleDatabaseGameMsg(msg)
cmds = append(cmds, cmd, m.updateMovesListCmd())
+ case SaveTurnMsg:
+ m, cmd = m.handleSaveTurnMsg(msg)
+ cmds = append(cmds, cmd)
+ case SendNewTurnMsg:
+ m, cmd = m.handleDefineTurnMsg()
+ cmds = append(cmds, cmd)
case EndGameMsg:
if msg.abandoned {
_ = m.getGame()()
@@ -136,7 +141,7 @@ func (m GameModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.network.SendAll([]byte("new-move"), []byte(moveStr))
m.err = nil
}
- cmds = append(cmds, m.getMoves(), m.updateMovesListCmd())
+ cmds = append(cmds, m.getMoves(), m.updateMovesListCmd(), m.sendNewTurnCmd())
if m.chessGame.Outcome() != chess.NoOutcome {
cmds = append(cmds, m.endGame(m.chessGame.Outcome().String(), false))