Ejemplo n.º 1
0
 /// <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);
     }
 }
Ejemplo n.º 2
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;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handler called when a game state is received from the server.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ServerGameStateArrived(object sender, YachtGameStateEventArgs e)
        {
            if (gameStateHandler == null)
            {
                InitializeGameStateHandler(e.GameState);

                YachtState yachtState = (YachtState)PhoneApplicationService.Current.State[Constants.YachtStateKey];
                yachtState.NetworkManagerState = NetworkManager.Instance;

                // Update state object with the new game state
                yachtState.YachGameState = gameStateHandler.State;

                // Reset the dice state if it is not valid for this turn
                if (diceHandler.DiceState.ValidForTurn != e.GameState.StepsMade)
                {
                    diceHandler.Reset(false);
                }

                NetworkManager.Instance.ScoreCardArrived += ServerScoreCardArrived;
            }
            else
            {
                if (e.GameState.StepsMade != gameStateHandler.State.StepsMade)
                {
                    diceHandler.Reset(false);
                }

                gameStateHandler.SetState(e.GameState);
            }

            diceHandler.DiceState.ValidForTurn = gameStateHandler.State.StepsMade;

            AudioManager.PlaySoundRandom("TurnChange", 2);

            if (e.GameState.Players[e.GameState.CurrentPlayer].PlayerID == NetworkManager.Instance.playerID)
            {
                NetworkManager.Instance.GetScoreCard();
            }
        }