Ejemplo n.º 1
0
        /// <summary>
        /// Updates the state of the game. This method checks the GameScreen.IsActive
        /// property, so the game will stop updating when the pause menu is active,
        /// or if you tab away to a different application.
        /// </summary>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                    bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);

            if (IsActive)
            {
                SimpleArcCamera.Update(gameTime);
                if (fallingPieceFrame > 0)
                {
                    fallingPieceFrame--;
                    if (fallingPieceFrame <= 0)
                    {
                        AudioManager.PlayCue("Drop");
                    }
                }
                if (fallingPieceFrame <= 0)
                {
                    player1.Update(board);
                    if (board.PieceCount > lastPieceCount)
                    {
                        lastPieceCount    = board.PieceCount;
                        fallingPieceFrame = fallingPieceFrames;
                    }
                }
                if (fallingPieceFrame <= 0)
                {
                    player2.Update(board);
                    if (board.PieceCount > lastPieceCount)
                    {
                        lastPieceCount    = board.PieceCount;
                        fallingPieceFrame = fallingPieceFrames;
                    }
                }
                if (board.GameOver)
                {
                    GameResult gameResult = GameResult.Tied;
                    if (board.WhitePieceCount > board.BlackPieceCount)
                    {
                        gameResult = GameResult.Player1Won;
                    }
                    else if (board.BlackPieceCount > board.WhitePieceCount)
                    {
                        gameResult = GameResult.Player2Won;
                    }
                    ExitScreen();
                    ScreenManager.AddScreen(new GameOverScreen(gameResult));
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            // Move to the previous menu entry?
            if (input.MenuUp)
            {
                AudioManager.PlayCue("Menu_Accept");
                selectedEntry--;

                if (selectedEntry < 0)
                {
                    selectedEntry = menuEntries.Count - 1;
                }
            }

            // Move to the next menu entry?
            if (input.MenuDown)
            {
                AudioManager.PlayCue("Menu_Accept");
                selectedEntry++;

                if (selectedEntry >= menuEntries.Count)
                {
                    selectedEntry = 0;
                }
            }

            // Accept or cancel the menu?
            if (input.MenuSelect)
            {
                OnSelectEntry(selectedEntry);
            }
            else if (input.MenuCancel)
            {
                OnCancel();
            }
        }
Ejemplo n.º 3
0
        public override void Update(Board board)
        {
            // safety check the parameter
            if (board == null)
            {
                throw new ArgumentNullException("board");
            }
            // quit now if it's not my turn
            if (board.CurrentColor != BoardColor)
            {
                return;
            }

            // check if we have a valid move
            if (checkValidMove)
            {
                if (board.HasValidMove(BoardColor))
                {
                    checkValidMove = false;                     // already checked, waiting for selection
                }
                else
                {
                    board.Pass(BoardColor);
                }
            }

            // if we don't have any input, don't bother
            if (inputState == null)
            {
                return;
            }

            // apply selection-movement input and generate a desired movement
            Point cursorMovement = new Point(0, 0);
            float degrees        = (int)SimpleArcCamera.Rotation % 360 - 180;

            if (Math.Abs(degrees) < 45)
            {
                if (inputState.IsPieceSelectionUp(playerIndex))
                {
                    cursorMovement.Y--;
                }
                if (inputState.IsPieceSelectionDown(playerIndex))
                {
                    cursorMovement.Y++;
                }
                if (inputState.IsPieceSelectionLeft(playerIndex))
                {
                    cursorMovement.X--;
                }
                if (inputState.IsPieceSelectionRight(playerIndex))
                {
                    cursorMovement.X++;
                }
            }
            else if ((degrees >= 45) && (degrees < 135))
            {
                if (inputState.IsPieceSelectionUp(playerIndex))
                {
                    cursorMovement.X++;
                }
                if (inputState.IsPieceSelectionDown(playerIndex))
                {
                    cursorMovement.X--;
                }
                if (inputState.IsPieceSelectionLeft(playerIndex))
                {
                    cursorMovement.Y--;
                }
                if (inputState.IsPieceSelectionRight(playerIndex))
                {
                    cursorMovement.Y++;
                }
            }
            else if (Math.Abs(degrees) >= 135)
            {
                if (inputState.IsPieceSelectionUp(playerIndex))
                {
                    cursorMovement.Y++;
                }
                if (inputState.IsPieceSelectionDown(playerIndex))
                {
                    cursorMovement.Y--;
                }
                if (inputState.IsPieceSelectionLeft(playerIndex))
                {
                    cursorMovement.X++;
                }
                if (inputState.IsPieceSelectionRight(playerIndex))
                {
                    cursorMovement.X--;
                }
            }
            else if ((degrees > -135) && (degrees <= -45))
            {
                if (inputState.IsPieceSelectionUp(playerIndex))
                {
                    cursorMovement.X--;
                }
                if (inputState.IsPieceSelectionDown(playerIndex))
                {
                    cursorMovement.X++;
                }
                if (inputState.IsPieceSelectionLeft(playerIndex))
                {
                    cursorMovement.Y++;
                }
                if (inputState.IsPieceSelectionRight(playerIndex))
                {
                    cursorMovement.Y--;
                }
            }
            // check for valid move and apply
            if (board.IsValidSpace(cursorPosition.X + cursorMovement.X,
                                   cursorPosition.Y + cursorMovement.Y))
            {
                cursorPosition.X += cursorMovement.X;
                cursorPosition.Y += cursorMovement.Y;
            }

            // apply play-piece input
            if (inputState.IsPlayPiece(playerIndex))
            {
                Move move = new Move(cursorPosition.X, cursorPosition.Y);
                if (board.IsValidMove(BoardColor, move))
                {
                    board.ApplyMove(BoardColor, move);
                    checkValidMove = true;
                }
                else
                {
                    AudioManager.PlayCue("Drop_Illegal");
                }
            }
        }