/// <summary> /// Begins the game. /// </summary> public override void Start() { this.Deal(cards: this.CardsInHand); Suit trumps = (Suit) new Random().Next(3) + 1; // Add one so it can't be Suit.Null bool aceHigh = true; for (int i = 0; i < this.CardsInHand; i++) { SuitOrder.Reset(); List <Card> laid = new List <Card>(); Suit first = Suit.Null; foreach (WhistPlayer play in this.Players) { Console.Clear(); Console.WriteLine("Player {0}'s turn!", play.ID); Console.Read(); Console.Clear(); Console.WriteLine("Player " + play.ID); // Create a new instance of WhistInfo WhistInfo info = new WhistInfo(); info.CardsInPlay = laid; info.FirstSuitLaid = first; info.RoundNumber = 0; info.Trumps = trumps; info.AceHigh = aceHigh; // Make the move, and remove the card from their hand Card c = play.MakeMove(info); play.Hand.Remove(c); laid.Add(c); // Update the first laid card, if necessary if (first == Suit.Null) { first = c.Suit; } } // Detect winner WhistPlayer winner = this.Players[laid.IndexOf(Card.HighestCardFromArray(laid))]; // Increment the player's score winner.Score += 1; Console.WriteLine("Player " + winner.ID + " won the hand!\n"); this.OrderPlayers(this.Players.IndexOf(winner)); } }
internal void VerifyCard(Card C) { if (!SuitOrder.Contains(C.Suit)) { goto InvalidSuit; } if (C.Value < MinValue || C.Value > MaxValue) { goto InvalidValue; } return; InvalidSuit: throw new CardSuit.CardSuitException("Invalid Suit"); InvalidValue: //Not Yet Implemented throw new CardSuit.CardSuitException("Invalid Suit"); }
/// <summary> /// Plays the first phase of play for the game. /// </summary> /// <param name="info"> The current game info. </param> protected void PlayPhaseOne(GermanWhistInfo info) { // Plays 13 rounds for (int i = 0; i < 13; i++, info.RoundNumber++) { // Reset the suit order SuitOrder.Reset(); SuitOrder.SetTrumps(info.Trumps); // Sets the card being played for to the top card in the deck info.ToPlayFor = this.Deck[0]; // Make each player play a card foreach (GermanWhistPlayer play in this.Players) { Console.Clear(); Console.WriteLine("Player {0}'s turn", play.ID); Console.ReadKey(true); Console.Clear(); this.MakePlayerMove(info, play); } Console.Clear(); // Decide who won the card and give players their new cards int winnerIndex = this.DecideCardWinner(info); Console.ReadKey(true); // Reset variables that need to be reset info.CardsInPlay.Clear(); info.FirstSuitLaid = Suit.Null; // Swap the players if the second player won if (winnerIndex == 1) { this.OrderPlayer(); } } info.ToPlayFor = new Card(Value.Null, Suit.Null); }
public Deck(bool usesJokers = false, bool shuffle = false, CardSuit[] suitOrder = null, int minValue = 1, int maxValue = 13) { try { MinValue = minValue; MaxValue = maxValue; if (null == suitOrder) { SuitOrder = DefaultSuitOrder; } else { SuitOrder = suitOrder; } Cards = new List <Card>(); HasJokers = usesJokers; if (HasJokers) { foreach (var c in Enumerable.Range(minValue - 1, MaxValue * SuitOrder.Count() + SuitOrder.Count())) { Card C = c; VerifyCard(C); Cards.Add(C); } } else { foreach (Deck.CardSuit s in SuitOrder) { foreach (char c in Enumerable.Range(MinValue, MaxValue)) { Card C = new Card(c, s); VerifyCard(C); Cards.Add(C); } } } if (shuffle) { Shuffle(Extensions.Random.Next(Cards.Count % 4), true); } return; } catch (Exception e) { throw new DeckException(e.Message, e); } }
/// <summary> /// Plays the second phase of play for the game. /// </summary> /// <param name="info"> The current game info. </param> protected void PlayPhaseTwo(GermanWhistInfo info) { // Play 13 rounds for (int i = 0; i < 13; i++, info.RoundNumber++) { // Reset the suit order SuitOrder.Reset(); SuitOrder.SetTrumps(info.Trumps); // Make each player play a card foreach (GermanWhistPlayer play in this.Players) { Console.Clear(); Console.WriteLine("Player {0}'s turn", play.ID); Console.ReadKey(true); Console.Clear(); this.MakePlayerMove(info, play); } Console.Clear(); // Decide who won the trick int winnerIndex = this.DecideTrickWinner(info); Console.ReadKey(true); // Reset info info.CardsInPlay.Clear(); info.FirstSuitLaid = Suit.Null; // Swap the players if the second player won if (winnerIndex == 1) { this.OrderPlayer(); } } Console.WriteLine("\n\n"); }
public void WorstCardTest() { // arrange List <Card> cardsList = new List <Card>(); cardsList.Add(new Card(Value.Ace, Suit.Spades)); cardsList.Add(new Card(Value.Ace, Suit.Diamonds)); cardsList.Add(new Card(Value.King, Suit.Diamonds)); cardsList.Add(new Card(Value.Seven, Suit.Clubs)); Card[] cards = cardsList.ToArray(); // arrange 1 SuitOrder.Reset(); Settings.AceHigh = false; // act Card actual = Card.LowestCardFromArray(cards); // assert Assert.AreEqual(cardsList[1], actual); // arrange 2 SuitOrder.Reset(); Settings.AceHigh = true; // act actual = Card.LowestCardFromArray(cards); // assert Assert.AreEqual(cardsList[3], actual); // arrange 3 SuitOrder.Reset(); SuitOrder.SetTrumps(Suit.Spades); Settings.AceHigh = false; // act actual = Card.LowestCardFromArray(cards); // assert Assert.AreEqual(cardsList[1], actual); // arrange 4 SuitOrder.Reset(); SuitOrder.SetTrumps(Suit.Spades); Settings.AceHigh = true; // act actual = Card.LowestCardFromArray(cards); // assert Assert.AreEqual(cardsList[3], actual); // arrange 5 SuitOrder.Reset(); SuitOrder.SetTrumps(Suit.Diamonds); Settings.AceHigh = false; // act actual = Card.LowestCardFromArray(cards); // assert Assert.AreEqual(cardsList[0], actual); // arrange 6 SuitOrder.Reset(); SuitOrder.SetTrumps(Suit.Diamonds); Settings.AceHigh = true; // act actual = Card.LowestCardFromArray(cards); // assert Assert.AreEqual(cardsList[3], actual); // arrange 7 SuitOrder.Reset(); SuitOrder.SetTrumps(Suit.Clubs); Settings.AceHigh = false; // act actual = Card.LowestCardFromArray(cards); // assert Assert.AreEqual(cardsList[1], actual); // arrange 8 SuitOrder.Reset(); SuitOrder.SetTrumps(Suit.Clubs); Settings.AceHigh = true; // act actual = Card.LowestCardFromArray(cards); // assert Assert.AreEqual(cardsList[2], actual); // arrange 9 SuitOrder.Reset(); SuitOrder.SetTrumps(Suit.Hearts); SuitOrder.SetPlayed(Suit.Diamonds); Settings.AceHigh = false; // act actual = Card.LowestCardFromArray(cards); // assert Assert.AreEqual(cardsList[0], actual); // arrange 10 SuitOrder.Reset(); SuitOrder.SetTrumps(Suit.Hearts); SuitOrder.SetPlayed(Suit.Diamonds); Settings.AceHigh = true; // act actual = Card.LowestCardFromArray(cards); // assert Assert.AreEqual(cardsList[3], actual); }