Beispiel #1
0
        //Attacking phase for human players
        public virtual void Attacking(CenterCards gameCenter, Card attackingCard)
        {
            CardList gameCenterList = new CardList();


            for (int i = 0; i < gameCenter.length(); i++)
            {
                gameCenterList.Add(gameCenter.GetCard(i));
            }



            switch (gameCenter.length())
            {
            case 0:


                gameCenter.CardToCenter(attackingCard);
                getHand().RemoveCardFromHand(attackingCard);

                break;

            case 2:
                if (attackingCard.getCardRank() == gameCenterList[0].rank | attackingCard.getCardRank() == gameCenterList[1].rank)
                {
                    gameCenter.CardToCenter(attackingCard);
                    getHand().RemoveCardFromHand(attackingCard);

                    break;
                }
                break;

            case 4:
                if (attackingCard.getCardRank() == gameCenterList[0].rank | attackingCard.getCardRank() == gameCenterList[1].rank | attackingCard.getCardRank() == gameCenterList[2].rank | attackingCard.getCardRank() == gameCenterList[3].rank)
                {
                    gameCenter.CardToCenter(attackingCard);
                    getHand().RemoveCardFromHand(attackingCard);
                    break;
                }
                break;

            case 6:
                if (attackingCard.getCardRank() == gameCenterList[0].rank | attackingCard.getCardRank() == gameCenterList[1].rank | attackingCard.getCardRank() == gameCenterList[2].rank | attackingCard.getCardRank() == gameCenterList[3].rank | attackingCard.getCardRank() == gameCenterList[4].rank | attackingCard.getCardRank() == gameCenterList[5].rank)
                {
                    gameCenter.CardToCenter(attackingCard);
                    getHand().RemoveCardFromHand(attackingCard);
                    break;
                }
                break;

            case 8:
                if (attackingCard.getCardRank() == gameCenterList[0].rank | attackingCard.getCardRank() == gameCenterList[1].rank | attackingCard.getCardRank() == gameCenterList[2].rank | attackingCard.getCardRank() == gameCenterList[3].rank | attackingCard.getCardRank() == gameCenterList[4].rank | attackingCard.getCardRank() == gameCenterList[5].rank)
                {
                    gameCenter.CardToCenter(attackingCard);
                    getHand().RemoveCardFromHand(attackingCard);
                    break;
                }
                break;
            }
        }
Beispiel #2
0
 public void CopyTo(CardList targetCards)
 {
     for (int index = 0; index < this.Count; index++)
     {
         targetCards[index] = this[index];
     }
 }
Beispiel #3
0
        //will add cards to players hand
        public void AddCardsToHand(CardList cards)
        {
            for (int i = 0; i < cards.Count(); i++)
            {
                playerCard.Add(cards[i]);
            }

            cardsRemaining = playerCard.Count();
        }
Beispiel #4
0
        public object Clone()
        {
            CardList newCards = new CardList();

            foreach (Card sourceCard in this)
            {
                newCards.Add((Card)sourceCard.Clone());
            }
            return(newCards);
        }
Beispiel #5
0
        //draw cards based on int value
        public CardList DrawCards(int numberOfCards)
        {
            CardList cardsdrawn = new CardList();

            for (int i = 0; i < numberOfCards; i++)
            {
                cardsdrawn.Add(cards.ElementAt(0));
                cards.RemoveAt(0);
            }

            return(cardsdrawn);
        }
Beispiel #6
0
 //fetching a card based on number
 public Card GetCard(int cardNum, CardList cards)
 {
     if (cardNum >= 0 && cardNum <= 51)
     {
         return(cards[cardNum]);
     }
     else
     {
         throw (new System.ArgumentOutOfRangeException("cardNum", cardNum,
                                                       "Value must be between 0 and 51."));
     }
 }
Beispiel #7
0
        //toString displays players cards
        public String ToString(CardList cardsDrawn, int playerNumber)
        {
            String cardsDrawnString = "";

            cardsDrawnString += "\n\nDrawnCards Player " + playerNumber.ToString() + "\n";
            for (int i = 0; i < cardsDrawn.Count(); i++)
            {
                Card tempCard = cardsDrawn.GetCard(i, cardsDrawn);
                cardsDrawnString += tempCard.ToString();
                if (i != 51)
                {
                    cardsDrawnString += ", ";
                }
            }

            return(cardsDrawnString);
        }
Beispiel #8
0
 //Parameterized Constructor
 private Deck(CardList newCards)
 {
     cards = newCards;
 }
Beispiel #9
0
 //shuffle method,
 public void Shuffle(int deckSize)
 {
     if (deckSize == 52)
     {
         CardList newDeck   = new CardList();
         bool[]   assigned  = new bool[52];
         Random   sourceGen = new Random();
         for (int i = 0; i < 52; i++)
         {
             int  sourceCard = 0;
             bool foundCard  = false;
             while (foundCard == false)
             {
                 sourceCard = sourceGen.Next(52);
                 if (assigned[sourceCard] == false)
                 {
                     foundCard = true;
                 }
             }
             assigned[sourceCard] = true;
             newDeck.Add(cards[sourceCard]);
         }
         newDeck.CopyTo(cards);
     }
     else if (deckSize == 36)
     {
         CardList newDeck   = new CardList();
         bool[]   assigned  = new bool[36];
         Random   sourceGen = new Random();
         for (int i = 0; i < 36; i++)
         {
             int  sourceCard = 0;
             bool foundCard  = false;
             while (foundCard == false)
             {
                 sourceCard = sourceGen.Next(36);
                 if (assigned[sourceCard] == false)
                 {
                     foundCard = true;
                 }
             }
             assigned[sourceCard] = true;
             newDeck.Add(cards[sourceCard]);
         }
         newDeck.CopyTo(cards);
     }
     else if (deckSize == 20)
     {
         CardList newDeck   = new CardList();
         bool[]   assigned  = new bool[20];
         Random   sourceGen = new Random();
         for (int i = 0; i < 20; i++)
         {
             int  sourceCard = 0;
             bool foundCard  = false;
             while (foundCard == false)
             {
                 sourceCard = sourceGen.Next(20);
                 if (assigned[sourceCard] == false)
                 {
                     foundCard = true;
                 }
             }
             assigned[sourceCard] = true;
             newDeck.Add(cards[sourceCard]);
         }
         newDeck.CopyTo(cards);
     }
 }
Beispiel #10
0
        //will refill player hand
        public void RefillHand(Deck deck)
        {
            CardList cards = deck.DrawCards(6 - hand.length());

            hand.AddCardsToHand(cards);
        }
Beispiel #11
0
        //Defending phase for human players
        public virtual void DefendingPhase(CenterCards gameCenter, Card trumpCard, Card defendingCard)
        {
            //Card defendingCard = new Card();
            CardList gameCenterList    = new CardList();
            bool     sucessfulldefense = false;



            for (int i = 0; i < gameCenter.length(); i++)
            {
                gameCenterList.Add(gameCenter.GetCard(i));
            }



            switch (gameCenter.length())
            {
            case 1:


                if (defendingCard.getCardSuit() == gameCenterList[0].suit & defendingCard > gameCenterList[0] | defendingCard.getCardSuit() == trumpCard.getCardSuit() & defendingCard > gameCenterList[0])
                {
                    gameCenter.CardToCenter(defendingCard);
                    getHand().RemoveCardFromHand(defendingCard);
                    sucessfulldefense = true;
                    break;
                }


                break;

            case 3:


                if (defendingCard.getCardSuit() == gameCenterList[2].suit & defendingCard > gameCenterList[2] | defendingCard.getCardSuit() == trumpCard.getCardSuit() & defendingCard > gameCenterList[2])
                {
                    gameCenter.CardToCenter(defendingCard);
                    getHand().RemoveCardFromHand(defendingCard);
                    sucessfulldefense = true;
                    break;
                }


                break;


            case 5:


                if (defendingCard.getCardSuit() == gameCenterList[4].suit & defendingCard > gameCenterList[4] | defendingCard.getCardSuit() == trumpCard.getCardSuit() & defendingCard > gameCenterList[4])
                {
                    gameCenter.CardToCenter(defendingCard);
                    getHand().RemoveCardFromHand(defendingCard);
                    sucessfulldefense = true;
                    break;
                }


                break;

            case 7:


                if (defendingCard.getCardSuit() == gameCenterList[6].suit & defendingCard > gameCenterList[6] | defendingCard.getCardSuit() == trumpCard.getCardSuit() & defendingCard > gameCenterList[6])
                {
                    gameCenter.CardToCenter(defendingCard);
                    getHand().RemoveCardFromHand(defendingCard);
                    sucessfulldefense = true;
                    break;
                }


                break;
            }
        }
Beispiel #12
0
 //parameterized constructor
 private PlayerCard(CardList newPlayerHand)
 {
     playerCard = newPlayerHand;
 }
Beispiel #13
0
 //parameriterized constructor
 private CenterCards(CardList newGameCenter)
 {
     gameCenter = newGameCenter;
 }
Beispiel #14
0
        //ComputerAttacking method
        public void Attacking(CenterCards gameCenter)
        {
            Card attackingCard = new Card();

            CardList gameCenterList = new CardList();

            bool sucessfullattack = false;

            for (int i = 0; i < gameCenter.length(); i++)
            {
                gameCenterList.Add(gameCenter.GetCard(i));
            }


            switch (gameCenter.length())
            {
            case 0:
                //AI chooses a card
                for (int i = 0; i < getHand().length(); i++)
                {
                    attackingCard = getHand().ChooseCardFromHand(i);

                    gameCenter.CardToCenter(attackingCard);
                    getHand().RemoveCardFromHand(attackingCard);
                    sucessfullattack = true;
                    break;
                }
                break;

            case 2:
                //AI chooses a card
                for (int i = 0; i < getHand().length(); i++)
                {
                    attackingCard = getHand().ChooseCardFromHand(i);

                    if (attackingCard.getCardRank() == gameCenterList[0].rank | attackingCard.getCardRank() == gameCenterList[1].rank)
                    {
                        gameCenter.CardToCenter(attackingCard);
                        getHand().RemoveCardFromHand(attackingCard);
                        sucessfullattack = true;
                        break;
                    }
                }
                break;

            case 4:
                //AI chooses a card
                for (int i = 0; i < getHand().length(); i++)
                {
                    attackingCard = getHand().ChooseCardFromHand(i);

                    if (attackingCard.getCardRank() == gameCenterList[0].rank | attackingCard.getCardRank() == gameCenterList[1].rank | attackingCard.getCardRank() == gameCenterList[2].rank | attackingCard.getCardRank() == gameCenterList[3].rank)
                    {
                        gameCenter.CardToCenter(attackingCard);
                        getHand().RemoveCardFromHand(attackingCard);
                        sucessfullattack = true;
                        break;
                    }
                }
                break;

            case 6:
                //AI chooses a card
                for (int i = 0; i < getHand().length(); i++)
                {
                    attackingCard = getHand().ChooseCardFromHand(i);

                    if (attackingCard.getCardRank() == gameCenterList[0].rank | attackingCard.getCardRank() == gameCenterList[1].rank | attackingCard.getCardRank() == gameCenterList[2].rank | attackingCard.getCardRank() == gameCenterList[3].rank | attackingCard.getCardRank() == gameCenterList[4].rank | attackingCard.getCardRank() == gameCenterList[5].rank)
                    {
                        gameCenter.CardToCenter(attackingCard);
                        getHand().RemoveCardFromHand(attackingCard);
                        sucessfullattack = true;
                        break;
                    }
                }
                break;

            case 8:
                //AI chooses a card
                for (int i = 0; i < getHand().length(); i++)
                {
                    attackingCard = getHand().ChooseCardFromHand(i);

                    if (attackingCard.getCardRank() == gameCenterList[0].rank | attackingCard.getCardRank() == gameCenterList[1].rank | attackingCard.getCardRank() == gameCenterList[2].rank | attackingCard.getCardRank() == gameCenterList[3].rank | attackingCard.getCardRank() == gameCenterList[4].rank | attackingCard.getCardRank() == gameCenterList[5].rank)
                    {
                        gameCenter.CardToCenter(attackingCard);
                        getHand().RemoveCardFromHand(attackingCard);
                        sucessfullattack = true;
                        break;
                    }
                }
                break;
            }


            if (sucessfullattack == false && gameCenter.length() == 0 | gameCenter.length() == 2 | gameCenter.length() == 4 | gameCenter.length() == 6 | gameCenter.length() == 8)
            {
                setIsDefending(true);
            }
        }
Beispiel #15
0
        //ComputerDefendingPhase method
        public void DefendingPhase(CenterCards gameCenter, Card trumpCard)
        {
            Card     defendingCard     = new Card();
            CardList gameCenterList    = new CardList();
            bool     sucessfulldefense = false;

            //int computerInput = 0;

            for (int i = 0; i < gameCenter.length(); i++)
            {
                gameCenterList.Add(gameCenter.GetCard(i));
            }

            switch (gameCenter.length())
            {
            case 1:
                //AI chooses a card
                for (int i = 0; i < getHand().length(); i++)
                {
                    defendingCard = getHand().ChooseCardFromHand(i);

                    if (defendingCard.getCardSuit() == gameCenterList[0].suit & defendingCard > gameCenterList[0] | defendingCard.getCardSuit() == trumpCard.getCardSuit() & defendingCard > gameCenterList[0])
                    {
                        gameCenter.CardToCenter(defendingCard);
                        getHand().RemoveCardFromHand(defendingCard);
                        sucessfulldefense = true;
                        break;
                    }
                }
                break;

            case 3:
                //AI chooses a card
                for (int i = 0; i < getHand().length(); i++)
                {
                    defendingCard = getHand().ChooseCardFromHand(i);

                    if (defendingCard.getCardSuit() == gameCenterList[2].suit & defendingCard > gameCenterList[2] | defendingCard.getCardSuit() == trumpCard.getCardSuit() & defendingCard > gameCenterList[2])
                    {
                        gameCenter.CardToCenter(defendingCard);
                        getHand().RemoveCardFromHand(defendingCard);
                        sucessfulldefense = true;
                        break;
                    }
                }
                break;


            case 5:
                //AI chooses a card
                for (int i = 0; i < getHand().length(); i++)
                {
                    defendingCard = getHand().ChooseCardFromHand(i);

                    if (defendingCard.getCardSuit() == gameCenterList[4].suit & defendingCard > gameCenterList[4] | defendingCard.getCardSuit() == trumpCard.getCardSuit() & defendingCard > gameCenterList[4])
                    {
                        gameCenter.CardToCenter(defendingCard);
                        getHand().RemoveCardFromHand(defendingCard);
                        sucessfulldefense = true;
                        break;
                    }
                }
                break;

            case 7:
                //AI chooses a card
                for (int i = 0; i < getHand().length(); i++)
                {
                    defendingCard = getHand().ChooseCardFromHand(i);

                    if (defendingCard.getCardSuit() == gameCenterList[6].suit & defendingCard > gameCenterList[6] | defendingCard.getCardSuit() == trumpCard.getCardSuit() & defendingCard > gameCenterList[6])
                    {
                        gameCenter.CardToCenter(defendingCard);
                        getHand().RemoveCardFromHand(defendingCard);
                        sucessfulldefense = true;
                        break;
                    }
                }
                break;
            }

            if (sucessfulldefense == false && gameCenter.length() == 1 | gameCenter.length() == 3 | gameCenter.length() == 5 | gameCenter.length() == 7)
            {
                setIsDefending(false);
            }
        }