knowyt/server/src/game/continueGame.go

61 lines
1.1 KiB
Go
Raw Normal View History

2021-08-30 16:21:14 +00:00
package game
import (
"fmt"
2021-09-03 19:53:58 +00:00
"time"
2021-08-30 16:21:14 +00:00
)
func (gm *Game) ContinueGame() {
state, phase := gm.GetState()
if state != STATE_PLAY {
fmt.Printf("invalid state, can't continue game in %s state\n", state)
return
}
switch phase {
case PHASE_SELECT_QUOTE:
gm.proceedToReveal()
default:
fmt.Printf("invalid state, can't continue game in %s state, %s phase\n", state, phase)
return
}
}
func (gm *Game) proceedToReveal() {
if !gm.allPlayersHaveSelectedAQuote() {
fmt.Println("not all players have selected a quote yet")
return
}
2021-09-04 23:51:10 +00:00
if err := gm.changeGamePhase(STATE_PLAY, PHASE_SELECT_QUOTE, PHASE_REVEAL_START); err != nil {
2021-08-30 16:21:14 +00:00
fmt.Println(err)
return
}
2021-09-03 19:53:58 +00:00
gm.notifyClients()
time.Sleep(1 * time.Second)
2021-08-30 16:21:14 +00:00
2021-09-04 23:51:10 +00:00
if err := gm.changeGamePhase(STATE_PLAY, PHASE_REVEAL_START, PHASE_REVEAL_SHOW_COUNT); err != nil {
2021-09-03 19:53:58 +00:00
fmt.Println(err)
return
}
2021-08-30 16:21:14 +00:00
gm.notifyClients()
}
func (gm *Game) allPlayersHaveSelectedAQuote() bool {
gm.mu.Lock()
defer gm.mu.Unlock()
for id, playerInfo := range gm.players {
if !playerInfo.isPlaying || playerInfo.isIdle {
continue
}
if len(gm.round.selections[id]) == 0 {
return false
}
}
return true
}