Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C# In this assignment, you will be creating a rather simple program that sport a deck of cards, a dealer, and allow you to choose

C#

In this assignment, you will be creating a rather simple program that sport a deck of cards, a dealer, and allow you to choose how many players are at the table. The dealer will shuffle the deck and distribute cards in a round-robin style to each player. While this assignment will not have any game rules, we will be able to use it in the future to build any card game we wish!

Requirements

First, let us set some ground rules:

You are FORBIDDEN from using the main method for anything other than simply starting the application. Minimal code for startup is expected here.

You will practice proper encapsulation of ALL data fields in ALL classes.

You are to practice proper abstraction. Every class should represent one specific thing and everything needed for the application should have a class. Every method should have one purpose. Generally speaking, methods should not exceed 12 statements. The 12-statement rule is more of a guideline, mind you, but that should help you identify methods that may need to be re-architected.

With all that said, here are the requirements for the application:

Be in C#

1:Create a new console application.

2.,Add two enums, Suit and Rank

Suit represents the four suits of a standard deck of cards

Rank represents the 13 distinct values of the cards

3.Create a Card class. Each card has a rank and a suit. Once set, neither of these fields should EVER be able to change. In other words, once an instance of Card is a 4 of Hearts, it is ALWAYS a 4 of Hearts. The class should also override the ToString method to represent the Cards data.

4.Create a Deck class. The Deck should have an array of 52 Cards. The Deck is only a standard deck of cards, so it knows which cards it needs and how to build them. The Deck is the ONLY one allowed to directly access the array of Cards. The Deck knows how to shuffle and how to deal a single Card. Once the Deck is out of Cards, it must be shuffled again before it can deal the next Card. The Deck also overrides the ToString to create a string representing the remaining Cards in the Deck.

5Create a Player class. Each Player has a name and a hand (which is a List). A Player can receive a Card into its hand, can return a Card from its hand, and return all cards from its hand. The Player overrides the ToString to represent the Players name and its current hand of Cards (if any).

6.Create a Dealer class. The Dealer has a collection of Players and a Deck. The Dealer is the class that interfaces directly with the user.

7. At startup, create a new instance of Dealer, who in turn creates a new instance of Deck (remember, the Deck knows how to build the Cards it needs; the Dealer doesnt have to build the Cards for the Deck). The Deck should NOT be shuffled yet. Think of the Deck as fresh out of the box.

8.When the application begins, prompt the user for how many Players they want.

For each Player, prompt the user to provide a name

i.Null, empty, and whitespace-only entries are NOT valid inputs for a Player name

9.After the Players are set, present the user with the following menu:

a.Print the Deck

b.Shuffle the Deck

c.Deal Cards

d.Deal one Card to a Player

e.Print the Players

f.Set new Players

g.Exit

10.Print the deck displays all of the remaining Cards in the Deck to the console in their current order. Make sure this is easily readable and user friendly in its format.

11.Shuffle the Deck results in the Deck being shuffled. If any Player has Cards in hand, those Cards are removed from the Player hand prior to the shuffle. Essentially, shuffling the Deck resets the Cards dealt.

12.Deal Cards prompts the user for how many Cards to deal each player and then, in a round-robin style, deals that many cards to each Player. If there are not enough cards left to meet the users request, the Dealer will still deal all the Cards it can. For example, if there are 3 Players and only 10 cards left, then when the user tries to deal 5 cards to each Player, the first Player will have 4 Cards, and the remaining two Players each receive 3 Cards.

13.Deal one Card to a Player prompts the user for which Player should receive the Card. Once selected, and assuming there are Cards left in the Deck, the Dealer will deal the next Card from the Deck to the selected Player. If there are no Cards in the Deck when this menu option is selected, a message indicating there are no cards left should be displayed INSTEAD of the prompt to select a Player.

14.Print Players prints each Player (meaning their name and hand) to the console. Again, make sure this is done in a readable, user-friendly format.

15.Set new Players empties the collection of Players, returns all Cards to the Deck, and starts over by prompting the user for the number of Players (as found in #8 above). After the Players are set up with names, the application continues as described above.

16.All invalid inputs should result in a useful error message and prompting the user again. No exceptions from bad input should reach the console.

17. Keep looping the application until the user selects Exit. Once they select Exit from the menu in #9, close the application.

This must be in C#

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Databases With PostgreSQL From Novice To Professional

Authors: Richard Stones, Neil Matthew

2nd Edition

1590594789, 978-1590594780

More Books

Students also viewed these Databases questions

Question

Explain the purpose of an ER diagram in database design.

Answered: 1 week ago