Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //Deck testDeck = new Deck();

            //foreach (Card card in testDeck)
            //{
            //    Console.WriteLine(card.ToString());
            //}

            Deck testDeck = new Deck(36);

            foreach (Card card in testDeck)
            {
                Console.WriteLine(card.ToString());
            }

            testDeck = testDeck.Shuffle();

            Card.trump = testDeck[testDeck.Count - 1].suit;

            Console.WriteLine("");

            foreach (Card card in testDeck)
            {
                Console.WriteLine(card.ToString());
            }

            EasyPlayer compPlayer = new EasyPlayer(testDeck);

            IComputerPlayer cpuPlayer = compPlayer;

            Player testPlayer = compPlayer;

            Cards playedCards = new Cards();

            //playedCards.Add(new Card(Suit.Spade, Rank.Eight));
            //playedCards.Add(new Card(Suit.Spade, Rank.Jack));

            Console.WriteLine("");

            foreach (Card card in playedCards)
            {
                Console.WriteLine(card.ToString());
            }

            Console.WriteLine("");

            foreach (Card card in testPlayer.GetHand())
            {
                if (card.isPlayable(playedCards))
                {
                    Console.WriteLine(card.ToString() + " is playable");
                }
                else
                {
                    Console.WriteLine(card.ToString() + " is not playable");
                }
            }

            Console.WriteLine("");

            try
            {
                Console.WriteLine(cpuPlayer.selectCard(playedCards).ToString() + " was played!");
            }
            catch (OperationCanceledException e)
            {
                Console.WriteLine(e.Message);
            }

            //Console.WriteLine("");

            //foreach (Card card in testHand)
            //{
            //    Console.WriteLine(card.ToString());
            //}

            //Console.WriteLine("");

            //foreach (Card card in testDeck)
            //{
            //    Console.WriteLine(card.ToString());
            //}

            //if (testDeck[0] > testDeck[1])
            //{
            //    Console.WriteLine("Greater");
            //}
            //else
            //{
            //    Console.WriteLine("Less or equal");
            //}

            //if (testDeck[0] >= testDeck[1])
            //{
            //    Console.WriteLine("Greater or equal");
            //}
            //else
            //{
            //    Console.WriteLine("Less");
            //}

            Console.ReadKey();
        }
Exemplo n.º 2
0
        /// <summary>
        /// The event that will be wired to playable Cardboxes
        /// </summary>
        /// <param name="sender"> The object that the event is fired from </param>
        /// <param name="e"> The EventArgs object </param>
        private void Cardbox_Click(object sender, EventArgs e)
        {
            //Initialize the sender as a Cardbox
            CardBox.CardBox box = sender as CardBox.CardBox;

            //If the human player is the attacker
            if (attacker == humanPlayer)
            {
                //Add the card to the river
                river.Add(box.Card);

                //Remove the card from the player's hand
                humanPlayer.GetHand().Remove(box.Card);

                //If the player's hand is empty and the deck is empty then the human player wins
                if (humanPlayer.GetHand().Count == 0 && talon.Count == 0)
                {
                    //Show the Winner form
                    this.Hide();
                    frmWinner win = new frmWinner();
                    win.ShowDialog();
                    this.Close();
                }
                else
                {
                    try
                    {
                        //Draw a card from the computer's hand
                        Card cpuCard = cpuPlayer.selectCard(river);

                        //If the computer's hand is empty and the deck is empty then the human player loses
                        if (defender.GetHand().Count == 0 && talon.Count == 0)
                        {
                            //Show the Loser form
                            this.Hide();
                            frmLoser lose = new frmLoser();
                            lose.ShowDialog();
                            this.Close();
                        }

                        //Add the computer's card to the river
                        river.Add(cpuCard);

                        //If the number of cards in the river equals 12
                        if (river.Count == 12)
                        {
                            //The defender was successful
                            DefenceSuccess();
                        }
                    }
                    catch (OperationCanceledException)
                    {
                        //Set the human player as the cardAdder
                        cardAdder = humanPlayer;
                        attacker  = null;

                        //Move the played card to the adder
                        adder.Add(box.Card);

                        //Set the rank of the adder
                        adderRank = box.Card.rank;

                        //Remove the card from the river
                        river.Remove(box.Card);
                    }
                }
            }
            //If the human player is the defender
            else if (defender == humanPlayer)
            {
                //Add the card to the river
                river.Add(box.Card);

                //Remove the card from the player hand
                humanPlayer.GetHand().Remove(box.Card);

                //If the human player's hand is empty and the deck is empty then the human player wins
                if (humanPlayer.GetHand().Count == 0 && talon.Count == 0)
                {
                    //Show the Winner form
                    this.Hide();
                    frmWinner win = new frmWinner();
                    win.ShowDialog();
                    this.Close();
                }

                //if the river count equals 12
                if (river.Count == 12)
                {
                    //The defender was successful
                    DefenceSuccess();
                }
                else
                {
                    try
                    {
                        //Draw a card from the computer's hand
                        Card cpuCard = cpuPlayer.selectCard(river);

                        //If the computer's hand is empty and the deck is empty then the human player loses
                        if (attacker.GetHand().Count == 0 && talon.Count == 0)
                        {
                            //Show the Loser form
                            this.Hide();
                            frmLoser lose = new frmLoser();
                            lose.ShowDialog();
                            this.Close();
                        }

                        //Add the computer's card to the river
                        river.Add(cpuCard);
                    }
                    catch (OperationCanceledException)
                    {
                        //The defender was successful
                        DefenceSuccess();
                    }
                }
            }
            //If the human player is the cardAdder
            else if (cardAdder == humanPlayer)
            {
                //Add the card to the adder
                adder.Add(box.Card);

                //Remove the card from the player hand
                humanPlayer.GetHand().Remove(box.Card);

                //If the human player's hand is empty and the deck is empty then the human player wins
                if (humanPlayer.GetHand().Count == 0 && talon.Count == 0)
                {
                    //Show the Winner form
                    this.Hide();
                    frmWinner win = new frmWinner();
                    win.ShowDialog();
                    this.Close();
                }

                //If the human player has played 6 cards
                if (river.Count / 2 + adder.Count == 6)
                {
                    //The attacker was successful
                    AttackSuccess();
                }
            }

            //Redraw the form
            Redraw();
        }