Beispiel #1
0
        private void CardClick(object sender, EventArgs e)
        {
            //takes the pic the Player clicked on and turns it into a new one to mess with.
            PictureBox chosen = (PictureBox)sender;

            //go through all the Player's cards, and find the one that matches the card that was clicked.
            foreach (Card card in Card.GetPlayerDeck())
            {
                if (card.CardKey == chosen.Tag.ToString())
                {
                    PlayerCardValue = card.CardValue;
                    PlayerCard      = card.CardKey;
                    break;
                }
            }

            //show the card the Player clicked in the upper corner
            pictureBoxPlayerPreview.BackgroundImage = chosen.Image;
        }
Beispiel #2
0
        private void SelectCardTest_Click(object sender, EventArgs e)
        {
            if (pictureBoxPickACard.Visible == true || pictureBoxPlayerPreview.BackgroundImage == WarCardGame.Properties.Resources.Card_Select)
            {
                MessageBox.Show("you need to pick a card, dingus");
            }

            else
            {
                Random rand     = new Random(DateTime.Now.Millisecond);
                int    Cardpick = rand.Next(0, OpponentDeckLength);


                //selects a card for your opponent to play

                if (imageListCardsOpponent.Images[Cardpick] == imageListCardsOpponent.Images[OpponentDeckLength])
                {
                    Cardpick = rand.Next(0, OpponentDeckLength);
                    //chooses a new card if it lands on the facedown; which is the last card in the image list.
                }
                else if (!(imageListCardsOpponent.Images[Cardpick] == imageListCardsOpponent.Images[OpponentDeckLength]))
                {
                    pictureBoxOpponentPreview.BackgroundImage = imageListCardsOpponent.Images[Cardpick];
                    //shows the true card
                }



                pictureBoxOpponentPreview.BackgroundImageLayout = ImageLayout.Stretch;

                label6.Text = PlayerCardValue.ToString();
                //test label. will be deleted later.


                OpponentCardValue = imageListCardsOpponent.Images.Keys[Cardpick].Substring(0, 1);
                if (imageListCardsOpponent.Images.Keys[Cardpick].Substring(0, 2) == "10")
                {
                    OpponentCardValue = "10";
                }
                if (OpponentCardValue == "A")
                {
                    OpponentCardValue = "14";
                }
                if (OpponentCardValue == "J")
                {
                    OpponentCardValue = "11";
                }
                if (OpponentCardValue == "K")
                {
                    OpponentCardValue = "12";
                }
                if (OpponentCardValue == "Q")
                {
                    OpponentCardValue = "13";
                }
                //this snippet of code takes the keys of the card images and uses the substring method
                //to calculate a value for the card instead of hardcoding it.
                //(for example- 2 of clubs -> 2_Clubs.bmp -> [2]_Clubs.bmp -> value = 2)


                label5.Text = OpponentCardValue.ToString();
                //test label, will be deleted later.


                if (int.Parse(OpponentCardValue) > PlayerCardValue)
                {
                    Score = (Score - (int.Parse(OpponentCardValue) - PlayerCardValue));
                    if (Score < 0)
                    {
                        Score = 0;
                    }
                    label2.Text = Score.ToString();


                    if (Opponent == 0)
                    {
                        pictureBoxOpponent.Image = WarCardGame.Properties.Resources.fullbody1;
                    }
                    if (Opponent == 1)
                    {
                        pictureBoxOpponent.Image = WarCardGame.Properties.Resources.fullbody2;
                    }
                    if (Opponent == 2)
                    {
                        pictureBoxOpponent.Image = WarCardGame.Properties.Resources.fullbody3Happy;
                    }
                    if (Opponent == 3)
                    {
                        pictureBoxOpponent.Image = WarCardGame.Properties.Resources.fullbody4Happy;
                    }

                    PlayerDeckLength--;
                }
                //if the Opponent has a higher value card, they win the round and the score is calculated.
                else if (int.Parse(OpponentCardValue) < PlayerCardValue)
                {
                    Score       = (Score + (PlayerCardValue - int.Parse(OpponentCardValue)));
                    label2.Text = Score.ToString();

                    if (Opponent == 0)
                    {
                        pictureBoxOpponent.Image = WarCardGame.Properties.Resources.fullbody1;
                    }
                    if (Opponent == 1)
                    {
                        pictureBoxOpponent.Image = WarCardGame.Properties.Resources.fullbody2;
                    }
                    if (Opponent == 2)
                    {
                        pictureBoxOpponent.Image = WarCardGame.Properties.Resources.fullbody3Angry;
                    }
                    if (Opponent == 3)
                    {
                        pictureBoxOpponent.Image = WarCardGame.Properties.Resources.fullbody4Angry;
                    }

                    OpponentDeckLength--;
                }
                //if the Player has a higher value card, they win the round and the score is calculated.
                //the program then deletes the opponent's card from the imagelist, or 'deck', and the calculated range for the opponent is decremented by one.
                //
                else if (int.Parse(OpponentCardValue) == PlayerCardValue)
                {
                    label2.Text = Score.ToString();

                    if (Opponent == 0)
                    {
                        pictureBoxOpponent.Image = WarCardGame.Properties.Resources.fullbody1;
                    }
                    if (Opponent == 1)
                    {
                        pictureBoxOpponent.Image = WarCardGame.Properties.Resources.fullbody2;
                    }
                    if (Opponent == 2)
                    {
                        pictureBoxOpponent.Image = WarCardGame.Properties.Resources.fullbody3;
                    }
                    if (Opponent == 3)
                    {
                        pictureBoxOpponent.Image = WarCardGame.Properties.Resources.fullbody4;
                    }

                    OpponentDeckLength--;
                }


                Card.PlayerDeckRemove(PlayerCard);
                Card.OpponentDeckRemove(OpponentCard);

                foreach (Control thing in this.Controls.OfType <PictureBox>())
                {
                    if (thing.Tag.ToString() == PlayerCard)
                    {
                        this.Controls.Remove(thing);
                    }
                }



                if (!Card.GetPlayerDeck().Any() || !Card.GetOpponentDeck().Any())
                {
                    if (PlayerDeckLength > OpponentDeckLength)
                    {
                        MessageBox.Show("WIN");
                        //if score is higher than previously listed high score, overwrite player highscore
                    }
                    else if (PlayerDeckLength < OpponentDeckLength)
                    {
                        MessageBox.Show("LOSE");
                    }
                    else
                    {
                        MessageBox.Show("DRAW");
                    }

                    //set 'last played' to current date
                    this.Close();
                }

                pictureBoxPickACard.Visible = true;
            }
        }
Beispiel #3
0
        private void SelectCardTest_Click(object sender, EventArgs e)
        {
            Random rand     = new Random(DateTime.Now.Millisecond);
            int    Cardpick = rand.Next(0, OpponentDeckLength);

            //selects a card for your opponent to play

            if (imageListCardsOpponent.Images[Cardpick] == imageListCardsOpponent.Images[OpponentDeckLength])
            {
                Cardpick = rand.Next(0, OpponentDeckLength);
                //chooses a new card if it lands on the facedown; which is the last card in the image list.
            }
            else if (!(imageListCardsOpponent.Images[Cardpick] == imageListCardsOpponent.Images[OpponentDeckLength]))
            {
                pictureBoxOpponentPreview.BackgroundImage = imageListCardsOpponent.Images[Cardpick];
                //shows the true card
            }



            pictureBoxOpponentPreview.BackgroundImageLayout = ImageLayout.Stretch;

            label6.Text = PlayerCardValue.ToString();
            //test label. will be deleted later.


            OpponentCardValue = imageListCardsOpponent.Images.Keys[Cardpick].Substring(0, 1);
            if (imageListCardsOpponent.Images.Keys[Cardpick].Substring(0, 2) == "10")
            {
                OpponentCardValue = "10";
            }
            if (OpponentCardValue == "A")
            {
                OpponentCardValue = "14";
            }
            if (OpponentCardValue == "J")
            {
                OpponentCardValue = "11";
            }
            if (OpponentCardValue == "K")
            {
                OpponentCardValue = "12";
            }
            if (OpponentCardValue == "Q")
            {
                OpponentCardValue = "13";
            }
            //this snippet of code takes the keys of the card images and uses the substring method
            //to calculate a value for the card instead of hardcoding it.
            //(for example- 2 of clubs -> 2_Clubs.bmp -> [2]_Clubs.bmp -> value = 2)


            label5.Text = OpponentCardValue.ToString();
            //test label, will be deleted later.

            if (int.Parse(OpponentCardValue) > PlayerCardValue)
            {
                label2.Text = "-" + (int.Parse(OpponentCardValue) - PlayerCardValue).ToString();

                PlayerDeckLength--;
            }
            //if the Opponent has a higher value card, they win the round and the score is calculated.
            else if (int.Parse(OpponentCardValue) < PlayerCardValue)
            {
                label2.Text = (PlayerCardValue - int.Parse(OpponentCardValue)).ToString();

                OpponentDeckLength--;
            }
            //if the Player has a higher value card, they win the round and the score is calculated.
            //the program then deletes the opponent's card from the imagelist, or 'deck', and the calculated range for the opponent is decremented by one.
            //
            else if (int.Parse(OpponentCardValue) == PlayerCardValue)
            {
                label2.Text = "DRAW";
                //the 2 lines below are only for testing

                OpponentDeckLength--;
            }


            Card.PlayerDeckRemove(PlayerCard);
            Card.OpponentDeckRemove(OpponentCard);

            foreach (Control thing in this.Controls.OfType <PictureBox>())
            {
                if (thing.Tag.ToString() == PlayerCard)
                {
                    this.Controls.Remove(thing);
                }
            }



            if (!Card.GetPlayerDeck().Any() || !Card.GetOpponentDeck().Any())
            {
                if (PlayerDeckLength > OpponentDeckLength)
                {
                    MessageBox.Show("WIN");
                    this.Close();
                }
                else if (PlayerDeckLength < OpponentDeckLength)
                {
                    MessageBox.Show("LOSE");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("DRAW");
                    this.Close();
                }
            }
        }