package game import ( "fmt" ) func (gm *Game) changeGameState(expectedState, newState, newPhase string) error { gm.mu.Lock() defer gm.mu.Unlock() if expectedState != STATE_ANY && gm.state != expectedState { return fmt.Errorf("game state \"%s\" != expected state \"%s\"", gm.state, expectedState) } gm.state = newState gm.phase = newPhase return nil } func (gm *Game) changeGamePhase(expectedState, expectedPhase, newPhase string) error { gm.mu.Lock() defer gm.mu.Unlock() if expectedState != STATE_ANY && gm.state != expectedState { return fmt.Errorf("game state \"%s\" != expected state \"%s\"", gm.state, expectedState) } if gm.phase != expectedPhase { return fmt.Errorf("game phase \"%s\" != expected phase \"%s\"", gm.phase, expectedPhase) } gm.phase = newPhase return nil }