/// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            // update the menu buttons
            MouseState mouse = Mouse.GetState();

            flipButton.Update(mouse);
            collectWinningsButton.Update(mouse);
            quitButton.Update(mouse);

            // update based on game state
            if (gameState == GameState.Flip)
            {
                // flip cards into battle piles
                Card player1Card = player1Hand.TakeTopCard();
                player1Card.FlipOver();
                player1BattlePile.AddCard(player1Card);
                Card player2Card = player2Hand.TakeTopCard();
                player2Card.FlipOver();
                player2BattlePile.AddCard(player2Card);

                // figure out winner and show the message
                if (player1Card.WarValue > player2Card.WarValue)
                {
                    player1Message.Visible = true;
                    currentWinner          = Player.Player1;
                }
                else if (player2Card.WarValue > player1Card.WarValue)
                {
                    player2Message.Visible = true;
                    currentWinner          = Player.Player2;
                }
                else
                {
                    currentWinner = Player.None;
                }

                // adjust button visibility
                flipButton.Visible            = false;
                collectWinningsButton.Visible = true;

                // wait for players to collect winnings
                gameState = GameState.CollectWinnings;
            }
            else if (gameState == GameState.Play)
            {
                // distribute battle piles into appropriate hands and hide message
                if (currentWinner == Player.Player1)
                {
                    player1Hand.AddCards(player1BattlePile);
                    player1Hand.AddCards(player2BattlePile);
                    player1Message.Visible = false;
                }

                else if (currentWinner == Player.Player2)
                {
                    player2Hand.AddCards(player1BattlePile);
                    player2Hand.AddCards(player2BattlePile);
                    player2Message.Visible = false;
                }

                else
                {
                    player1Hand.AddCards(player1BattlePile);
                    player2Hand.AddCards(player2BattlePile);
                }

                currentWinner = Player.None;

                // set button visibility
                flipButton.Visible            = true;
                collectWinningsButton.Visible = false;

                // check for game over
                if (player1Hand.Empty)
                {
                    flipButton.Visible     = false;
                    player2Message.Visible = true;
                    gameState = GameState.GameOver;
                }

                else if (player2Hand.Empty)
                {
                    player2Message.Visible = true;
                    flipButton.Visible     = false;
                    gameState = GameState.GameOver;
                }
            }
            else if (gameState == GameState.Quit)
            {
                Exit();
            }

            base.Update(gameTime);
        }
Example #2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }
            MouseState mouse = Mouse.GetState();

            // update the menu buttons
            flipButton.Update(mouse);
            quitButton.Update(mouse);
            collectWinnings.Update(mouse);


            // update based on game state
            if (gameState == GameState.Play)
            {
                playerOneWM.Visible     = false;
                playerTwoWM.Visible     = false;
                flipButton.Visible      = true;
                collectWinnings.Visible = false;
                if (playerOneHand.Empty)
                {
                    flipButton.Visible  = false;
                    playerTwoWM.Visible = true;
                }
                else if (playerTwoHand.Empty)
                {
                    flipButton.Visible  = false;
                    playerOneWM.Visible = true;
                }
            }

            if (gameState == GameState.Flip && playerOneBP.Empty && playerTwoBP.Empty)
            {
                Card cardToAddToPlayerOne = playerOneHand.TakeTopCard();
                cardToAddToPlayerOne.FlipOver();
                playerOneBP.AddCard(cardToAddToPlayerOne);

                Card cardToAddToPlayerTwo = playerTwoHand.TakeTopCard();
                cardToAddToPlayerTwo.FlipOver();
                playerTwoBP.AddCard(cardToAddToPlayerTwo);

                if (playerOneBP.GetTopCard().WarValue > playerTwoBP.GetTopCard().WarValue)
                {
                    currentWinner       = Player.Player1;
                    playerOneWM.Visible = true;
                    playerTwoWM.Visible = false;
                }
                else if (playerOneBP.GetTopCard().WarValue < playerTwoBP.GetTopCard().WarValue)
                {
                    currentWinner       = Player.Player2;
                    playerTwoWM.Visible = true;
                    playerOneWM.Visible = false;
                }
                else
                {
                    currentWinner       = Player.None;
                    playerOneWM.Visible = false;
                    playerTwoWM.Visible = false;
                }
                flipButton.Visible      = false;
                collectWinnings.Visible = true;
            }
            if (gameState == GameState.CollectWinnings)
            {
                if (currentWinner == Player.Player1)
                {
                    playerOneHand.AddCards(playerOneBP);
                    playerOneHand.AddCards(playerTwoBP);
                }
                else if (currentWinner == Player.Player2)
                {
                    playerTwoHand.AddCards(playerOneBP);
                    playerTwoHand.AddCards(playerTwoBP);
                }
                else
                {
                    playerOneHand.AddCards(playerOneBP);
                    playerTwoHand.AddCards(playerTwoBP);
                }
                gameState = GameState.Play;
            }
            if (gameState == GameState.Quit)
            {
                this.Exit();
            }



            base.Update(gameTime);
        }
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }


            // update the menu buttons
            MouseState mouse = Mouse.GetState();

            flipCards.Update(mouse);
            collectWinnings.Update(mouse);
            quitGame.Update(mouse);

            // update based on game state
            if (gameState == GameState.Flip)
            {
                // FLIP CARDS INTO BATTLE PILES
                Card player1Card = handPlayer1.TakeTopCard();
                player1Card.FlipOver();
                pilePlayer1.AddCard(player1Card);
                Card player2Card = handPlayer2.TakeTopCard();
                player2Card.FlipOver();
                pilePlayer2.AddCard(player2Card);

                //Otherwise
                //pilePlayer1.AddCard(handPlayer1.TakeTopCard());
                //pilePlayer1.GetTopCard().FlipOver();
                //pilePlayer2.AddCard(handPlayer2.TakeTopCard());
                //pilePlayer2.GetTopCard().FlipOver();

                // FIGURE OUT WINNER AND SHOW MESSAGE

                if (player1Card.WarValue > player2Card.WarValue)
                {
                    winnerPlayer1.Visible = true;
                    currentWinner         = Player.Player1;
                }
                else if (player1Card.WarValue < player2Card.WarValue)
                {
                    winnerPlayer2.Visible = true;
                    currentWinner         = Player.Player2;
                }
                else
                {
                    currentWinner = Player.None;
                }

                // Otherwise
                //if (pilePlayer1.GetTopCard().WarValue > pilePlayer2.GetTopCard().WarValue)
                //{
                //    winnerPlayer1.Visible = true;
                //}
                //else if (pilePlayer1.GetTopCard().WarValue < pilePlayer2.GetTopCard().WarValue)
                //{
                //    winnerPlayer2.Visible = true;
                //}

                // gameState = GameState.Play;

                // adjust button visibility
                flipCards.Visible       = false;
                collectWinnings.Visible = true;

                // wait for player to collect winnings
                gameState = GameState.CollectWinnings;
            }

            else if (gameState == GameState.Play)
            {
                // distribute battle piles into appropiate hands and hide message
                if (currentWinner == Player.Player1)
                {
                    handPlayer1.AddCards(pilePlayer1);
                    handPlayer1.AddCards(pilePlayer2);
                    winnerPlayer1.Visible = false;
                }
                else if (currentWinner == Player.Player2)
                {
                    handPlayer2.AddCards(pilePlayer1);
                    handPlayer2.AddCards(pilePlayer2);
                    winnerPlayer2.Visible = false;
                }
                else
                {
                    handPlayer1.AddCards(pilePlayer1);
                    handPlayer2.AddCards(pilePlayer2);
                }
                currentWinner = Player.None;

                //Otherwise
                //if (pilePlayer1.GetTopCard().WarValue > pilePlayer2.GetTopCard().WarValue)
                //{
                //    handPlayer1.AddCards(pilePlayer1);
                //    handPlayer1.AddCards(pilePlayer2);
                //    winnerPlayer1.Visible = false;
                //}
                //else if (pilePlayer1.GetTopCard().WarValue < pilePlayer2.GetTopCard().WarValue)
                //{
                //    handPlayer2.AddCards(pilePlayer1);
                //    handPlayer2.AddCards(pilePlayer2);
                //    winnerPlayer2.Visible = false;
                //}
                //else
                //{
                //    handPlayer1.AddCards(pilePlayer1);
                //    handPlayer2.AddCards(pilePlayer2);
                //}

                // set flip button visibility
                flipCards.Visible       = true;
                collectWinnings.Visible = false;

                //gameState = GameState.Play;

                // check for game over

                if (handPlayer1.Empty || handPlayer2.Empty)
                {
                    flipCards.Visible = false;
                    gameState         = GameState.GameOver;
                    if (handPlayer1.Empty)
                    {
                        winnerPlayer2.Visible = true;
                    }
                    else
                    {
                        winnerPlayer1.Visible = true;
                    }
                }
            }

            //Otherwise
            //if (gameState == GameState.GameOver)
            //{
            //    collectWinnings.Visible = false;
            //    flipCards.Visible = false;
            //    if (handPlayer1.Empty)
            //    {
            //        winnerPlayer2.Visible = true;
            //    }
            //    else
            //    {
            //        winnerPlayer1.Visible = true;
            //    }
            //}

            else if (gameState == GameState.Quit)
            {
                Exit();
            }

            //base.Update(gameTime);
        }
Example #4
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            
            // update the menu buttons
            MouseState mouse = Mouse.GetState();
            quitButton.Update(mouse);
            flipButton.Update(mouse);
            collectButton.Update(mouse);
 
            // update based on game state
            if (gameState == GameState.Play)
            {
                flipButton.Visible = true;
                quitButton.Visible = true;
                collectButton.Visible = false;
            }


            if (gameState == GameState.Flip)
            {
                flipButton.Visible = false;
                collectButton.Visible = true;

                if (playerOnePile.Empty)
                {
                    playerOnePile.AddCard(playerOneHand.TakeTopCard());
                    playerTwoPile.AddCard(playerTwoHand.TakeTopCard());
                    playerOnePile.GetTopCard().FlipOver();
                    playerTwoPile.GetTopCard().FlipOver();
                }

                else if (playerOnePile.GetTopCard().WarValue > playerTwoPile.GetTopCard().WarValue)
                {
                    playerOneMessage.Visible = true;
                }
                else if (playerTwoPile.GetTopCard().WarValue > playerOnePile.GetTopCard().WarValue)
                {
                    playerTwoMessage.Visible = true;
                }
                else
                {
                    playerOnePile.AddCard(playerOneHand.TakeTopCard());
                    playerTwoPile.AddCard(playerTwoHand.TakeTopCard());
                    playerOnePile.GetTopCard().FlipOver();
                    playerTwoPile.GetTopCard().FlipOver();
                }
            }


            if (gameState == GameState.CollectWinnings)
            {                
                flipButton.Visible = true;
                playerOneMessage.Visible = false;
                playerTwoMessage.Visible = false;
                gameState = GameState.Play;

                if (playerOnePile.GetTopCard().WarValue > playerTwoPile.GetTopCard().WarValue)
                {
                    playerOneHand.AddCards(playerOnePile);
                    playerOneHand.AddCards(playerTwoPile);
                }
                else if (playerTwoPile.GetTopCard().WarValue > playerOnePile.GetTopCard().WarValue)
                {
                    playerTwoHand.AddCards(playerOnePile);
                    playerTwoHand.AddCards(playerTwoPile);
                }
            }

            if (gameState == GameState.CollectWinnings)
            {
                playerOneHand.AddCards(playerOnePile);
                playerTwoHand.AddCards(playerTwoPile);
            }


            
            if (gameState == GameState.Quit)
            {
                this.Exit();
            }
            
            // update game stats
            string0 = playerOneHand.Count.ToString();
            string1 = playerTwoHand.Count.ToString();
    
             base.Update(gameTime);
        }
Example #5
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }
            MouseState mouse = Mouse.GetState();

            // update the menu buttons
            flipButton.Update(mouse);
            collectButton.Update(mouse);
            quitButton.Update(mouse);

            switch (gameState)
            {
            case (GameState.Play):
                flipButton.Visible    = true;
                collectButton.Visible = false;
                playerOneWin.Visible  = false;
                playerTwoWin.Visible  = false;
                quitButton.Visible    = true;
                break;

            case (GameState.Flip):
                flipButton.Visible    = false;
                collectButton.Visible = true;
                break;

            case (GameState.Quit):
                Exit();
                break;
            }

            // update based on game state
            switch (gameState)
            {
            case (GameState.Flip):
                if (battlePile1.Empty && battlePile2.Empty)
                {
                    takeCardsForBattle();
                    while (playCard1.WarValue == playCard2.WarValue)
                    {
                        takeCardsForBattle();
                    }
                }
                if (playCard1.WarValue > playCard2.WarValue)
                {
                    //player1 win
                    playerOneWin.Visible = true;
                }
                else
                {
                    //player2 win
                    playerTwoWin.Visible = true;
                }

                break;

            case (GameState.CollectWinnings):
                if (playCard1.WarValue > playCard2.WarValue)
                {
                    player1.AddCards(battlePile1);
                    player1.AddCards(battlePile2);
                }
                else
                {
                    player2.AddCards(battlePile1);
                    player2.AddCards(battlePile2);
                }

                if (player1.Empty || player2.Empty)
                {
                    flipButton.Visible    = false;
                    collectButton.Visible = false;
                }
                else
                {
                    ChangeState(GameState.Play);
                }

                break;
            }

            base.Update(gameTime);
        }