Пример #1
0
        /// <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;
            }
        }
Пример #2
0
        /// <summary>
        /// Handle the human player's input.
        /// </summary>
        public override void PerformPlayerLogic()
        {
            // Enable or disable buttons
            roll.Enabled  = DiceHandler.Rolls != 3 && !DiceHandler.DiceRolling();
            score.Enabled = GameStateHandler != null && GameStateHandler.IsScoreSelect;

            for (int i = 0; i < input.Gestures.Count; i++)
            {
                roll.HandleInput(input.Gestures[i]);
                score.HandleInput(input.Gestures[i]);
                HandleDiceHandlerInput(input.Gestures[i]);
                HandleSelectScoreInput(input.Gestures[i]);
            }

            HandleShakeInput();
        }