Skip to content

C# Card Games: UML

Overview

In the last step, Intermediate C# Programming: Card Games Introduction, you were challenged to list the patterns you see across several card games and the properties of a single card. The lists you created will help you identify classes, attributes, and operations to include in UML diagrams. The UML diagrams you create will give you insight into how your system will be structured (before you begin coding). You can also get an idea of the type of components you'll want to build out in your system.

C# Card Games Patterns

What patterns did you find across multiple card games? In the expandable section below are card and game patterns that others have identified. Did you find patterns others haven't? Are there any patterns that you think are important that you didn't have on your list?

Game Patterns Examples

Card

  • Card value (and whether certain cards such as Aces have alternative values)
  • Card number
  • Card suit

Game

  • # of cards in deck
  • Card value (and whether certain cards such as Aces have alternative values)
  • Card number
  • Card suit
  • Comparing cards (value/number/suit)
  • Deal
  • Dealer
  • Deck(s)
  • Discarding cards
  • Game names
  • Game rules
  • Goals/Objectives/Win conditions (for example, discarding all cards in your hand before everyone else)
  • Minimum/maximum number of players
  • Origin (of game and/or deck)
  • Player hand
  • Player(s)
  • Playing cards
  • Points
  • Random
  • Ranks/Face cards
  • Sequences/combinations/melds
  • Showing/revealing cards
  • Shuffle
  • Strategies
  • System
  • Total points (or adding up points)
  • Turn(s)

C# Card Games UML

Organize your list into classes based on the patterns you've identified, and the relationships between them.

For example, if you want to have a class that will be a template for any card in any card game, you can group together the patterns you've identified that relate to the concept of "a card".

Card Class Attributes

  • Value
  • Suit
  • Name (i.e., one-eyed Jack)

There are other data structures and ways of organizing patterns that can also work aside from just classes. Right now we are staying with classes to keep this simple, but once you've finished building your first version and you are ready to refactor and improve your code, you can look at other structures such as structs and interfaces.

Card Game Class Examples


Below are some patterns pulled from the earlier lists that could be grouped together into a template for any card game.

Examples of Class Attributes

  • Game name
  • Number of players
  • Number of cards in the deck (and/or number of decks)
  • Rules of the game
  • Cards in the deck (set of instances of a Card class, each with suit/value/number/name)
  • Discard pile (set of instances of a Card class)
  • Player(s)
  • Number of cards a player is dealt (a player's hand)
  • Win condition

Examples of Class Operations

  • Deal
  • Shuffle
  • Draw
  • Discard
  • Play/Place card
  • Compare cards
  • Win
  • Lose
  • Fold
  • Begin game (and restart game)
  • End game

UML Diagrams

There are many ways to create UML diagrams. If you are using Visual Studio and have the Class Designer installed, you can create your diagrams in your project. Visual Studio will create code from your diagrams.

You can also write code first, then have Visual Studio create UML diagrams from your code.

Next Step

Use the UML you've created to build out the first draft of your application's classes.