/// <summary> /// Handle the "Score" button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void score_Click(object sender, EventArgs e) { if (GameStateHandler != null && GameStateHandler.IsScoreSelect) { GameStateHandler.FinishTurn(); AudioManager.PlaySoundRandom("Pencil", 3); DiceHandler.Reset(GameStateHandler.IsGameOver); } }
/// <summary> /// Performs the AI player's game logic, based on its current state. /// </summary> public override void PerformPlayerLogic() { // State machine for handling the AI player behavior. switch (State) { case AIState.Roll: // Roll the dice DiceHandler.Roll(); State = AIState.Rolling; break; case AIState.Rolling: // Wait for the dice to stop rolling if (!DiceHandler.DiceRolling()) { State = AIState.ChooseDice; } break; case AIState.ChooseDice: // Hold one of the dice DiceHandler.MoveDice(random.Next(0, 5)); // Randomly move on to selecting the score, or hold another die if (DiceHandler.GetHoldingDice() != null && random.Next(0, 5) == 1) { State = AIState.SelectScore; } break; case AIState.SelectScore: // Select an unused score line if (GameStateHandler.SelectScore((YachtCombination)random.Next(1, 13))) { State = AIState.WriteScore; } break; case AIState.WriteScore: // If a valid score was selected then write the score if (GameStateHandler != null && GameStateHandler.IsScoreSelect) { GameStateHandler.FinishTurn(); DiceHandler.Reset(GameStateHandler.IsGameOver); State = AIState.Roll; } break; default: break; } }