diff options
author | Santo Cariotti <santo@dcariotti.me> | 2025-04-27 11:15:11 +0200 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2025-04-27 12:24:40 +0200 |
commit | 85a6b4c2915fbfb42978fd7d2e3f7bd67e650314 (patch) | |
tree | eb705d5b97bb515d806049176df149890355e6e9 /pkg/ui/views/game_api.go | |
parent | 6a60cc1c133ccf42dae8498fc40cc3276fc91561 (diff) |
Co-op mode with next player randomly
Diffstat (limited to 'pkg/ui/views/game_api.go')
-rw-r--r-- | pkg/ui/views/game_api.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/pkg/ui/views/game_api.go b/pkg/ui/views/game_api.go index 66b63c1..32ea873 100644 --- a/pkg/ui/views/game_api.go +++ b/pkg/ui/views/game_api.go @@ -3,9 +3,12 @@ package views import ( "encoding/json" "fmt" + "math/rand" "os" + "time" "github.com/boozec/rahanna/internal/api/database" + "github.com/boozec/rahanna/pkg/p2p" tea "github.com/charmbracelet/bubbletea" "github.com/notnil/chess" ) @@ -44,6 +47,19 @@ func (m GameModel) handleDatabaseGameMsg(msg database.Game) (GameModel, tea.Cmd) } } + if myPlayerNum == 1 && m.turn == p2p.EmptyNetworkID { + // FIXME: use another way instead of sleep + time.Sleep(2 * time.Second) + if m.game.MoveChoose == database.RandomChooseType { + players := []int{1, 3} + m.turn = m.playerPeer(players[rand.Intn(len(players))]) + } else { + m.turn = m.playerPeer(1) + } + m.network.SendAll([]byte("define-turn"), []byte(string(m.turn))) + + } + if m.restore { cmd = func() tea.Msg { return RestoreGameMsg{} |