knowyt/server/src/game/startGame.go

42 lines
637 B
Go
Raw Normal View History

2021-08-12 23:07:06 +00:00
package game
2021-08-13 20:39:37 +00:00
import (
"fmt"
"time"
)
2021-08-12 23:07:06 +00:00
func (gm *Game) StartGame() {
2021-08-13 20:39:37 +00:00
go gm.startGameSub()
}
func (gm *Game) startGameSub() {
phases := []string{
"ready",
"3",
"2",
"1",
"go",
}
err := gm.changeGameState(STATE_IDLE, STATE_READY_SET, phases[0])
if err != nil {
fmt.Println(err)
return
}
2021-08-12 23:07:06 +00:00
2021-08-13 20:39:37 +00:00
for i := 1; i < len(phases); i++ {
time.Sleep(2 * time.Second)
err = gm.changeGamePhase(STATE_READY_SET, phases[i-1], phases[i])
if err != nil {
fmt.Println(err)
return
}
}
time.Sleep(3 * time.Second)
err = gm.changeGameState(STATE_READY_SET, STATE_PLAY, "")
if err != nil {
fmt.Println(err)
return
}
2021-08-12 23:07:06 +00:00
}