Hi,
I worked through example 4 and would like to know if it answers the question posed. I know it runs and finds a flush if it exists, but only by reshuffling each hand.
I looked at seblakes code and, to be honest, I don't see how it is keeping track of what cards have already been dealt and therefor not redeal them.
If someone can help me out by modifying my code to only shuffle once and always deal the next card in the deck instead of the same ones over again, that would be great.
Thanks again and heres my code.
Jael
Code:
using System;
using Ch10ClassLib;
namespace Ch10SumEx04
{
class MyClass
{
static void Main(string[] args)
{
//Initialize a Clean Deck
Deck myDeck = new Deck();
//Deal out 50 cards @ 5 cards per hand @ 10 hands.
for (int x = 1; x <= 10; x++)
{
//Shuffle Deck each hand
myDeck.Shuffle();
//Initialize bool to check if flush exists
bool isFlush = true;
//Initialize theHand Array and String theSuit
string[] theHand = new string[5];
string[] theHandSuit = new string[5];
//Suit to check against.
string theSuit;
theSuit = "";
//Get the suit of the first card (base zero)
theSuit = myDeck.GetCard(0).suit.ToString();
Console.WriteLine (theSuit + " is the suit to Match.\n");
//Deal 5 Cards from Top of deck
for(int i = 0; i < 5; i++)
{
Card tempCard = myDeck.GetCard(i);
//Console.Write(tempCard.ToString() + "\n");
//Put dealt card into hand
theHand[i] = tempCard.ToString();
//Store suits in hand dealt
theHandSuit[i] = tempCard.suit.ToString();
}
//Check if the suits match each other in the hand dealt
foreach (string suit in theHandSuit)
{
if(suit == theSuit)
{
isFlush = true;
}
else
{
isFlush = false;
break;
}
}
//Display hand.
foreach (string card in theHand)
{
Console.Write(card + "\n");
}
if (isFlush == true)
{
Console.WriteLine("*** You have a flush ! ***\n\n");
}
else
{
Console.WriteLine("Sorry, you don't have a flush ...\n\n");
}
}
}
}
}