Question: Create a Go Fish game with c# At the start of each game, the deck is shuffled and cut. Then 5 cards are dealt out

Create a Go Fish game with c#

At the start of each game, the deck is shuffled and cut. Then 5 cards are dealt out to each of the four players. Each player keeps their cards in their hand and can look at them.

1.) Use the Card and Deck classes

2.) You Main() method will be where the game simulation takes place. It will need to have a loop that continues until the game is over. Each time through the loop represents another player's turn.

3.) Each time a player does anything, a message needs to be printed out on the console describing what the player did. After the program finishes, the console should have a complete record of everything that happened during the game.

 public enum Suit { Clubs, Diamonds, Hearts, Spades }; public enum Rank { Ace, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King }; public class Card { public Rank Rank { get; private set; } public Suit Suit { get; private set; } public Card(Suit suit, Rank rank) { this.Suit = suit; this.Rank = rank; } public override string ToString() { return ("[" + Rank + " of " + Suit + "]"); } } public class Deck { private Card[] cards; private static Random rng = new Random(); public Deck() { Array suits = Enum.GetValues(typeof(Suit)); Array ranks = Enum.GetValues(typeof(Rank)); int size = suits.Length * ranks.Length; cards = new Card[size]; int i = 0; foreach (Suit suit in suits) { foreach (Rank rank in ranks) { Card card = new Card(suit, rank); cards[i++] = card; } } } public int Size() { return cards.Length; } public void Shuffle() { if (Size() == 0) return; // Fisher-Yates Shuffle (modern algorithm) // - http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle for (int i = 0; i < Size(); i++) { int j = rng.Next(i, Size()); Card c = cards[i]; cards[i] = cards[j]; cards[j] = c; } } public void Cut() { if (Size() == 0) return; int cutPoint = rng.Next(1, Size()); Card[] newDeck = new Card[Size()]; int i; int j = 0; // Copy the cards at or below the cutpoint into the top of the new deck for (i = cutPoint; i < Size(); i++) { newDeck[j++] = cards[i]; } // Copy the cards above the cutpoint into the bottom of the new deck for (i = 0; i < cutPoint; i++) { newDeck[j++] = cards[i]; } cards = newDeck; } public Card DealCard() { if (Size() == 0) return null; Card card = cards[Size() - 1]; Array.Resize(ref cards, Size() - 1); return card; } public override string ToString() { string s = "["; string comma = ""; foreach (Card c in cards) { s += comma + c.ToString(); comma = ", "; } s += "]"; s += " " + Size() + " cards in deck. "; return s; } } public abstract class Player { public string Name { get; private set; } public Hand Hand { get; private set; } // Other Properties/member variables go here public Player(string name) { this.Name = name; this.Hand = new Hand(); } public abstract Player ChoosePlayerToAsk(Player[] players); public abstract Rank ChooseRankToAskFor(); // Other Player methods go here public override string ToString() { string s = Name + "'s Hand: "; s += Hand.ToString(); return s; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!