42 lines
637 B
Go
42 lines
637 B
Go
package game
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
func (gm *Game) StartGame() {
|
|
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
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|