Ejemplo n.º 1
0
        //Attacking phase for human players
        public virtual void AttackingPhase(GameRiver gameRiver, Card attackingCard)
        {
            CardList gameRiverList = new CardList();


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



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


                gameRiver.AddCardToRiver(attackingCard);
                getHand().RemoveCardFromHand(attackingCard);

                break;

            case 2:
                if (attackingCard.getCardRank() == gameRiverList[0].rank | attackingCard.getCardRank() == gameRiverList[1].rank)
                {
                    gameRiver.AddCardToRiver(attackingCard);
                    getHand().RemoveCardFromHand(attackingCard);

                    break;
                }
                break;

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

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

            case 8:
                if (attackingCard.getCardRank() == gameRiverList[0].rank | attackingCard.getCardRank() == gameRiverList[1].rank | attackingCard.getCardRank() == gameRiverList[2].rank | attackingCard.getCardRank() == gameRiverList[3].rank | attackingCard.getCardRank() == gameRiverList[4].rank | attackingCard.getCardRank() == gameRiverList[5].rank)
                {
                    gameRiver.AddCardToRiver(attackingCard);
                    getHand().RemoveCardFromHand(attackingCard);
                    break;
                }
                break;
            }
        }
Ejemplo n.º 2
0
 /// copyto method for copying card instances into another Cards
 /// instance—used in Deck.Shuffle(). This implementation assumes that
 /// source and target collections are the same size.
 public void CopyTo(CardList targetCards)
 {
     for (int index = 0; index < this.Count; index++)
     {
         targetCards[index] = this[index];
     }
 }
Ejemplo n.º 3
0
        //will add cards to players hand
        public void AddCardsToHand(CardList cards)
        {
            for (int i = 0; i < cards.Count(); i++)
            {
                playerHand.Add(cards[i]);
            }

            numberOfCardsRemaning = playerHand.Count();
        }
Ejemplo n.º 4
0
        public object Clone()
        {
            CardList newCards = new CardList();

            foreach (Card sourceCard in this)
            {
                newCards.Add((Card)sourceCard.Clone());
            }
            return(newCards);
        }
Ejemplo n.º 5
0
 //gets a card based on int 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."));
     }
 }
Ejemplo n.º 6
0
        //draw cards based on int value provided
        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);
        }
Ejemplo n.º 7
0
        //to string shows players cards as string
        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);
        }
Ejemplo n.º 8
0
 //parameterized constructor
 private PlayerHand(CardList newPlayerHand)
 {
     playerHand = newPlayerHand;
 }
Ejemplo n.º 9
0
        //ComputerAttackingPhase method, guides the ai through attacking phase
        public void AttackingPhase(GameRiver gameRiver)
        {
            Card attackingCard = new Card();

            CardList gameRiverList = new CardList();

            bool sucessfullattack = false;

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


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

                    gameRiver.AddCardToRiver(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() == gameRiverList[0].rank | attackingCard.getCardRank() == gameRiverList[1].rank)
                    {
                        gameRiver.AddCardToRiver(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() == gameRiverList[0].rank | attackingCard.getCardRank() == gameRiverList[1].rank | attackingCard.getCardRank() == gameRiverList[2].rank | attackingCard.getCardRank() == gameRiverList[3].rank)
                    {
                        gameRiver.AddCardToRiver(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() == gameRiverList[0].rank | attackingCard.getCardRank() == gameRiverList[1].rank | attackingCard.getCardRank() == gameRiverList[2].rank | attackingCard.getCardRank() == gameRiverList[3].rank | attackingCard.getCardRank() == gameRiverList[4].rank | attackingCard.getCardRank() == gameRiverList[5].rank)
                    {
                        gameRiver.AddCardToRiver(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() == gameRiverList[0].rank | attackingCard.getCardRank() == gameRiverList[1].rank | attackingCard.getCardRank() == gameRiverList[2].rank | attackingCard.getCardRank() == gameRiverList[3].rank | attackingCard.getCardRank() == gameRiverList[4].rank | attackingCard.getCardRank() == gameRiverList[5].rank)
                    {
                        gameRiver.AddCardToRiver(attackingCard);
                        getHand().RemoveCardFromHand(attackingCard);
                        sucessfullattack = true;
                        break;
                    }
                }
                break;
            }


            if (sucessfullattack == false && gameRiver.length() == 0 | gameRiver.length() == 2 | gameRiver.length() == 4 | gameRiver.length() == 6 | gameRiver.length() == 8)
            {
                setIsDefending(true);
            }
        }
Ejemplo n.º 10
0
        //ComputerDefendingPhase method, guides the ai through Defending phase
        public void DefendingPhase(GameRiver gameRiver, Card trumpCard)
        {
            Card     defendingCard     = new Card();
            CardList gameRiverList     = new CardList();
            bool     sucessfulldefense = false;

            //int computerInput = 0;

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

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

                    if (defendingCard.getCardSuit() == gameRiverList[0].suit & defendingCard > gameRiverList[0] | defendingCard.getCardSuit() == trumpCard.getCardSuit() & defendingCard > gameRiverList[0])
                    {
                        gameRiver.AddCardToRiver(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() == gameRiverList[2].suit & defendingCard > gameRiverList[2] | defendingCard.getCardSuit() == trumpCard.getCardSuit() & defendingCard > gameRiverList[2])
                    {
                        gameRiver.AddCardToRiver(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() == gameRiverList[4].suit & defendingCard > gameRiverList[4] | defendingCard.getCardSuit() == trumpCard.getCardSuit() & defendingCard > gameRiverList[4])
                    {
                        gameRiver.AddCardToRiver(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() == gameRiverList[6].suit & defendingCard > gameRiverList[6] | defendingCard.getCardSuit() == trumpCard.getCardSuit() & defendingCard > gameRiverList[6])
                    {
                        gameRiver.AddCardToRiver(defendingCard);
                        getHand().RemoveCardFromHand(defendingCard);
                        sucessfulldefense = true;
                        break;
                    }
                }
                break;
            }

            if (sucessfulldefense == false && gameRiver.length() == 1 | gameRiver.length() == 3 | gameRiver.length() == 5 | gameRiver.length() == 7)
            {
                setIsDefending(false);
            }
        }
Ejemplo n.º 11
0
 //Parameterized Constructor (CardList), sets private attribute cardlist to new carlist.
 private GameDeck(CardList newCards)
 {
     cards = newCards;
 }
Ejemplo n.º 12
0
 //shuffle method, randomizes the order of the cardlist,
 //then uses the copy to method in cardlist to copy over the cards to a new cardlist deck.
 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);
     }
 }
Ejemplo n.º 13
0
        //will refill player hand
        public void RefillHand(GameDeck deck)
        {
            CardList cards = deck.DrawCards(6 - hand.length());

            hand.AddCardsToHand(cards);
        }
Ejemplo n.º 14
0
        //Defending phase for human players
        public virtual void DefendingPhase(GameRiver gameRiver, Card trumpCard, Card defendingCard)
        {
            //Card defendingCard = new Card();
            CardList gameRiverList     = new CardList();
            bool     sucessfulldefense = false;


            //gameRiver.AddCardToRiver(defendingCard);
            //getHand().RemoveCardFromHand(defendingCard);
            //sucessfulldefense = true;



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



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


                if (defendingCard.getCardSuit() == gameRiverList[0].suit & defendingCard > gameRiverList[0] | defendingCard.getCardSuit() == trumpCard.getCardSuit() & defendingCard > gameRiverList[0])
                {
                    gameRiver.AddCardToRiver(defendingCard);
                    getHand().RemoveCardFromHand(defendingCard);
                    sucessfulldefense = true;
                    break;
                }


                break;

            case 3:


                if (defendingCard.getCardSuit() == gameRiverList[2].suit & defendingCard > gameRiverList[2] | defendingCard.getCardSuit() == trumpCard.getCardSuit() & defendingCard > gameRiverList[2])
                {
                    gameRiver.AddCardToRiver(defendingCard);
                    getHand().RemoveCardFromHand(defendingCard);
                    sucessfulldefense = true;
                    break;
                }


                break;


            case 5:


                if (defendingCard.getCardSuit() == gameRiverList[4].suit & defendingCard > gameRiverList[4] | defendingCard.getCardSuit() == trumpCard.getCardSuit() & defendingCard > gameRiverList[4])
                {
                    gameRiver.AddCardToRiver(defendingCard);
                    getHand().RemoveCardFromHand(defendingCard);
                    sucessfulldefense = true;
                    break;
                }


                break;

            case 7:


                if (defendingCard.getCardSuit() == gameRiverList[6].suit & defendingCard > gameRiverList[6] | defendingCard.getCardSuit() == trumpCard.getCardSuit() & defendingCard > gameRiverList[6])
                {
                    gameRiver.AddCardToRiver(defendingCard);
                    getHand().RemoveCardFromHand(defendingCard);
                    sucessfulldefense = true;
                    break;
                }


                break;
            }



            //if (sucessfulldefense == false)
            //{
            //    setIsDefending(false);
            //}
        }
Ejemplo n.º 15
0
 //parameriterized constructor sets new gameriver
 private GameRiver(CardList newGameRiver)
 {
     gameRiver = newGameRiver;
 }