public Crazy_Eights()
 {
     InitializeComponent();
     Crazy_Eights_Game.SetUpGame();
     tableLayoutPanels = new TableLayoutPanel[Crazy_Eights_Game.NUM_OF_PLAYERS] {
         pTableLayoutPanel, cTableLayoutPanel
     };
 }
Exemple #2
0
 private void DealBtn_Click(object sender, EventArgs e)
 {
     PlayerPanel.Enabled = true;
     DeckPB.Enabled      = true;
     Crazy_Eights_Game.SetupGame();
     DealBtn.Enabled = false;
     SortBtn.Enabled = true;
     RefreshScreen();
     InstructionText.Text = yourTurnText;
 }
Exemple #3
0
        /// <summary>
        /// Loads and displays the pictureboxes into the player table layout
        /// panel
        /// </summary>
        private void DisplayPHand()
        {
            PlayerPanel.Controls.Clear();
            Hand pHand    = Crazy_Eights_Game.GetPlayerHand();
            int  handSize = pHand.GetCount();

            for (int i = 0; i < handSize; i++)
            {
                PlayerPanel.Controls.Add(playerPBox[i]);
            }
        }
Exemple #4
0
        /// <summary>
        /// Loads and displays the pictureboxes into the computer table layout
        /// panel
        /// </summary>
        private void DisplayCHand()
        {
            CompPanel.Controls.Clear();
            Hand cHand    = Crazy_Eights_Game.GetComputerHand();
            int  handSize = cHand.GetCount();

            for (int i = 0; i < handSize; i++)
            {
                CompPanel.Controls.Add(computerPBox[i]);
            }
        }
        /// <summary>
        /// Checks if card player clicked on is valid, plays it then passes turn to CPU
        /// </summary>
        /// <param name="clickedCard"></param>
        private void TryToPlayCard(Card clickedCard)
        {
            Card discard     = Crazy_Eights_Game.CurrentDiscard();
            Suit discardSuit = discard.GetSuit();

            // check for crazy eight suit
            if (discard.GetFaceValue() == FaceValue.Eight)
            {
                discardSuit = eightsuit;
            }
            // Check if card is valid and play it
            if (Crazy_Eights_Game.IsGoodClick(clickedCard, discardSuit))
            {
                // Update GUI with new cards
                discardPile.Image = Images.GetCardImage(clickedCard);
                DisplayDrawPile();
                DisplayGuiHand(Crazy_Eights_Game.GetHand(1), pTableLayoutPanel, 1);
                //MessageBox.Show(clickedCard.ToString(false, true), "Clicked");

                // Check for empty hand after turn
                if (Crazy_Eights_Game.EmptyHand(1))
                {
                    MessageBox.Show("Player wins!", "Game Over");
                    this.Close();
                } // end if
                // CPU Go
                if (clickedCard.GetFaceValue() == FaceValue.Eight)
                {
                    using (Eight_suit eight_suit = new Eight_suit()) {
                        if (eight_suit.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            eightsuit = eight_suit.SelectedSuit;
                            //instructionLabel.Text = "Last crazy eights suit is" + eightsuit.ToString();
                        }
                        else
                        {
                            Card card = Crazy_Eights_Game.CurrentDiscard();
                            eightsuit = card.GetSuit();
                        }
                    }
                }
                CpuGo();
            }
            else
            {
                MessageBox.Show(clickedCard.ToString(false, true) + " is not a valid option.", "Clicked");
            } // end if
        }     // end TryToPlayCard
Exemple #6
0
        /// <summary>
        /// updates picture boxes for the computer based on the current
        /// computers hand
        /// </summary>
        private void UpdateCHand()
        {
            PictureBox pBox;
            Hand       cHand    = Crazy_Eights_Game.GetComputerHand();
            int        handSize = cHand.GetCount();

            for (int i = 0; i < handSize; i++)
            {
                Card card = cHand.GetCard(i);
                pBox            = new PictureBox();
                pBox.SizeMode   = PictureBoxSizeMode.AutoSize;
                pBox.Dock       = DockStyle.Fill;
                pBox.Image      = Images.GetCardImage(card);
                computerPBox[i] = pBox;
            }
        }
Exemple #7
0
        private void DeckPB_Click(object sender, EventArgs e)
        {
            bool canDraw = Crazy_Eights_Game.AddFromDeck();

            if (!canDraw)
            {
                InstructionText.Text = canDrawText;
            }
            if (canDraw)
            {
                Crazy_Eights_Game.DeckDiscardSwap();
                Crazy_Eights_Game.ComputerTurn();
            }
            Crazy_Eights_Game.DeckDiscardSwap(); //in case computer draws and now resets deck
            RefreshScreen();
        }
Exemple #8
0
        /// <summary>
        /// Updates the pictureboxes for the player with images for current
        /// players hand
        /// </summary>
        private void UpdatePHand()
        {
            PictureBox pBox;
            Hand       pHand    = Crazy_Eights_Game.GetPlayerHand();
            int        handSize = pHand.GetCount();

            for (int i = 0; i < handSize; i++)
            {
                Card card = pHand.GetCard(i);
                pBox                 = new PictureBox();
                pBox.SizeMode        = PictureBoxSizeMode.AutoSize;
                pBox.Dock            = DockStyle.Fill;
                pBox.Image           = Images.GetCardImage(card);
                playerPBox[i]        = pBox;
                playerPBox[i].Click += new EventHandler(PlayerPBox_Click);
                playerPBox[i].Tag    = Crazy_Eights_Game.GetPlayerHand().GetCard(i);
            }
        }
        } //end RefreshTheFormThenPause

        private void dealButton_Click(object sender, EventArgs e)
        {
            dealButton.Enabled = false;
            // deal 8 to each if handsize is 0, or deal 1 and pass
            if (Crazy_Eights_Game.DealStart())
            {
                for (int i = 0; i <= 7; i++)
                {
                    Crazy_Eights_Game.DealOneCardTo(0); //deals one card to dealer
                    Crazy_Eights_Game.DealOneCardTo(1); //deals one card to user
                } // end for
                  //displays images of dealer and users hands
                DisplayGuiHand(Crazy_Eights_Game.GetHand(0), cTableLayoutPanel, 0);
                DisplayGuiHand(Crazy_Eights_Game.GetHand(1), pTableLayoutPanel, 1);
                DisplayDrawPile();
                discardPile.Image = Images.GetCardImage(Crazy_Eights_Game.DealOneCard());
            }
            else
            {
                // check for max hand size, then a tied game, and deal if not
                if (!Crazy_Eights_Game.MaxHand(1))
                {
                    Crazy_Eights_Game.DealOneCardTo(1);
                    DisplayGuiHand(Crazy_Eights_Game.GetHand(1), pTableLayoutPanel, 1);
                }
                else if (Crazy_Eights_Game.MaxHand(0))
                {
                    MessageBox.Show("Neither player can play, game is a tie!", "Game Over");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Handsize limit reached, passing turn.", "Deal");
                } // end if
                // pass turn to CPU
                CpuGo();
            } // end if
        }     // end dealButton_Click
Exemple #10
0
        /// <summary>
        /// Changes the windows form based on the victory condition. Calling
        /// end game check and if it results.
        /// </summary>
        private void EndGame()
        {
            const int loss    = -1;
            const int win     = 1;
            const int tie     = 0;
            int       victory = Crazy_Eights_Game.IsEndGame();

            if (victory == loss)
            {
                RestartGame();
                MessageBox.Show(lossText);
            }
            else if (victory == tie)
            {
                RestartGame();
                MessageBox.Show(tieText);
            }
            else if (victory == win)
            {
                RestartGame();
                MessageBox.Show(victoryText);
            }
        }
        }     // end dealButton_Click

        /// <summary>
        /// Performs the CPU's turn then passes back to the player
        /// </summary>
        private void CpuGo()
        {
            RefreshTheFormThenPause();
            Card discard     = Crazy_Eights_Game.CurrentDiscard();
            Suit discardSuit = discard.GetSuit();

            // check for player selected crazy eight suit
            if (discard.GetFaceValue() == FaceValue.Eight)
            {
                discardSuit = eightsuit;
            } // end if
            // reset the discard suit for players next turn if the CPU played something
            if (Crazy_Eights_Game.ComputerTurn(discardSuit))
            {
                eightsuit   = Crazy_Eights_Game.CurrentDiscard().GetSuit();
                discardSuit = Crazy_Eights_Game.CurrentDiscard().GetSuit();
            } // end if
            // check for tied game
            if (Crazy_Eights_Game.MaxHand(1) && Crazy_Eights_Game.MaxHand(0) && !Crazy_Eights_Game.PlayerHasMove(discardSuit))
            {
                MessageBox.Show("Neither player can play, game is a tie!", "Game Over");
                this.Close();
            } // end if
            DisplayGuiHand(Crazy_Eights_Game.GetHand(0), cTableLayoutPanel, 0);
            DisplayDiscardPile();
            // Checks for empty hand after turn
            if (Crazy_Eights_Game.EmptyHand(0) && !Crazy_Eights_Game.EmptyHand(1))
            {
                MessageBox.Show("Computer Wins!", "Game Over");
                this.Close();
            } // end if
            // Pass back to player
            if (!Crazy_Eights_Game.PlayerHasMove(discardSuit))
            {
                dealButton.Enabled = true;
            } // end if
        }     // end CpuGo
Exemple #12
0
        private void PlayerPBox_Click(object sender, EventArgs e)
        {
            //Get the selected card from the picture box
            int        whichCard;
            PictureBox whichClicked = (PictureBox)sender;

            whichCard = Crazy_Eights_Game.WhichCard((Card)whichClicked.Tag);
            Card Selected = Crazy_Eights_Game.GetPlayerHand().GetCard(whichCard);

            if (Crazy_Eights_Game.IsEight(Selected)) //If the selected card is an eight, load suit selection form
            {
                SuitSelection suitSelection = new SuitSelection();
                DialogResult  result        = suitSelection.ShowDialog();
                Card          card          = new Card();
                if (result == DialogResult.OK)
                {
                    card = suitSelection.GetSelection();
                }
                Crazy_Eights_Game.PlayerTurn(Selected, card);
                Crazy_Eights_Game.ComputerTurn();
                InstructionText.Text = yourTurnText;
            }
            else
            {
                bool check = Crazy_Eights_Game.PlayerTurn(Selected);
                if (check)
                {
                    Crazy_Eights_Game.ComputerTurn();
                    InstructionText.Text = yourTurnText;
                }
                else //If no card is played, change instruction text
                {
                    InstructionText.Text = wrongCard;
                }
            }
            RefreshScreen();
        }
        /// <summary>
        /// Displays the discard pile;
        /// </summary>
        private void DisplayDiscardPile()
        {
            Card card = Crazy_Eights_Game.CurrentDiscard();

            discardPile.Image = Images.GetCardImage(card);
        }
        } // end cancelButton_Click

        private void sortButton_Click(object sender, EventArgs e)
        {
            Crazy_Eights_Game.SortHand();
            DisplayGuiHand(Crazy_Eights_Game.GetHand(1), pTableLayoutPanel, 1);
        } // end sortButton_Click
Exemple #15
0
        /// <summary>
        /// Updates the Discard deck and displays the new images
        /// </summary>
        private void UpdateDiscard()
        {
            Card card = Crazy_Eights_Game.GetTopOfDiscard();

            DiscardPB.Image = Images.GetCardImage(card);
        }
Exemple #16
0
 private void SortBtn_Click(object sender, EventArgs e)
 {
     Crazy_Eights_Game.SortPlayerHand();
     RefreshScreen();
 }
Exemple #17
0
 /// <summary>
 /// Checks if the deck is out of cards and tells crazy eights class
 /// to swap if so
 /// </summary>
 private void UpdateDeck()
 {
     Crazy_Eights_Game.DeckDiscardSwap();
 }