Exemplo n.º 1
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 == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                this.Exit();
            System.Windows.Forms.Cursor.Current = Cursors.Arrow;
            KeyboardState currentKeyboardState = Keyboard.GetState();
            MouseState mouseState = Mouse.GetState();

            if (gameStarted)
            {
                if (currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape))
                {
                    theMenu.PreviousMenuState = theMenu.MenuState;
                    theMenu.MenuState = MenuState.MainMenu;
                    theMenu.PreviousGameState = gameState;
                    GamePaused = true;
                }
                if (playerState == PlayerState.WaitingToStateHands)
                {
                    //SummaryShown = true;
                    if ((HandsStated.Count > 0) && (SummaryShown == false))
                    {
                        if (HandSummary.Count > 0)
                        {
                            SummaryShown = true;
                            theMenu.MenuState = MenuState.ShowSummary;
                            gameState = GameState.ShowMenu;
                            theMenu.PreviousGameState = GameState.RoundInProgress;
                        }

                    }
                }
                if (HandsStated.Count == 4)
                {
                    //if (SummaryShown == false)
                    //{
                        if (playerState == PlayerState.StatedHandsAndTrump)
                        {
                            // the summary is only shown if player one has also stated the trump
                            // else the last step will be missed out
                            SummaryShown = true;
                            theMenu.MenuState = MenuState.ShowSummary;
                            gameState = GameState.ShowMenu;
                            theMenu.PreviousGameState = GameState.RoundInProgress;

                      //  }
                            HandsStated.Clear();
                    }
                }
                //if (GamePaused)
                //{
                //    theMenu.MenuStrings[0] = "Resume";
                //}
                //else
                //{
                //    theMenu.MenuStrings[0] = "Start";
                //}

                if (gameState == GameState.RoundStarting)
                {
                    StartNewRound();
                }
                else if (gameState == GameState.RoundInProgress)
                {
                    if (roundState == RoundState.HandOver)
                    {
                        gameState = GameState.RoundInProgress;
                        // the round has begun again
                        roundState = RoundState.HandInProgress;
                        // clear the cards on the table
                        cardsOnTable.Clear();
                        cardsOnTableList.Clear();
                        roundState = RoundState.HandInProgress;
                        if (deck.Cards.Count == 0)
                        {
                            HandSummary.Clear();
                            gameState = GameState.ShowMenu;
                            theMenu.MenuState = MenuState.ShowScore;
                        }
                    }
                    else if (roundState == RoundState.HandInProgress)
                    {
                        if (cardsOnTable.Count < 4)
                        {
                            if (playerToPlay == PlayerIndex.One)
                            {
                                // its the human's turn, we dont need to do anything
                            }
                            else
                            {

                                switch (playerToPlay)
                                {
                                    case PlayerIndex.Four:
                                        PlaceCard(player4);
                                        playerToPlay = PlayerIndex.One;
                                        break;
                                    case PlayerIndex.Two:
                                        PlaceCard(player2);
                                        playerToPlay = PlayerIndex.Three;
                                        break;
                                    case PlayerIndex.Three:
                                        PlaceCard(player3);
                                        playerToPlay = PlayerIndex.Four;
                                        break;
                                    default:
                                        break;
                                }

                            }
                        }
                        else
                        {
                            timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds;

                            if (timeSinceLastFrame >= 1000)
                            {
                                timeSinceLastFrame = 0;
                                roundState = RoundState.CardsPlaced;
                                winningPlayer = FindPlayerToGetTheHand();
                                playerToPlay = winningPlayer;
                                switch (winningPlayer)
                                {
                                    case PlayerIndex.Four:
                                        UpdatePlayerHands(player4);
                                        break;
                                    case PlayerIndex.One:
                                        deck.HandsMade++;
                                        break;
                                    case PlayerIndex.Three:
                                        UpdatePlayerHands(player3);
                                        break;
                                    case PlayerIndex.Two:
                                        UpdatePlayerHands(player2);
                                        break;
                                    default:
                                        break;
                                }

                            }
                        }
                    }
                }
                else if (gameState == GameState.RoundOver)
                {
                    HandKeystroke = 0;
                    deck.Trump = Suit.Unspecified;

                    cardsDistributed = false;

                    deck.HandsMade = 0;
                    deck.HandsStated = 0;
                    player2.HandsMade = 0;
                    player2.HandsStated = 0;

                    player3.HandsMade = 0;
                    player3.HandsStated = 0;

                    player4.HandsMade = 0;
                    player4.HandsStated = 0;

                    gameState = GameState.RoundStarting;
                }
                else if (gameState == GameState.GameOver)
                {

                    if (currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Enter))
                    {
                        if (EnterPressed)
                        {
                            return;
                        }
                        EnterPressed = true;
                        gameState = GameState.ShowMenu;
                        theMenu.MenuState = MenuState.ShowAbout;
                    }
                    else
                    {
                        EnterPressed = false;
                    }

                    if (mouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                    {
                        if (buttonPressed)
                        {
                            return;
                        }
                        gameState = GameState.ShowMenu;
                        theMenu.MenuState = MenuState.ShowAbout;
                    }
                    else
                    {
                        buttonPressed = false;

                    }
                }
                if (gameState == GameState.RoundInProgress)
                {

                    // only if its the player's turn to play
                    if (playerToPlay == PlayerIndex.One)
                    {
                        MouseState currentMouseState = Mouse.GetState();

                        if (currentMouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                        {
                            // each time this look executes, if a button press is detected, the car flikers
                            // since it is picked up and kept down again. The buttonPressed variable is
                            // used to handle this case. If buttonPressed is true, the card position is not
                            // updated, this takes care of flickering if the button is kept pressed
                            if (!buttonPressed)
                            {
                                Card cardToRemove = null;
                                buttonPressed = true;

                                int posX, posY;
                                // the x position of the placed
                                posX = MidX;
                                posY = MidY + CARD_PLACE_OFFSET;
                                bool cardPresent = false;
                                Card playingCard ;
                                bool isClickOnCard;
                                for (int index = 0; index < deck.Cards.Count; index++)
                                {
                                    playingCard = deck.Cards[index];
                                    isClickOnCard = playingCard.IsClickOnCard(currentMouseState.X, currentMouseState.Y, deck.DistanceBetweenCards);
                                    if (!isClickOnCard)
                                    {
                                        // check for the last card
                                        if (index == deck.Cards.Count - 1)
                                        {
                                            // This is the last card (Right Most), we need to check
                                            // click on the entire card and not jst the difference
                                            // between the cards

                                            if (currentMouseState.X >= playingCard.Position.X && currentMouseState.X <= (playingCard.Position.X + CARD_WIDTH))
                                            {
                                                if (currentMouseState.Y >= playingCard.Position.Y && currentMouseState.Y <= (playingCard.Position.Y + playingCard.Image.Height))
                                                {
                                                    isClickOnCard = true;
                                                }
                                            }
                                            else
                                            {
                                                isClickOnCard = false;
                                            }

                                        }
                                    }
                                    if (isClickOnCard)
                                    {
                                        // Check if the card is of the same suit as the 1st card
                                        if (cardsOnTable.Count > 0)
                                        {
                                            Card card = cardsOnTableList[0];
                                            if (playingCard.CardSuite != card.CardSuite)
                                            {
                                                // check if no card exists in the player's deck of the suit
                                                // with which the hand has started
                                                foreach (Card cardToCheck in deck.Cards)
                                                {
                                                    if (card.CardSuite == cardToCheck.CardSuite)
                                                    {
                                                        cardPresent = true;
                                                        break;
                                                    }
                                                }
                                                if (cardPresent)
                                                {
                                                    playingCard.IsMarkedBlack = true;
                                                    playingCard.IsClicked = true;
                                                    ClickedCard = playingCard;
                                                }
                                                else
                                                {
                                                    // Place card
                                                    playingCard.Position = new Vector2(posX, posY);
                                                    // set the card to remove
                                                    cardToRemove = playingCard;
                                                    deck.PlacedCard = cardToRemove;
                                                    cardsOnTable.Add(cardToRemove, PlayerIndex.One);
                                                    cardsOnTableList.Add(cardToRemove);
                                                    playerToPlay = PlayerIndex.Two;

                                                }
                                            }
                                            else
                                            {
                                                // Place card
                                                playingCard.Position = new Vector2(posX, posY);
                                                // set the card to remove
                                                cardToRemove = playingCard;
                                                deck.PlacedCard = cardToRemove;
                                                cardsOnTable.Add(cardToRemove, PlayerIndex.One);
                                                cardsOnTableList.Add(cardToRemove);
                                                playerToPlay = PlayerIndex.Two;
                                            }
                                        }
                                        else
                                        {
                                            // Place card
                                            playingCard.Position = new Vector2(posX, posY);
                                            // set the card to remove
                                            cardToRemove = playingCard;
                                            deck.PlacedCard = cardToRemove;
                                            cardsOnTable.Add(cardToRemove, PlayerIndex.One);
                                            cardsOnTableList.Add(cardToRemove);
                                            playerToPlay = PlayerIndex.Two;
                                        }
                                        break;
                                    }
                                }

                                if (cardToRemove != null)
                                {
                                    deck.Cards.Remove(cardToRemove);
                                    playerToPlay = PlayerIndex.Two;
                                }
                            }
                        }
                        else
                        {
                            buttonPressed = false;
                            if (ClickedCard != null)
                            {
                                ClickedCard.IsClicked = false;
                            }
                        }
                    }

                }

                if (gameState == GameState.ShowMenu)
                {
                    if (theMenu.MenuState == MenuState.MainMenu)
                    {
                        if (currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Down))
                        {
                            if (downKeyPressed)
                            {
                                return;
                            }

                            downKeyPressed = true;

                            optionSelected++;
                            optionAnimationCounter = 0;

                            if (optionSelected > 3)
                            {
                                optionSelected = 0;
                            }
                        }
                        else
                        {
                            downKeyPressed = false;
                        }
                        if (currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Up))
                        {
                            if (upKeyPressed)
                            {
                                return;
                            }

                            upKeyPressed = true;

                            optionSelected--;
                            optionAnimationCounter = 0;

                            if (optionSelected < 0)
                            {
                                optionSelected = 3;
                            }
                        }
                        else
                        {
                            upKeyPressed = false;
                        }

                        if (currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Enter))
                        {
                            if (EnterPressed)
                            {
                                return;
                            }
                            EnterPressed = true;
                            switch (optionSelected)
                            {
                                case 0:
                                    //gameState = GameState.RoundStarting;
                                    //if (string.Compare(theMenu.MenuStrings[0],"Resume") == 0)
                                    //{
                                    //    //resume the game
                                    //    theMenu.MenuState = theMenu.PreviousMenuState;
                                    //    gameState = theMenu.PreviousGameState;
                                    //    GamePaused = false;
                                    //}
                                    //else
                                    //{
                                    //    theMenu.MenuState = MenuState.AskName;
                                    //}
                                    theMenu.MenuState = MenuState.AskName;
                                    gameStarted = true;
                                    break;
                                case 1:
                                    // Instructions
                                    theMenu.MenuState = MenuState.ShowInstructions;
                                    //optionSelected = 0;
                                    break;
                                case 2:
                                    // About
                                    theMenu.MenuState = MenuState.ShowAbout;
                                    //optionSelected = 0;
                                    break;
                                case 3:
                                    this.Exit();
                                    break;
                                default:
                                    break;
                            }
                        }
                        else
                        {
                            EnterPressed = false;
                        }
                        Rectangle rectCoOrdinates;
                        if (mouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                        {

                            rectCoOrdinates = theMenu.MenuStringRectangles[optionSelected];

                            if (rectCoOrdinates.X <= mouseState.X && (rectCoOrdinates.X + rectCoOrdinates.Width) >= (mouseState.X))
                            {
                                if (rectCoOrdinates.Y <= mouseState.Y && (rectCoOrdinates.Y + rectCoOrdinates.Height) >= (mouseState.Y))
                                {

                                    switch (optionSelected)
                                    {
                                        case 0:
                                            //gameState = GameState.RoundStarting;
                                            //if (string.Compare(theMenu.MenuStrings[0],"Resume") == 0)
                                            //{
                                            //    //resume the game
                                            //    theMenu.MenuState = theMenu.PreviousMenuState;
                                            //    gameState = theMenu.PreviousGameState;
                                            //    GamePaused = false;
                                            //}
                                            //else
                                            //{
                                            //    theMenu.MenuState = MenuState.AskName;
                                            //}
                                            theMenu.MenuState = MenuState.AskName;
                                            gameStarted = true;
                                            break;
                                        case 1:
                                            // Instructions
                                            theMenu.MenuState = MenuState.ShowInstructions;
                                            //optionSelected = 0;
                                            break;
                                        case 2:
                                            // About
                                            theMenu.MenuState = MenuState.ShowAbout;
                                            //optionSelected = 0;
                                            break;
                                        case 3:
                                            this.Exit();
                                            break;
                                        default:
                                            break;
                                    }
                                }
                            }

                        }
                        // Check for the mouse
                        for (int index = 0; index < theMenu.MenuStringRectangles.Count; index++)
                        {
                            rectCoOrdinates = theMenu.MenuStringRectangles[index];

                            if (rectCoOrdinates.X <= mouseState.X && (rectCoOrdinates.X + rectCoOrdinates.Width) >= (mouseState.X))
                            {
                                if (rectCoOrdinates.Y <= mouseState.Y && (rectCoOrdinates.Y + rectCoOrdinates.Height) >= (mouseState.Y))
                                {
                                    optionSelected = index;
                                    System.Windows.Forms.Cursor.Current = Cursors.Hand;
                                    break;
                                }
                            }

                        }
                    }
                    else if (theMenu.MenuState == MenuState.ShowScore)
                    {
                        // if the count is same as the round number, the scores have already been
                        // calculated
                        if (!AreScoresCalculated)
                        {
                            int score = 0;
                            AreScoresCalculated = true;
                            // Calculate score for player 2
                            player2.CalculateScore();

                            // Calculate score for player 3
                            player3.CalculateScore();

                            // Calculate score for player 4
                            player4.CalculateScore();

                            // // Calculate score for player 1
                            if (deck.HandsMade == deck.HandsStated)
                            {
                                TotalScore += deck.HandsStated * 10;
                                Scores.Add(deck.HandsStated * 10);
                            }
                            else
                            {
                                //int score;
                                if (deck.HandsStated > deck.HandsMade)
                                {
                                    score = deck.HandsMade - deck.HandsStated;
                                    score *= 5;
                                }
                                else
                                {
                                    score = 0;
                                }

                                TotalScore += (score);
                                Scores.Add(score);

                            }
                        }

                        if (currentKeyboardState.GetPressedKeys().Length != 0)
                        {
                            AreScoresCalculated = false;
                            gameState = GameState.RoundInProgress;
                            // the round has begun again
                            roundState = RoundState.HandInProgress;
                            // clear the cards on the table
                            cardsOnTable.Clear();
                            cardsOnTableList.Clear();
                            roundState = RoundState.HandInProgress;
                            if (deck.Cards.Count == 0)
                            {
                                gameState = GameState.RoundOver;
                            }
                        }

                        if (mouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                        {
                            if (buttonPressed)
                            {
                                Clicked = false;
                            }

                            AreScoresCalculated = false;
                            gameState = GameState.RoundInProgress;
                            // the round has begun again
                            roundState = RoundState.HandInProgress;
                            // clear the cards on the table
                            cardsOnTable.Clear();
                            cardsOnTableList.Clear();
                            roundState = RoundState.HandInProgress;
                            if (deck.Cards.Count == 0)
                            {
                                gameState = GameState.RoundOver;
                            }
                        }
                        else
                        {
                            buttonPressed = false;
                        }

                    }
                    else if (theMenu.MenuState == MenuState.ShowAbout)
                    {
                        if (currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Enter))
                        {
                            if (EnterPressed)
                            {
                                return;
                            }
                            EnterPressed = true;

                            theMenu.MenuState = MenuState.MainMenu;

                        }
                        else
                        {
                            EnterPressed = false;
                        }

                        if (Clicked)
                        {
                            theMenu.MenuState = MenuState.MainMenu;
                        }

                    }
                    else if (theMenu.MenuState == MenuState.ShowInstructions)
                    {
                        int speed = 10;
                        if (currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Enter))
                        {
                            if (EnterPressed)
                            {
                                return;
                            }
                            EnterPressed = true;

                            theMenu.MenuState = MenuState.MainMenu;

                        }
                        else
                        {
                            EnterPressed = false;
                        }

                        if (currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Down))
                        {
                            if (downKeyPressed)
                            {
                                DownKeyPressedCount++;
                                if (DownKeyPressedCount <= speed)
                                {
                                    return;
                                }
                                if (DownKeyPressedCount > speed)
                                {
                                    DownKeyPressedCount = 0;
                                }

                            }

                            downKeyPressed = true;

                            StartYInstructions -= 20;
                        }
                        else
                        {
                            downKeyPressed = false;
                            DownKeyPressedCount = 0;
                        }

                        if (currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Up))
                        {
                            if (upKeyPressed)
                            {
                                UpKeyPressedCount++;
                                if (UpKeyPressedCount <= speed)
                                {
                                    return;
                                }
                                // the count of 20 is to gradually scroll the screen
                                if (UpKeyPressedCount > speed)
                                {
                                    UpKeyPressedCount = 0;
                                }

                            }

                            upKeyPressed = true;
                            StartYInstructions += 20;
                        }
                        else
                        {
                            UpKeyPressedCount = 0;
                            upKeyPressed = false;
                        }
                    }
                    else if (theMenu.MenuState == MenuState.AskName)
                    {
                        GetKeyPressesName(currentKeyboardState);
                        if (currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Enter))
                        {
                            if (EnterPressed)
                            {
                                return;
                            }
                            if (name != string.Empty)
                            {
                                EnterPressed = true;
                                CalculateGridForScore();
                                theMenu.MenuState = MenuState.AskRounds;
                            }
                        }
                        else
                        {
                            EnterPressed = false;
                        }
                    }
                    else if (theMenu.MenuState == MenuState.AskRounds)
                    {
                        GetKeyPressesRounds(currentKeyboardState);
                        if (currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Enter))
                        {
                            if (EnterPressed)
                            {
                                return;
                            }
                            EnterPressed = true;
                            try
                            {
                                int rounds = Convert.ToInt32(Rounds);
                                if (rounds <= 13 && rounds > 0)
                                {
                                    gameState = GameState.RoundStarting;
                                    gameStarted = true;
                                    roundNumber = 13 - rounds;
                                }
                            }
                            catch (Exception)
                            {
                                // do nothing for now
                            }

                        }
                        else
                        {
                            EnterPressed = false;
                        }
                    }
                    else if (theMenu.MenuState == MenuState.AskTrump)
                    {
                        if (currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Down))
                        {
                            if (downKeyPressed)
                            {
                                return;
                            }

                            downKeyPressed = true;

                            optionSelected++;

                            if (optionSelected > 3)
                            {
                                optionSelected = 0;
                            }
                        }
                        else
                        {
                            downKeyPressed = false;
                        }

                        if (currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Up))
                        {
                            if (upKeyPressed)
                            {
                                return;
                            }

                            upKeyPressed = true;

                            optionSelected--;
                            if (optionSelected < 0)
                            {
                                optionSelected = 3;
                            }
                        }
                        else
                        {
                            upKeyPressed = false;
                        }

                        if (currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D1)
                            || currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.NumPad1))
                        {
                            optionSelected = 0;
                        }

                        if (currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D2)
                            || currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.NumPad1))
                        {
                            optionSelected = 1;
                        }

                        if (currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D3)
                            || currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.NumPad3))
                        {
                            optionSelected = 2;
                        }

                        if (currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D4)
                            || currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.NumPad4))
                        {
                            optionSelected = 3;
                        }

                        if (currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Enter))
                        {
                            if (EnterPressed)
                            {
                                return;
                            }

                            EnterPressed = true;
                            if (optionSelected != -1)
                            {
                                playerState = PlayerState.StatedHandsAndTrump;
                                gameState = GameState.RoundStarting;
                                switch (optionSelected)
                                {
                                    case 0:
                                        trump = Suit.Hearts;
                                        HandSummary.Add(name + " stated the maximum hands.");
                                        HandSummary.Add("Hence, " + name + " chose the trump which is Hearts.");
                                        break;
                                    case 1:
                                        trump = Suit.Diamonds;
                                        HandSummary.Add(name + " stated the maximum hands.");
                                        HandSummary.Add("Hence, " + name + " chose the trump which is Diamonds.");
                                        break;
                                    case 2:
                                        trump = Suit.Clubs;
                                        HandSummary.Add(name + " stated the maximum hands.");
                                        HandSummary.Add("Hence, " + name + " chose the trump which is Clubs.");
                                        break;
                                    case 3:
                                        trump = Suit.Spades;
                                        HandSummary.Add(name + " stated the maximum hands.");
                                        HandSummary.Add("Hence, " + name + " chose the trump which is Spades.");
                                        break;
                                    default:
                                        break;
                                }
                            }

                        }
                        else
                        {
                            EnterPressed = false;
                        }
                        Rectangle rectCoOrdinates;
                        for (int index = 0; index < theMenu.TrumpStringRectangles.Count; index++)
                        {
                            rectCoOrdinates = theMenu.TrumpStringRectangles[index];

                            if (rectCoOrdinates.X <= mouseState.X && (rectCoOrdinates.X + rectCoOrdinates.Width) >= (mouseState.X))
                            {
                                if (rectCoOrdinates.Y <= mouseState.Y && (rectCoOrdinates.Y + rectCoOrdinates.Height) >= (mouseState.Y))
                                {
                                    optionSelected = index;
                                    System.Windows.Forms.Cursor.Current = Cursors.Hand;
                                    break;
                                }
                            }

                        }

                        if (Clicked)
                        {
                            rectCoOrdinates = theMenu.TrumpStringRectangles[optionSelected];

                            if (rectCoOrdinates.X <= mouseState.X && (rectCoOrdinates.X + rectCoOrdinates.Width) >= (mouseState.X))
                            {
                                if (rectCoOrdinates.Y <= mouseState.Y && (rectCoOrdinates.Y + rectCoOrdinates.Height) >= (mouseState.Y))
                                {
                                    playerState = PlayerState.StatedHandsAndTrump;
                                    gameState = GameState.RoundStarting;
                                    switch (optionSelected)
                                    {
                                        case 0:
                                            trump = Suit.Hearts;
                                            HandSummary.Add(name + " stated the maximum hands.");
                                            HandSummary.Add("Hence, " + name + " chose the trump which is Hearts.");
                                            break;
                                        case 1:
                                            trump = Suit.Diamonds;
                                            HandSummary.Add(name + " stated the maximum hands.");
                                            HandSummary.Add("Hence, " + name + " chose the trump which is Diamonds.");
                                            break;
                                        case 2:
                                            trump = Suit.Clubs;
                                            HandSummary.Add(name + " stated the maximum hands.");
                                            HandSummary.Add("Hence, " + name + " chose the trump which is Clubs.");
                                            break;
                                        case 3:
                                            trump = Suit.Spades;
                                            HandSummary.Add(name + " stated the maximum hands.");
                                            HandSummary.Add("Hence, " + name + " chose the trump which is Spades.");
                                            break;
                                        default:
                                            break;
                                    }
                                }
                            }
                        }
                    }
                    else if (theMenu.MenuState == MenuState.AskHands)
                    {
                        if (currentKeyboardState.GetPressedKeys().Length != 0)
                        {
                            switch (currentKeyboardState.GetPressedKeys()[0])
                            {
                                case Microsoft.Xna.Framework.Input.Keys.NumPad0:
                                case Microsoft.Xna.Framework.Input.Keys.D0:
                                    HandKeystroke = 0;
                                    break;
                                case Microsoft.Xna.Framework.Input.Keys.NumPad1:
                                case Microsoft.Xna.Framework.Input.Keys.D1:
                                    HandKeystroke = 1;
                                    break;
                                case Microsoft.Xna.Framework.Input.Keys.NumPad2:
                                case Microsoft.Xna.Framework.Input.Keys.D2:
                                    HandKeystroke = 2;
                                    break;
                                case Microsoft.Xna.Framework.Input.Keys.NumPad3:
                                case Microsoft.Xna.Framework.Input.Keys.D3:
                                    HandKeystroke = 3;
                                    break;
                                case Microsoft.Xna.Framework.Input.Keys.NumPad4:
                                case Microsoft.Xna.Framework.Input.Keys.D4:
                                    HandKeystroke = 4;
                                    break;
                                case Microsoft.Xna.Framework.Input.Keys.NumPad5:
                                case Microsoft.Xna.Framework.Input.Keys.D5:
                                    HandKeystroke = 5;
                                    break;
                                case Microsoft.Xna.Framework.Input.Keys.NumPad6:
                                case Microsoft.Xna.Framework.Input.Keys.D6:
                                    HandKeystroke = 6;
                                    break;
                                case Microsoft.Xna.Framework.Input.Keys.NumPad7:
                                case Microsoft.Xna.Framework.Input.Keys.D7:
                                    HandKeystroke = 7;
                                    break;
                                case Microsoft.Xna.Framework.Input.Keys.NumPad8:
                                case Microsoft.Xna.Framework.Input.Keys.D8:
                                    HandKeystroke = 8;
                                    break;
                                case Microsoft.Xna.Framework.Input.Keys.NumPad9:
                                case Microsoft.Xna.Framework.Input.Keys.D9:
                                    HandKeystroke = 9;
                                    break;
                                //case Keys.C:
                                //    if (CheckIfEligibleForTrumpChange(HandKeystroke))
                                //    {
                                //        theMenu.MenuState = MenuState.AskTrump;
                                //    }

                                    //break;
                                default:
                                    break;
                            }

                            if (playerToStart == PlayerIndex.Two)
                            {
                                // we only need to check for the total hands and number of cards
                                // condition if the player is the last one to state the hands

                                int totalHands = player2.HandsStated + player3.HandsStated +
                                    player4.HandsStated + HandKeystroke;

                                if (totalHands == deck.Cards.Count)
                                {
                                    AreHandsValid = false;
                                }
                                else
                                {
                                    AreHandsValid = true;
                                }

                            }

                            if (currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Enter))
                            {
                                if (EnterPressed)
                                {
                                    return;
                                }
                                EnterPressed = true;

                                if (AreHandsValid)
                                {
                                    gameState = GameState.RoundStarting;
                                    playerState = PlayerState.StatedHands;
                                    deck.HandsStated = HandKeystroke;
                                    HandSummary.Add(name + " stated " + HandKeystroke + " hands.");
                                    HandsStated.Add(HandKeystroke);
                                    SummaryShown = false;
                                }

                            }
                            else
                            {
                                EnterPressed = false;
                            }

                            if (Clicked)
                            {
                                if (AreHandsValid)
                                {
                                    gameState = GameState.RoundStarting;
                                    playerState = PlayerState.StatedHands;
                                    deck.HandsStated = HandKeystroke;
                                    HandSummary.Add(name + " stated " + HandKeystroke + " hands.");
                                    HandsStated.Add(HandKeystroke);
                                    SummaryShown = false;
                                }

                            }

                        }
                    }
                    else if (theMenu.MenuState == MenuState.ShowSummary)
                    {
                        if (currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Enter))
                        {
                            if (EnterPressed)
                            {
                                return;
                            }
                            EnterPressed = true;
                            if (theMenu.PreviousGameState == GameState.RoundInProgress)
                            {
                                gameState = GameState.RoundStarting;
                            }
                            else
                            {
                                theMenu.MenuState = theMenu.PreviousMenuState;
                            }

                        }
                        else
                        {
                            EnterPressed = false;
                        }

                        if (mouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                        {
                            if (buttonPressed)
                            {
                                Clicked = false;
                            }

                            if (AreHandsValid)
                            {
                                if (theMenu.PreviousGameState == GameState.RoundInProgress)
                                {
                                    gameState = GameState.RoundStarting;
                                }
                                else
                                {
                                    theMenu.MenuState = theMenu.PreviousMenuState;
                                }
                            }
                        }
                        else
                        {
                            buttonPressed = false;
                        }

                    }
                }

                base.Update(gameTime);
            }
        }
Exemplo n.º 2
0
        public Judgement()
        {
            graphics = new GraphicsDeviceManager(this);
            graphics.PreferredBackBufferWidth = BOARD_WIDTH;
            graphics.PreferredBackBufferHeight = BOARD_HEIGHT;
            graphics.IsFullScreen = false;

            Clicked = false;
            trump = Suit.Unspecified;
            deck = new Deck();
            deck.DistanceBetweenCards = 25;
            // turn on the mouse cursor
            this.IsMouseVisible = true;

            Rounds = "13";
            name = string.Empty;
            HandsStated = new List<int>();
            HandSummary = new List<string>();
            Content.RootDirectory = "Content";
            MidX = (BOARD_WIDTH / 2) - (CARD_WIDTH / 2);
            MidY = (BOARD_HEIGHT / 2) - (CARD_HEIGHT / 2);

            GamePaused = false;
            YourTurnDisplayCount = 0;
            UpKeyPressedCount = 0;
            DownKeyPressedCount = 0;
            SummaryLineIndex = 0;
            ClickedCard = null;
            cardsOnTableList = new List<Card>();
            //cardsOnTable = new Dictionary<Card, PlayerIndex>();
            cardsOnTable = new OrderedDictionary();
            downKeyPressed = false;

            gameStarted = true;
            playerToPlay = PlayerIndex.Two;
            roundState = RoundState.HandOver;
            timeSinceLastFrame = 0;
            AreHandsValid = true;
            cardsDistributed = false;
            //playerToStart = PlayerIndex.Four;
            IsEligibleForTrumpChange = false;
            SummaryShown = false;

            StartYInstructions = 20;
            AreScoresCalculated = false;

            optionSelected = 0;
            optionAnimationCounter = 0;
            PlayerNames = new List<string>();
            Scores = new List<int>();
            TotalScore = 0; // set the total score to 0
            listOfNames = new List<string>();
            listOfNames.Add("Ashwani");
            listOfNames.Add("Rahul");
            listOfNames.Add("Bhakti");
            listOfNames.Add("Akshay");
            listOfNames.Add("Sanhita");
            listOfNames.Add("Nishij");
            listOfNames.Add("Amol");
            listOfNames.Add("Prajyot");
            listOfNames.Add("Prachiti");
            listOfNames.Add("Ajit");
            listOfNames.Add("Ravi");
            listOfNames.Add("Sonia");
            listOfNames.Add("Sayli");
            listOfNames.Add("Aman");
            listOfNames.Add("Sonal");
            listOfNames.Add("Anita");
            listOfNames.Add("Prasad");
            listOfNames.Add("Vikram");
            listOfNames.Add("Sagar");
            listOfNames.Add("Sachin");
            listOfNames.Add("Shweta");
        }
Exemplo n.º 3
0
        private void FillCompleteDeck()
        {
            Card tempCard;

            List<Card> tempList = new List<Card>();
            for (int rankIndex = 0; rankIndex < 13; rankIndex++)
            {
                for (int suitIndex = 0; suitIndex < 4; suitIndex++)
                {
                    tempCard = new Card();
                    tempCard.CardSuite = (Suit)suitIndex;
                    tempCard.RankOfCard = (Rank)rankIndex;
                    tempList.Add(tempCard);
                }
            }
            deck.Cards = tempList;
        }
Exemplo n.º 4
0
        private void RemoveCard(Card cardToRemove)
        {
            if (cardToRemove.CardSuite == Trump)
            {
                TrumpCards.Remove(cardToRemove);
            }
            else
            {
                List<Card> tempList = null;
                switch (cardToRemove.CardSuite)
                {
                    case Suit.Spades:
                        tempList = Spades;
                        break;
                    case Suit.Hearts:
                        tempList = Hearts;
                        break;
                    case Suit.Diamonds:
                        tempList = Diamonds;
                        break;
                    case Suit.Clubs:
                        tempList = Clubs;
                        break;
                    default:
                        break;
                }
                if (tempList != null)
                {
                    tempList.Remove(cardToRemove);
                }
            }

            Cards.Remove(cardToRemove);
        }