Ejemplo n.º 1
0
        /// <summary>
        /// This function dispalys the results of the game
        /// </summary>
        /// <param name="winnerText"></param>
        private void Results(string winnerText)
        {
            //Flip the first card of the dealer
            dealerHand[0].FlipOver();

            //Display the message for the winner
            winnerMessage = new Message(winnerText, messageFont, winnerMessageLocation);
            messages.Add(winnerMessage);

            //Display the score for the dealer
            dealerScoreMessage = new Message(ScoreMessagePrefix + GetBlockjuckScore(dealerHand).ToString(),
                                             messageFont, dealerScoreLocation);
            messages.Add(dealerScoreMessage);

            //Remove the stand and hit button to replace with quit
            menuButtons.Clear();

            //Add quit menu button to the list to update display options
            quitMenuButton = new MenuButton(quitButtonSprite, quitMenuLocation, GameState.Exiting);
            menuButtons.Add(quitMenuButton);

            //Change state
            currentState = GameState.DisplayingHandResults;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // create and shuffle deck
            deck = new Deck(Content, WindowHeight / 2, WindowWidth / 2);
            deck.Shuffle();

            // first player card
            Card card1Player = deck.TakeTopCard();

            card1Player.FlipOver();
            card1Player.X = HorizontalCardOffset;
            card1Player.Y = TopCardOffset;
            playerHand.Add(card1Player);

            // first dealer card
            Card card1Dealer = deck.TakeTopCard();

            card1Dealer.X = WindowWidth - HorizontalCardOffset;
            card1Dealer.Y = TopCardOffset;
            dealerHand.Add(card1Dealer);

            // second player card
            Card card2Player = deck.TakeTopCard();

            card2Player.FlipOver();
            card2Player.X = HorizontalCardOffset;
            card2Player.Y = TopCardOffset + VerticalCardSpacing;
            playerHand.Add(card2Player);

            // second dealer card
            Card card2Dealer = deck.TakeTopCard();

            card2Dealer.FlipOver();
            card2Dealer.X = WindowWidth - HorizontalCardOffset;
            card2Dealer.Y = TopCardOffset + VerticalCardSpacing;
            dealerHand.Add(card2Dealer);

            // load sprite font, create message for player score and add to list
            messageFont        = Content.Load <SpriteFont>(@"fonts\Arial24");
            playerScoreMessage = new Message(ScoreMessagePrefix + GetBlockjuckScore(playerHand).ToString(),
                                             messageFont,
                                             new Vector2(HorizontalMessageOffset, ScoreMessageTopOffset));
            messages.Add(playerScoreMessage);

            // load quit button sprite for later use
            quitButtonSprite = Content.Load <Texture2D>(@"graphics\quitbutton");

            // create hit button and add to list
            Vector2    centerHit = new Vector2(HorizontalMenuButtonOffset, VeryicalMenuButtonSpacing);
            MenuButton hitButton = new MenuButton(Content.Load <Texture2D>(@"graphics/hitbutton"), centerHit, GameState.PlayerHitting);

            menuButtons.Add(hitButton);

            // create stand button and add to list
            Vector2    centerStand = new Vector2(HorizontalMenuButtonOffset, VeryicalMenuButtonSpacing + VeryicalMenuButtonSpacing);
            MenuButton standButton = new MenuButton(Content.Load <Texture2D>(@"graphics/standbutton"), centerStand, GameState.WaitingForDealer);

            menuButtons.Add(standButton);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch    = new SpriteBatch(GraphicsDevice);
            playerHitCount = 2;
            dealerHitCount = 2;

            // create and shuffle deck
            deck = new Deck(Content, 50, 50);
            deck.Shuffle();

            // first player card
            Card playerCard1 = deck.TakeTopCard();

            playerCard1.X = HorizontalCardOffset;
            playerCard1.Y = TopCardOffset;
            playerCard1.FlipOver();
            playerHand.Add(playerCard1);

            // first dealer card. Face Down
            Card dealerCard1 = deck.TakeTopCard();

            dealerCard1.X = WindowWidth - HorizontalCardOffset;
            dealerCard1.Y = TopCardOffset;
            dealerHand.Add(dealerCard1);

            // second player card
            Card playerCard2 = deck.TakeTopCard();

            playerCard2.X = HorizontalCardOffset;
            playerCard2.Y = TopCardOffset + VerticalCardSpacing;
            playerCard2.FlipOver();
            playerHand.Add(playerCard2);

            // second dealer card
            Card dealerCard2 = deck.TakeTopCard();

            dealerCard2.X = WindowWidth - HorizontalCardOffset;
            dealerCard2.Y = TopCardOffset + VerticalCardSpacing;
            dealerCard2.FlipOver();
            dealerHand.Add(dealerCard2);

            // load sprite font, create message for player score and add to list
            messageFont        = Content.Load <SpriteFont>(@"fonts\Arial24");
            playerScoreMessage = new Message(ScoreMessagePrefix + GetBlockjuckScore(playerHand).ToString(),
                                             messageFont,
                                             new Vector2(HorizontalMessageOffset, ScoreMessageTopOffset));
            messages.Add(playerScoreMessage);

            dealerScoreMessage = new Message(ScoreMessagePrefix + GetBlockjuckScore(dealerHand).ToString(),
                                             messageFont,
                                             new Vector2(HorizontalMessageOffset, ScoreMessageTopOffset));

            // load quit button sprite for later use
            quitButtonSprite  = Content.Load <Texture2D>(@"graphics\quitbutton");
            hitButtonSprite   = Content.Load <Texture2D>(@"graphics\hitbutton");
            standButtonSprite = Content.Load <Texture2D>(@"graphics\standbutton");

            quitButtonVector = new Vector2(HorizontalMenuButtonOffset, QuitMenuButtonOffset);
            quitButton       = new MenuButton(quitButtonSprite, quitButtonVector, GameState.Exiting);

            // create hit button and add to list
            topButtonVector = new Vector2(HorizontalMenuButtonOffset, TopMenuButtonOffset);
            menuButtons.Add(new MenuButton(hitButtonSprite, topButtonVector, GameState.PlayerHitting));

            // create stand button and add to list
            bottomButtonVector = new Vector2(HorizontalMenuButtonOffset, TopMenuButtonOffset + VeryicalMenuButtonSpacing);
            menuButtons.Add(new MenuButton(standButtonSprite, bottomButtonVector, GameState.WaitingForDealer));

            outcome = "temp";
        }
Ejemplo n.º 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)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }


            // update menu buttons as appropriate
            if (currentState == GameState.WaitingForPlayer ||
                currentState == GameState.DisplayingHandResults)
            {
                foreach (MenuButton btn in menuButtons)
                {
                    btn.Update(Mouse.GetState());
                }
            }


            // game state-specific processing

            switch (currentState)
            {
            case GameState.PlayerHitting:
                Card cardPlayer = deck.TakeTopCard();
                cardPlayer.FlipOver();
                cardPlayer.X = HorizontalCardOffset;
                cardPlayer.Y = playerHand.Count * TopCardOffset + VerticalCardSpacing;
                playerHand.Add(cardPlayer);
                playerScoreMessage.Text = ScoreMessagePrefix + GetBlockjuckScore(playerHand).ToString();
                currentState            = GameState.WaitingForDealer;
                playerHit = true;
                break;

            case GameState.WaitingForDealer:
                if (GetBlockjuckScore(dealerHand) <= 16)
                {
                    currentState = GameState.DealerHitting;
                }
                else
                {
                    currentState = GameState.CheckingHandOver;
                }
                break;

            case GameState.DealerHitting:
                Card cardDealer = deck.TakeTopCard();
                cardDealer.X = WindowWidth - HorizontalCardOffset;
                cardDealer.Y = dealerHand.Count * TopCardOffset + VerticalCardSpacing;
                cardDealer.FlipOver();
                dealerHand.Add(cardDealer);
                currentState = GameState.CheckingHandOver;
                dealerHit    = true;
                break;

            case GameState.CheckingHandOver:
                if (GetBlockjuckScore(playerHand) >= MaxHandValue ||
                    GetBlockjuckScore(dealerHand) >= MaxHandValue ||
                    (!dealerHit && !playerHit))
                {
                    string winnerText;
                    if (GetBlockjuckScore(playerHand) == GetBlockjuckScore(dealerHand))
                    {
                        winnerText = "Tie!";
                    }
                    else if (GetBlockjuckScore(playerHand) <= MaxHandValue && GetBlockjuckScore(dealerHand) > MaxHandValue ||
                             GetBlockjuckScore(playerHand) <= MaxHandValue && GetBlockjuckScore(playerHand) > GetBlockjuckScore(dealerHand))
                    {
                        winnerText = "Player Won!";
                    }
                    else
                    {
                        winnerText = "Dealer Won!";
                    }

                    winnerMessage = new Message(winnerText, messageFont, winnerMessageLocation);
                    messages.Add(winnerMessage);

                    dealerHand[0].FlipOver();

                    dealerScoreMessage = new Message(ScoreMessagePrefix + GetBlockjuckScore(dealerHand).ToString(),
                                                     messageFont, new Vector2(WindowWidth - HorizontalMessageOffset, ScoreMessageTopOffset));
                    messages.Add(dealerScoreMessage);

                    menuButtons.Clear();
                    Vector2    centerQuit = new Vector2(HorizontalMenuButtonOffset, WindowHeight - VeryicalMenuButtonSpacing);
                    MenuButton quitButton = new MenuButton(Content.Load <Texture2D>(@"graphics/quitbutton"), centerQuit, GameState.Exiting);
                    menuButtons.Add(quitButton);

                    currentState = GameState.DisplayingHandResults;
                }
                else
                {
                    currentState = GameState.WaitingForPlayer;
                    dealerHit    = false;
                    playerHit    = false;
                }
                break;

            case GameState.Exiting:

                this.Exit();
                break;
            }

            base.Update(gameTime);
        }