Introduction

To build your very own card game, you first need to define your card model.
For the standard set of cards there are two values that define each card:
- The suit (or color): Hearts, Diamonds, Spades and Clubs
- The “value”: Ace, Two, …, Ten, Jack, Queen, King
Assignment

Step 1
Define your own card class using two Enum values: Suit
and Value
.
- Make sure that the equals method works.
- And for an extra challenge, add the ability to sort your cards.
Step 2
Add a value to both enums that allows you to toString
your card in two character strings. For instance:
- Two of Spades : “2S”
- Ace of Clubs : “AC”
- Ten of Hearts: “TH”
- Queen of Diamonds: “QD”
Step 3
Add additional infomation to your enums:
- Hearts and Diamonds are “red”, Clubs and Spades are “black”
- The “2” cards have a value of 2, “10” has a value of 10, just like Jack, Queen and King. Choose a logical value for Ace.
Step 4
When given five random cards, determine the poker hand:
- High card
- One Pair
- Two Pairs
- Three of a kind
- Full House
- Four of a kind
- Flush (same suit)
- Straight (incremental values, 2,3,4,5,6 or 8,9,10,J,Q)
- Royal Flush (combination of Flush and Straigh)
In case of ties, the set with the highest card wins.
When both players have two fives, then the highest other card decides.
So “four 2’s” loses from “four 3’s” and a straight to 7 loses from a straight with highest card 8.
Variations
Not looking for a standard card game?
Why not use
Cards have the following values:
- Shape: Circle, Box, Squiggle
- Number: 1, 2 or 3
- Color: Green, Red, Blue (in this case purple)
- Filling: None, Solid, Half
A set of three cards is a set when all values are either the same or different. In the image:
- The top left set: Different number, shapes and colors, but all cards hace a solid fill.
- The top right set: Same shape and color, but different number and filling.
- The bottom left set: Same number and shape, but different color and filling.
- The bottom right set: Same number, color and filling, but different shape.
- For thhe 3x3 cards: all rows, columns are sets.
You choose
Pick a card game that you know well.
Create a data model.
Add the ability to play some part of that game.
For inspiration: https://adventofcode.com/2023/day/7