コード例 #1
0
        public void opponentTurn()
        {
            System.Console.WriteLine($"\n     {currentPlayer.name} takes their turn.");

            startingTotal = currentPlayer.hand.Count;
            discarded     = topCard;
            topCard       = currentPlayer.Play(topCard, deck);

            if (startingTotal <= currentPlayer.hand.Count)
            {
                playedACard = false;
            }
            else
            {
                playedACard = true;
                discard.cards.Add(discarded);
            }

            if (currentPlayer.hand.Count == 0)//check for opponent win
            {
                System.Console.WriteLine("\n     " + currentPlayer.name + " wins!");
                if (PlayAgain() == false)
                {
                    return;
                }
                else
                {
                    Reset();
                }
            }

            if (playedACard == true)
            {
                ResolveCard();
            }

            Thread.Sleep(2000);

            if (reverse)
            {
                currentPlayer = currentPlayer.prev;
            }
            else
            {
                currentPlayer = currentPlayer.next;
            }
        }
コード例 #2
0
        public void playerTurn()
        {
            System.Console.Write($"\n     The top card is a ");
            topCard.PrintCard();
            System.Console.WriteLine(".");

            System.Console.WriteLine("\n     Your hand:");
            System.Console.WriteLine(player);
            if (CheckLegalMoves(player))
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
                System.Console.WriteLine("\n     Which card would you like to play?");
                Console.Out.Flush();

                int input;
                while (!(Int32.TryParse(Console.ReadLine(), out input)) || input > player.hand.Count - 1 || input < 0 || !CheckMove(player.hand[input]))
                {
                    System.Console.WriteLine("\n     Try again.");
                }
                Console.ResetColor();

                discarded   = topCard;
                topCard     = player.Play(input);
                playedACard = true;
                discard.cards.Add(discarded);

                if (player.hand.Count == 0)//check for player win
                {
                    System.Console.WriteLine("\n     You win!");
                    playing = false;
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
                System.Console.WriteLine("\n     You have no legal moves! Press enter to draw a card.");
                Console.ResetColor();
                System.Console.ReadLine();

                player.Draw(deck);
                playedACard = false;
                return;
            }
        }
コード例 #3
0
ファイル: Game.cs プロジェクト: jeffle88/UnoGame
 public void Run()
 {
     topCard = deck.Deal();
     System.Console.WriteLine("-------------------------------------");
     while (playing)
     {
         if (deck.cards.Count < 5)
         {
             for (int i = 0; i < deck.cards.Count; i++)
             {
                 discard.cards.Add(deck.cards[i]);
                 deck.cards.RemoveAt(i);
             }
             discard.Shuffle();
             deck.cards = discard.cards;
             discard    = new Deck(true);
         }
         if (currentPlayer == player)
         {
             playerTurn();
             if (!playing)
             {
                 if (PlayAgain())
                 {
                     Reset();
                 }
                 else
                 {
                     return;
                 }
             }
             if (playedACard)
             {
                 ResolveCard();
             }
             Thread.Sleep(1000);
             if (reverse)
             {
                 currentPlayer = currentPlayer.prev;
             }
             else
             {
                 currentPlayer = currentPlayer.next;
             }
         }
         else
         {
             System.Console.WriteLine($"{currentPlayer.name} takes their turn.");
             startingTotal = currentPlayer.hand.Count;
             discarded     = topCard;
             topCard       = currentPlayer.Play(topCard, deck);
             if (startingTotal == currentPlayer.hand.Count)
             {
                 playedACard = false;
             }
             else
             {
                 playedACard = true;
                 discard.cards.Add(discarded);
             }
             if (currentPlayer.hand.Count == 0)
             {
                 System.Console.WriteLine(currentPlayer.name + " wins!");
                 if (!PlayAgain())
                 {
                     return;
                 }
                 else
                 {
                     Reset();
                 }
             }
             if (playedACard)
             {
                 ResolveCard();
             }
             Thread.Sleep(2000);
             if (reverse)
             {
                 currentPlayer = currentPlayer.prev;
             }
             else
             {
                 currentPlayer = currentPlayer.next;
             }
         }
         System.Console.WriteLine("-------------------------------------");
     }
 }