Poker Game Solved

30.00 $ 15.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: . zip solution files instantly, after Payment

Description

5/5 - (1 vote)

Poker Game
In my Program.cs file: Leave the statement where you create a new myDeck, but delete the simple “write all 52 cards
loop”. Leave the very last Console.ReadLine(). Create an int called howManyCards and set it to 5. We will normally play with a 5 card hand,
but it’s nice to be able to make it smaller when you are debugging. So never hard code a 5 in
your program, always use this variable. Create an int balance and set it to 10. This holds how much money the player has, they start with
10 dollars. Set your screen output to be some color set, we will call it the base scheme, such as
o
o Console.ForegroundColor = ConsoleColor.Yellow;
Console.BackgroundColor = ConsoleColor.DarkBlue; Write out a statement welcoming player to the game and explain they have $10 to start, and
each turn (loop) of the game will be a $1 bet. Create a while loop that runs until the player balance is $0. Each pass thru this loop represents
“playing one hand” as a turn is called in card games. In the next phase, you are going to call methods that do not yet exist! That’s ok, just write the calls. In each pass through this loop:
o 2 times call a new method: myDeck.GetCards(int)
(Which will later be added to your CardSet Class.) It will return an array of size “howManyCards”, filled with random cards from your deck. You can just add the next two
lines of code to do this. You are creating a “hand” (an array of cards) for both the computer
and the player.
o
o SuperCard computerHand = myDeck.GetCards(howManyCards);
SuperCard playersHand = myDeck.GetCards(howManyCards); o Call a new method you will write later in this Program.cs file (it will write out the cards) DisplayHands(computerHand, playersHand);
o Call a new method, CompareHands ,you will write later in this Program.cs file with
this line of code. The return value will be true if the player wins this hand, false if they
lose. bool won = CompareHands(computerHand, playersHand); o Then o let the player know if they won or lost (based on that bool “won”) what their new balance is, and have them click the “Enter” key to play another hand.
If their balance is zero, tell them they lost, and exit the loop. End with that
Console.ReadLine() so that the screen doesn’t disappear. Go to your CardSet class, and implement the GetCards(int) method
o public SuperCard GetCards(int number)
o It picks number cards (the number you passed in) at random from the your CardArray
and returns them as an array.
o You will need to instantiate the Random class, do that at the very top of the CardSet
class, right after the line where you defined the CardArray, treating it like another public
field. (By putting it there, your random numbers will correctly flow continuously,
whereas if you create Random just inside the GetCards method, you will keep re-starting
the Random sequence, and every time you play the game will look the same.)
o For this stage of the project, you can reuse the same card. For example, it’s ok if a hand
has 2 or 3 Jack of Diamonds. We will fix that in the next phase of the project. Now go back Program.cs and implement the missing DisplayHands method, which is
o DisplayHands(computerHand, playersHand);
o Start by writing a line to say this is the computers hand, and then loop through the
computerHand array and call each member’s Display() method.
o Reset the console color scheme back to your base setting.
o Then write a line to say this is the player’s hand, and then loop through the playersHand
array and call each member’s Display() method.
o Lastly, reset the console color scheme back to your base setting. go to your SuperClass Class and add an abstract Display method public abstract void Display();
o Then go to each of your 4 card classes and implement an override Display method. I’ll
give them to you here: public override void Display()
{
// Code to Display a club card…
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine(cardsRank + " of " + _cardsuit + "s ♣");
Console.ResetColor();
}
public override void Display()
{
// Code to Display a diamond card…
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine(cardsRank + " of " + _cardsuit + "s ♦");
Console.ResetColor(); }
public override void Display()
{
// Code to Display a heart card…
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(cardsRank + " of " + _cardsuit + "s ♥");
Console.ResetColor();
}
public override void Display()
{
// Code to Display a Spade card…
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Black;
Console.WriteLine(cardsRank + " of " + _cardsuit + "s ♠");
Console.ResetColor();
} Finally, implement the last missing method in Program.cs, CompareHands
o It needs to have passed in to it as arguments both the computer and the player’s hand
arrays.
o For now, just add up the int value of the rank of each card in the hands
o If the player’s total is greater than the computers, return a true, which means the player won
o If the player’s total is less than or equal to the computers, return a false At this point, I should have a working game.
If you are using Windows 10, you might have to go to the command windows properties and set them to
“legacy” console to get the small card icons to show up. Right click on the small icon in the upper left of the console window. Here are 2 screen shots: Initial screen After typing enter the first time.