Ejemplo n.º 1
0
        /// <summary>
        /// Perform the game's update logic.
        /// </summary>
        /// <param name="gameTime">Game time information.</param>
        /// <param name="otherScreenHasFocus">Whether another screen has the focus currently.</param>
        /// <param name="coveredByOtherScreen">Whether this screen is covered by another screen.</param>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            if (!Guide.IsVisible && gameStateHandler != null && !gameStateHandler.IsGameOver)
            {
                gameStateHandler.SetScoreDice(diceHandler.GetHoldingDice());

                diceHandler.Update();

                if (gameStateHandler.IsInitialized && gameStateHandler.CurrentPlayer != null &&
                    !gameStateHandler.IsWaitingForPlayer)
                {
                    if (!(gameStateHandler.CurrentPlayer is AIPlayer))
                    {
                        gameStateHandler.CurrentPlayer.PerformPlayerLogic();
                    }
                    else
                    {
                        if (timer == null)
                        {
                            timer = new Timer(MakeAIPlay, gameStateHandler.CurrentPlayer, random.Next(300, 600), -1);
                        }
                    }
                }
            }

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Move dice that are tapped.
        /// </summary>
        /// <param name="sample">Input gesture performed.</param>
        private void HandleDiceHandlerInput(GestureSample sample)
        {
            if (DiceHandler.Rolls < 3)
            {
                Dice[] rollingDice = DiceHandler.GetRollingDice();
                Dice[] holdingDice = DiceHandler.GetHoldingDice();

                if (sample.GestureType == GestureType.Tap)
                {
                    // Create the touch rectangle
                    Rectangle touchRect = new Rectangle((int)sample.Position.X - 5, (int)sample.Position.Y - 5, 10, 10);

                    for (int i = 0; i < DiceHandler.DiceAmount; i++)
                    {
                        // Check for intersection between the touch rectangle and any of the dice
                        if ((rollingDice != null && rollingDice[i] != null &&
                             !rollingDice[i].IsRolling && rollingDice[i].Intersects(touchRect)) ||
                            (holdingDice != null && holdingDice[i] != null && holdingDice[i].Intersects(touchRect)))
                        {
                            DiceHandler.MoveDice(i);
                            if (DiceHandler.GetHoldingDice() == null)
                            {
                                GameStateHandler.SelectScore(null);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Draw the score currently selected by the player.
        /// </summary>
        /// <param name="spriteBatch">The <see cref="SpriteBatch"/> to use when drawing.</param>
        private void DrawSelectedScore(SpriteBatch spriteBatch)
        {
            if (GameStateHandler != null && GameStateHandler.IsScoreSelect)
            {
                Dice[] holdingDice = DiceHandler.GetHoldingDice();
                if (holdingDice != null)
                {
                    // Calculate the score and the position
                    byte selectedScore =
                        GameStateHandler.CombinationScore(GameStateHandler.SelectedScore.Value, holdingDice);
                    string text =
                        GameStateHandler.ScoreTypesNames[(int)GameStateHandler.SelectedScore.Value - 1].ToUpper();
                    Vector2 position = new Vector2(score.Position.X, roll.Position.Y);
                    position.Y += roll.Texture.Height + 10;
                    Vector2 measure = YachtGame.Font.MeasureString(text);
                    position.X += score.Texture.Bounds.Center.X - measure.X / 2;
                    spriteBatch.DrawString(YachtGame.Font, text, position, Color.White);

                    text        = selectedScore.ToString();
                    position.Y += measure.Y;
                    measure     = YachtGame.Font.MeasureString(text);
                    position.X  = score.Position.X;
                    position.X += score.Texture.Bounds.Center.X - measure.X / 2;
                    spriteBatch.DrawString(YachtGame.Font, text, position, Color.White);
                }
            }
        }
Ejemplo n.º 4
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;
            }
        }