knowyt/server/src/game/startGame.go

50 lines
788 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)
2021-08-14 11:21:53 +00:00
err = gm.changeGameState(STATE_READY_SET, STATE_PLAY, PHASE_NONE)
if err != nil {
fmt.Println(err)
return
}
}
func (gm *Game) ResetGame() {
err := gm.changeGameState(STATE_ANY, STATE_IDLE, PHASE_NONE)
2021-08-13 20:39:37 +00:00
if err != nil {
fmt.Println(err)
return
}
2021-08-12 23:07:06 +00:00
}