Exemple #1
0
        public Deck()
        {
            //Spade Heart Diamond and Club
            String t       = null;
            int    Counter = 1;

            for (int i = 1; i <= 4; i++)
            {
                if (i == 1)
                {
                    t = "Spade";
                }
                if (i == 2)
                {
                    t = "Heart";
                }
                if (i == 3)
                {
                    t = "Diamond";
                }
                if (i == 4)
                {
                    t = "Club";
                }
                slots[i - 1] = t;
                for (int n = 1; n <= 13; n++)
                {
                    Card1 card = new Card1(n, t);
                    this.cards[Counter - 1] = card;
                    Console.WriteLine(card.ToString());
                    Counter++;
                }
            }
        }
Exemple #2
0
 public bool areFollowingNum(Card1 c1, Card1 c2)
 //are the Cards one after the other
 {
     if (c1.getNum() == c2.getNum() - 1)
     {
         return(true);
     }
     return(false);
 }
Exemple #3
0
 public bool areDifferentcolors(Card1 c1, Card1 c2)
 //are the Cards diffrent colors
 {
     if ((c1.getType() == "Spade" || c1.getType() == "Club") && (c2.getType() == "Heart" || c2.getType() == "Diamond"))
     {
         return(true);
     }
     else if ((c2.getType() == "Spade" || c2.getType() == "Club") && (c1.getType() == "Heart" || c1.getType() == "Diamond"))
     {
         return(true);
     }
     return(false);
 }
Exemple #4
0
        public void removeFromSlots(PictureBox selectedC)
        {
            Console.WriteLine($"You moved {(Card1)glowingC.Tag} from the slots to under {(Card1)selectedC.Tag}");
            for (int j = 0; j < 7; j++)
            {
                if (lines[j].Contains(selectedC))
                {
                    lines[j].Add(glowingC);
                }
            }
            PictureBox tempPB = new PictureBox();

            if (((Card1)glowingC.Tag).getNum() != 1)
            {
                Card1 prevC = new Card1(((Card1)glowingC.Tag).getNum() - 1, ((Card1)glowingC.Tag).getType());
                foreach (Control PB in this.Controls)
                {
                    if (PB.Tag != null && ((PB.Tag).GetType() == typeof(Card1)) && ((Card1)PB.Tag).getType() == prevC.getType() && ((Card1)PB.Tag).getNum() == prevC.getNum())
                    {
                        tempPB = (PictureBox)PB;
                        break;
                    }
                }
                if (((Card1)glowingC.Tag).getType() == "Spade")
                {
                    slotSCount--;
                    slotSpb = tempPB;
                }
                else if (((Card1)glowingC.Tag).getType() == "Heart")
                {
                    slotHCount--;
                    slotHpb = tempPB;
                }
                else if (((Card1)glowingC.Tag).getType() == "Diamond")
                {
                    slotDCount--;
                    slotDpb = tempPB;
                }
                else if (((Card1)glowingC.Tag).getType() == "Club")
                {
                    slotCCount--;
                    slotCpb = tempPB;
                }
            }
            else
            {
                if (((Card1)selectedC.Tag).getType() == "Spade")
                {
                    slotSCount--;
                    slotSpb = null;
                }
                else if (((Card1)selectedC.Tag).getType() == "Heart")
                {
                    slotHCount--;
                    slotHpb = null;
                }
                else if (((Card1)selectedC.Tag).getType() == "Diamond")
                {
                    slotDCount--;
                    slotDpb = null;
                }
                else if (((Card1)selectedC.Tag).getType() == "Club")
                {
                    slotCCount--;
                    slotCpb = null;
                }
            }
            glowingC.Location = new Point(selectedC.Location.X, selectedC.Location.Y + 20);
            glowingC.BringToFront();
            glowingC = null;
        }
Exemple #5
0
 public Card1(Card1 c)
 {
     num  = c.num;
     type = c.type;
 }
Exemple #6
0
        public void buildDeck()
        {
            {
                dealerCounterLabel.Location = new Point(630, 30);
                dealerCounterLabel.Width    = 25;
                dealerCounterLabel.Height   = 15;
                dealerCounterLabel.Text     = "0";
                Controls.Add(dealerCounterLabel);
                movesCounterL.Location = new Point(715, 75);
                movesCounterL.Width    = 100;
                movesCounterL.Height   = 20;
                movesCounterL.Text     = $"moves: {movesCounter}";
                Controls.Add(movesCounterL);

                GoDark();
                toggleTheme.Text     = "Go Light";
                toggleTheme.Location = new Point(700, 120);
                toggleTheme.Size     = new Size(80, 40);
                toggleTheme.Click   += ToggleTheme_Click;
                Controls.Add(toggleTheme);
            } //Add Counters
            for (int i = 0; i < 7; i++)
            {
                emptyCards[i] = new PictureBox();
                Image img = Properties.Resources.emptyCard as Image;
                img = Resize(img, 86, 132);
                emptyCards[i].Size  = img.Size;
                emptyCards[i].Image = img;
                //cards[i].Tag = deck.getCard(i);
                emptyCards[i].Click   += emptyCardClick;
                emptyCards[i].Location = new Point(470 + i * 130, 300);
                Controls.Add(emptyCards[i]);
            } //Add empty cards
            for (int i = 0; i < 51; i++)
            {
                Card1 tempC   = deck.getCard(i);
                int   tempNum = rnd.Next(i, 52);
                deck.setCard(deck.getCard(tempNum), i);
                deck.setCard(tempC, tempNum);
            } //Shuffle
            for (int i = 0; i < 7; i++)
            {
                lines[i] = new List <PictureBox>();
            } //Create lines
            for (int i = 0; i < 52; i++)
            {
                cards[i] = new PictureBox();
                Image img = Properties.Resources.ResourceManager.GetObject("_" + deck.getCard(i).getNum().ToString() + deck.getCard(i).getType()[0]) as Image;
                img             = Resize(img, 86, 132);
                cards[i].Size   = img.Size;
                cards[i].Image  = img;
                cards[i].Tag    = deck.getCard(i);
                cards[i].Click += cardClick;
                if (i > 27)
                {
                    hiddenCardImg = Resize(hiddenCardImg, 86, 132);
                    dealer.Add(new PictureBox());
                    dealer[i - 28].Location = new Point(470, 50);
                    dealer[i - 28].Size     = hiddenCardImg.Size;
                    dealer[i - 28].Image    = hiddenCardImg;
                    dealer[i - 28].Tag      = cards[i];
                    dealer[i - 28].Click   += dealerClick;
                    Controls.Add(dealer[i - 28]);
                }
                else if (i < 27 && i != 0 && i != 2 && i != 5 && i != 9 && i != 14 && i != 20)
                {
                    hidCards[i] = new PictureBox();
                    Image img2 = Properties.Resources.yellow_back;
                    img2              = Resize(img2, 86, 132);
                    hidCards[i].Size  = img2.Size;
                    hidCards[i].Image = img2;
                    hidCards[i].Tag   = cards[i];
                } //Create hidden lines cards
            }     //Create PictureBoxes
            for (int i = 0; i < 28; i++)
            {
                if (i == 0)
                {
                    lines[0].Add(cards[0]);
                    lines[0][0].Location = new Point(470, 300);
                    //                    Controls.Add(lines[0][0]);
                }
                if (i == 1 || i == 2)
                {
                    if (i != 2)
                    {
                        lines[1].Add(hidCards[i]);
                    }
                    else
                    {
                        lines[1].Add(cards[i]);
                    }
                    lines[1][i - 1].Location = new Point(600, 300 + (i - 1) * 20);
                    //                    Controls.Add(lines[1][i - 1]);
                }
                if (i >= 3 && i <= 5)
                {
                    if (i != 5)
                    {
                        lines[2].Add(hidCards[i]);
                    }
                    else
                    {
                        lines[2].Add(cards[i]);
                    }
                    lines[2][i - 3].Location = new Point(730, 300 + (i - 3) * 20);
                    //                    Controls.Add(lines[2][i - 3]);
                }
                if (i >= 6 && i <= 9)
                {
                    if (i != 9)
                    {
                        lines[3].Add(hidCards[i]);
                    }
                    else
                    {
                        lines[3].Add(cards[i]);
                    }
                    lines[3][i - 6].Location = new Point(860, 300 + (i - 6) * 20);
                    //                    Controls.Add(lines[3][i - 6]);
                }
                if (i >= 10 && i <= 14)
                {
                    if (i != 14)
                    {
                        lines[4].Add(hidCards[i]);
                    }
                    else
                    {
                        lines[4].Add(cards[i]);
                    }
                    lines[4][i - 10].Location = new Point(990, 300 + (i - 10) * 20);
                    //                    Controls.Add(lines[4][i - 10]);
                }
                if (i >= 15 && i <= 20)
                {
                    if (i != 20)
                    {
                        lines[5].Add(hidCards[i]);
                    }
                    else
                    {
                        lines[5].Add(cards[i]);
                    }
                    lines[5][i - 15].Location = new Point(1120, 300 + (i - 15) * 20);
                    //                    Controls.Add(lines[5][i - 15]);
                }
                if (i >= 21 && i <= 27)
                {
                    if (i != 27)
                    {
                        lines[6].Add(hidCards[i]);
                    }
                    else
                    {
                        lines[6].Add(cards[i]);
                    }
                    lines[6][i - 21].Location = new Point(1250, 300 + (i - 21) * 20);
                    //                    Controls.Add(lines[6][i - 21]);
                }
            } //Add the PictureBoxes to the list
            for (int i = 0; i < 7; i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    Controls.Add(lines[i][j]);
                    lines[i][j].BringToFront();
                }
            } //add the lines to the form
        }
Exemple #7
0
 public void setCard(Card1 c, int i)
 {
     cards[i] = c;
 }