diff options
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{} |