public void Run() { topCard = deck.Deal(); System.Console.WriteLine("\n -------------------------------------"); while (playing) { if (deck.cards.Count < 1) { System.Console.WriteLine("\n The deck is impty. Shuffling Discard pile!\n\n -------------------------------------"); Reshuffle(); } if (currentPlayer == player) { playerTurn(); if (!playing) { if (PlayAgain()) { Reset(); } else { return; } } if (playedACard == true) { ResolveCard(); } Thread.Sleep(1000); if (reverse) { currentPlayer = currentPlayer.prev; } else { currentPlayer = currentPlayer.next; } } else { opponentTurn(); } System.Console.WriteLine("\n -------------------------------------"); } }
static void Main(string[] args) { List <Player> players = new List <Player>(); players.Add(new UserPlayer("Nolan")); players.Add(new Player("Bot")); Deck deck = new Uno.Deck(); deck.Deal(players); Card top = deck.Draw(); Card temp; Card wild_color = new Card(0, "WILD"); bool winner = false; int index = 0; while (!winner) { System.Console.WriteLine("Top: {0}", top); if (top.GetValue() == "Wild") { temp = players[index].Play(wild_color); } else { temp = players[index].Play(top); } if (temp.GetValue() == "FAIL") { System.Console.WriteLine("{0} draws a card", players[index].ID); players[index].AddCard(deck.Draw()); continue; } top = temp; winner = players[index].CheckWin(); deck.AddToPile(top); if (top.GetValue() == "Reverse") { players.Reverse(); } if (top.GetValue() == "Skip") { index++; } if (top.GetValue() == "Wild") { wild_color.SetColor("RED"); System.Console.WriteLine("Wild: {0}!", "RED"); } if (top.GetValue() == "Wild+4") { wild_color.SetColor("RED"); System.Console.WriteLine("Wild+4: {0}!", "RED"); for (int i = 0; i < 4; i++) { players[(index + 1) % players.Count].AddCard(deck.Draw()); } index++; } index = (index + 1) % players.Count; } }
public Card Draw(Deck deck) { hand.Add(deck.Deal()); return(hand[hand.Count - 1]); }
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("-------------------------------------"); } }