Example #1
0
        // Constructor
        public Game()
        {
            this.players   = new List <Player>();
            this.turnQueue = new Queue <Player>();
            // Start the Game
            Console.WriteLine("How Many Players are Playing?");
            int numPlayers = Convert.ToInt32(Console.ReadLine());

            for (int ii = 0; ii < numPlayers; ii++)
            {
                Console.WriteLine("Enter the name of the next player:");
                string name  = Console.ReadLine();
                Player nextP = new Player(name);
                players.Add(nextP);
                Console.WriteLine(name + " has entered the game!");
            }
            this.deck = new Deck();
            deck.shuffle();
            // Deal 7 cards
            for (int ii = 0; ii < 7; ii++)
            {
                for (int jj = 0; jj < players.Count; jj++)
                {
                    players[jj].draw(deck);
                }
            }
            // Creating Turn Order
            for (int ii = 0; ii < players.Count; ii++)
            {
                turnQueue.Enqueue(players[ii]);
            }
            lastCard  = null;
            lastColor = null;
        }
Example #2
0
        public UnoCard draw(Deck deck)
        {
            UnoCard next = deck.deal();

            hand.Add(next);
            return(next);
        }
Example #3
0
        public UnoCard play(int idx)
        {
            if (idx < 0 || idx >= hand.Count)
            {
                return(null);
            }
            UnoCard card = hand[idx];

            hand.RemoveAt(idx);
            return(card);
        }
Example #4
0
        public UnoCard deal()
        {
            if (cards.Count == 0)
            {
                return(null);
            }
            UnoCard topCard = cards[0];

            cards.RemoveAt(0);
            return(topCard);
        }
Example #5
0
 // Procssing the card played.
 public void processCard(UnoCard thisCard)
 {
     lastCard  = thisCard;
     lastColor = thisCard.color;
     if (thisCard.type.Equals("Wild"))
     {
         chooseColor();
         lastNum = 0;
     }
     if (thisCard.type.Equals("Draw 4 Wild"))
     {
         chooseColor();
         lastNum = 0;
         for (int ii = 0; ii < 4; ii++)
         {
             turnQueue.Peek().draw(deck);
         }
     }
     if (thisCard.type.Equals("Skip"))
     {
         Player temp = turnQueue.Dequeue();
         turnQueue.Enqueue(temp);
         lastNum = 0;
     }
     if (thisCard.type.Equals("Reverse"))
     {
         reverse();
         lastNum = 0;
     }
     if (thisCard.type.Equals("Draw 2"))
     {
         for (int ii = 0; ii < 4; ii++)
         {
             turnQueue.Peek().draw(deck);
         }
         lastNum = 0;
     }
     if (contains(data.numCards, thisCard.type))
     {
         lastNum = Convert.ToInt32(thisCard.type);
     }
 }
Example #6
0
 // Bool is whether or not you can make this play with the given card.
 public bool ValidPlay(UnoCard thisCard)
 {
     if (thisCard.type.Equals("Wild") || thisCard.type.Equals("Draw 4 Wild"))
     {
         return(true);
     }
     if (thisCard.color.Equals(lastColor))
     {
         if (contains(data.otherCards, thisCard.type) || contains(data.otherCards, lastCard.type))
         {
             return(true);
         }
         else if (Array.IndexOf(data.numCards, thisCard.type) >= lastNum)
         {
             return(true);
         }
     }
     if (thisCard.type.Equals(lastCard.type))
     {
         return(true);
     }
     return(false);
 }
Example #7
0
        // Bool is whether or not game is still going on.
        public bool play()
        {
            Player currentP = turnQueue.Dequeue();

            turnQueue.Enqueue(currentP);
            printGame(currentP);
            Console.WriteLine("Pick the card you wish to play:");
            Console.WriteLine();
            Console.WriteLine("0) Don't Play");
            for (int b = 0; b < currentP.hand.Count; b++)
            {
                Console.WriteLine($"{b+1}) {currentP.hand[b].toString()}");
            }
            if (lastCard != null)
            {
                Console.WriteLine("******************************");
                assignColor();
                Console.WriteLine("Last card played is " + lastCard.toString());
                if (lastCard.type.Equals("Wild") || lastCard.type.Equals("Draw 4 Wild"))
                {
                    Console.WriteLine("Color Chosen for Wild was " + lastColor);
                }
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("******************************");
            }
            int  input   = 0;
            bool CanPlay = false;

            while (!CanPlay)
            {
                input = Convert.ToInt32(Console.ReadLine());
                if (input <= 0 || input > currentP.hand.Count)
                {
                    CanPlay = true;
                }
                else if (lastCard == null)
                {
                    CanPlay = true;
                }
                else
                {
                    CanPlay = ValidPlay(currentP.hand[input - 1]);
                }
                if (!CanPlay)
                {
                    Console.WriteLine("Invalid play, please choose another card.");
                }
            }
            if (input <= 0 || input > currentP.hand.Count)
            {
                currentP.draw(deck);
            }
            else
            {
                UnoCard card = currentP.play(input - 1);
                processCard(card);
            }
            if (currentP.hand.Count == 0)
            {
                Console.WriteLine($"{currentP.name} wins!!!!!!!!!!");
                return(false);
            }
            if (deck.cards.Count == 0)
            {
                Console.WriteLine("You all suck, game was a draw.");
                return(false);
            }
            return(true);
        }