示例#1
0
        public void PokerGameSession_Validate_Card_Deck_Created()
        {
            PokerSessionGame newGame = CreatePokerGame();

            Assert.NotNull(newGame.gameCardDeck);
            Assert.AreEqual(newGame.gameCardDeck.cardDeck.Count, CardDeck.DeckSize);
        }
示例#2
0
        protected void EvaluateHands_OnClick(object sender, EventArgs e)
        {
            PokerSession     pokerSession = (PokerSession)Session["PokerSession"];
            List <Player>    gameWinners;
            PokerSessionGame currentGame    = pokerSession.gamesPlayed.Where(g => g.isActive).SingleOrDefault();
            string           strgameWinners = string.Empty;

            try
            {
                gameWinners = PokerHandEvaluator.EvaluateHands(pokerSession.sessionPlayers);

                lblCompHand.Text   = EnumHelper.GetDescription(pokerSession.sessionPlayers[0].hand.handCombination);
                lblPlayerHand.Text = EnumHelper.GetDescription(pokerSession.sessionPlayers[1].hand.handCombination);

                foreach (Player winner in gameWinners)
                {
                    strgameWinners = strgameWinners + winner.name + ", ";
                }
                strgameWinners        = strgameWinners.Remove(strgameWinners.LastIndexOf(','));
                lblDisplayWinner.Text = "Game Winner/s: " + strgameWinners;

                currentGame.winningHand = EnumHelper.GetDescription(gameWinners.First().hand.handCombination);
                currentGame.gameWinner  = strgameWinners;
                currentGame.isActive    = false;

                btnEvaluateHands.Visible = false;
                btnNewGame.Visible       = true;

                gvSessionStats.DataSource = pokerSession.gamesPlayed;
                gvSessionStats.DataBind();

                for (int i = 1; i <= 5; i++)
                {
                    Button btnComputerRedraw = (Button)ucComputerHand.FindControl("btnRedraw" + i);
                    Button btnPlayerRedraw   = (Button)ucPlayerHand.FindControl("btnRedraw" + i);

                    btnComputerRedraw.Enabled = btnPlayerRedraw.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                // General exception catch
                lblDisplayError.Text = "Error occured: " + ex.Message;
            }
        }
示例#3
0
        private void StartGame()
        {
            try
            {
                PokerSession currentPokerSession = (PokerSession)Session["PokerSession"];

                PokerSessionGame newPokerGame = new PokerSessionGame();
                currentPokerSession.gamesPlayed.Add(newPokerGame);
                newPokerGame.gameNumber = currentPokerSession.gamesPlayed.Count;

                // Draw the initial 5 cards for each player
                foreach (Player player in currentPokerSession.sessionPlayers)
                {
                    player.hand = new PokerHand(newPokerGame);
                }

                // Display drawn hands
                ucComputerHand.hand = currentPokerSession.sessionPlayers[0].hand;
                ucPlayerHand.hand   = currentPokerSession.sessionPlayers[1].hand;

                ucComputerHand.DisplayPokerHand();
                ucPlayerHand.DisplayPokerHand();

                // Assign current game to user control
                ucComputerHand.currentGame = ucPlayerHand.currentGame = newPokerGame;

                for (int i = 1; i <= 5; i++)
                {
                    Button btnComputerRedraw = (Button)ucComputerHand.FindControl("btnRedraw" + i);
                    Button btnPlayerRedraw   = (Button)ucPlayerHand.FindControl("btnRedraw" + i);

                    btnComputerRedraw.Visible = btnPlayerRedraw.Visible = true;
                    btnComputerRedraw.Enabled = btnPlayerRedraw.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                // General exception catch
                lblDisplayError.Text = "Error occured: " + ex.Message;
            }
        }
示例#4
0
        protected void btnRedraw_Click(object sender, EventArgs e)
        {
            // Get the order number of the card to redraw
            Button senderButton = (Button)sender;
            string buttonID     = senderButton.ID;
            int    sortOrder    = Convert.ToInt32(buttonID.Substring(buttonID.Length - 1, 1));

            PokerSession     pokerSession = (PokerSession)Session["PokerSession"];
            PokerSessionGame currentGame  = pokerSession.gamesPlayed.Where(g => g.isActive).FirstOrDefault();

            Card drawnCard = currentGame.gameCardDeck.GetCardsFromDeck(1)[0];

            // Redraw from computer hand
            if (senderButton.Parent.ID.ToLower().Contains("computer"))
            {
                pokerSession.sessionPlayers[0].hand.cardHands[sortOrder - 1] = drawnCard;
                this.hand = pokerSession.sessionPlayers[0].hand;
            }
            else if (senderButton.Parent.ID.ToLower().Contains("player"))
            {
                pokerSession.sessionPlayers[1].hand.cardHands[sortOrder - 1] = drawnCard;
                this.hand = pokerSession.sessionPlayers[1].hand;
            }

            senderButton.Visible = false;
            this.hand.redrawCount++;

            if (this.hand.redrawCount == 3)
            {
                for (int i = 1; i <= 5; i++)
                {
                    this.FindControl("btnRedraw" + i).Visible = false;
                }
            }

            DisplayPokerHand();
        }