2021-08-13 20:39:37 +00:00
|
|
|
package game
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (gm *Game) changeGameState(expectedState, newState, newPhase string) error {
|
|
|
|
gm.mu.Lock()
|
|
|
|
defer gm.mu.Unlock()
|
|
|
|
|
2021-08-14 11:21:53 +00:00
|
|
|
if expectedState != STATE_ANY && gm.state != expectedState {
|
2022-03-16 08:16:40 +00:00
|
|
|
return fmt.Errorf("%s game state \"%s\" != expected state \"%s\"", gm.id, gm.state, expectedState)
|
2021-08-13 20:39:37 +00:00
|
|
|
}
|
|
|
|
gm.state = newState
|
|
|
|
gm.phase = newPhase
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gm *Game) changeGamePhase(expectedState, expectedPhase, newPhase string) error {
|
|
|
|
gm.mu.Lock()
|
|
|
|
defer gm.mu.Unlock()
|
|
|
|
|
2021-08-14 11:21:53 +00:00
|
|
|
if expectedState != STATE_ANY && gm.state != expectedState {
|
2022-03-16 08:16:40 +00:00
|
|
|
return fmt.Errorf("%s game state \"%s\" != expected state \"%s\"", gm.id, gm.state, expectedState)
|
2021-08-13 20:39:37 +00:00
|
|
|
}
|
|
|
|
if gm.phase != expectedPhase {
|
2022-03-16 08:16:40 +00:00
|
|
|
return fmt.Errorf("%s game phase \"%s\" != expected phase \"%s\"", gm.id, gm.phase, expectedPhase)
|
2021-08-13 20:39:37 +00:00
|
|
|
}
|
|
|
|
gm.phase = newPhase
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|