knowyt/server/src/game/startGame.go

51 lines
800 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{
2021-08-14 12:28:38 +00:00
"5",
"4",
2021-08-13 20:39:37 +00:00
"3",
"2",
"1",
2021-08-14 12:28:38 +00:00
"Go!",
2021-08-13 20:39:37 +00:00
}
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++ {
2021-08-14 12:28:38 +00:00
time.Sleep(1500 * time.Millisecond)
2021-08-13 20:39:37 +00:00
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
}