1.4-Software-Development-Principles

Card games

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:

Assignment

Step 1

Define your own card class using two Enum values: Suit and Value.

Step 2

Add a value to both enums that allows you to toString your card in two character strings. For instance:

Step 3

Add additional infomation to your enums:

Step 4

When given five random cards, determine the poker hand:

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

Set!

Not looking for a standard card game? Why not use Cards have the following values:

A set of three cards is a set when all values are either the same or different. In the image:

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