44 lines
672 B
Go
44 lines
672 B
Go
|
package game
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func (gm *Game) runCountdown() {
|
||
|
phases := []string{
|
||
|
"Ready?",
|
||
|
"3",
|
||
|
"2",
|
||
|
"1",
|
||
|
"Go!",
|
||
|
"",
|
||
|
}
|
||
|
|
||
|
err := gm.changeGameState(STATE_IDLE, STATE_READY_SET, phases[0])
|
||
|
if err != nil {
|
||
|
fmt.Println(err)
|
||
|
return
|
||
|
}
|
||
|
gm.notifyClients()
|
||
|
time.Sleep(2000 * time.Millisecond)
|
||
|
|
||
|
for i := 1; i < len(phases); i++ {
|
||
|
err = gm.changeGamePhase(STATE_READY_SET, phases[i-1], phases[i])
|
||
|
if err != nil {
|
||
|
fmt.Println(err)
|
||
|
return
|
||
|
}
|
||
|
gm.notifyClients()
|
||
|
time.Sleep(1500 * time.Millisecond)
|
||
|
}
|
||
|
|
||
|
err = gm.changeGameState(STATE_READY_SET, STATE_PLAY, PHASE_NONE)
|
||
|
if err != nil {
|
||
|
fmt.Println(err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
gm.runRound()
|
||
|
}
|