Playing Cards – 21
Overview: In this
program, you will create a card game.
In the game of 21, the object is to get cards that total close to 21
without going over. In this version,
there will be two players. Player 1
takes their cards until they stop or “bust”.
Then, Player 2 gets their cards.
Specifics:
·
The first player of
the game will get two cards. Each card
can be determined by two random numbers.
The first random number is 1 to 13 and determines the card (1 = Ace, 2,
3, 4, 5, 6, 7, 8, 9, 10, 11=Jack, 12=Queen, 13=King). The second random number is 1 to 4 and determines suit (1=Hearts,
2=Diamonds…etc).
·
Psudeocode for dealing
a random card:
o
Find random number for
card
o
Find random number
suit
o
Print card name based
on first random number (8 of….)
o
Print card suit based
on second random number (…clubs)
·
After you’ve given the
player one card, give them another one.
(For a challenge, make it so they can’t get the same card twice.)
·
Add up a total for the
two cards. In the game of 21, lets say
that Aces are worth 11, Jacks, Queens, and Kings are worth 10 (so are
10’s). Every other card is worth its
face value. For example, if I were
given a 6 of H (6 of Hearts) and King of D, my total for the two cards would be
16. (Challenge: Aces can be worth either 1 or 11, depending
on what benefits the player most)
·
After the user is
given two cards, they may decide if they want another card or not. (If my total were 10 or less, I’d take a
card for sure since it won’t put me over 21).
This repeats itself until the player goes over 21 or decides not to take
any more cards. (Once again, for a
challenge, make sure the player doesn’t get the same card twice. If you’re confused, don’t sweat it too
much.)
·
After the first player
has quit taking cards (or busted), the second player does the same.
·
The game reports the
winner of the hand.
|
Sample I/O: Player 1: Card#1 is a 7 of Clubs Card#2 is a 9 of Spades Your total is 16 Do you want another card (y/n)? y Card#3 is a 3 of Clubs Your total is 19 Do you want another card (y/n)? n Player 2: Card #1 is a King of Spades Card #2 is a Jack of Hearts Your total is 20 Do you want another card (y/n)? n Player 2 wins, 20 to 19 |
Another Sample I/O: Player 1: Card#1 is a Ace of Diamonds Card#2 is a 2 of Spades Your total is 13 Do you want another card (y/n)? y Card#3 is a 4 of Clubs Your total is 17 Do you want another card (y/n)? y Card#4 is a 7 of Hearts Your total is 24 You bust since your total is over 21 Player 2: Card #1 is a King of Spades Card #2 is a 8 of Hearts Your total is 18 Do you want another card (y/n)? n Player 2 wins, 18 to 24(bust) |