uOttawaUniversity of Ottawa - Canadas University
list of dots

Umple User Manual    [Previous]   [Next]   

Loading

Card Games

This system will allow players to play card games such as Whist and Oh Hell online.

The system should manage the cards in a deck of cards, the players (including who is dealer), the hands of cards each player has, the tricks, the pile of cards on the table. It should also manage the matches between players. Use some background research to improve these simple requirements.

Example

// Umple class diagram representing card games in the Oh Hell and Whist family

class Card {
  suit;  // "hearts", "clubs", "diamonds", "spades" 
  rank;  // A23456789JQK
  Boolean isJoker; // suit and rank are null for a Joker
}

class CardSet {
  // Could be a complete deck or a trick
  1 -- * Card;
}

class NotDealtCardSet {
  // This would be initialized with a complete 52-card set
  // at the start of each game
  // During dealing, the cards would be distributed to players
  isA CardSet;
}

class Trick {
  // A group of cards with one contributed by each player, and
  // eventually won by a player
  // One is built after each player has played a card
  isA CardSet;
}

class Player {
   // These are the people playing.
   name;

   // A hand is dealt at the start of a game
   // The cards a player has in his or her hand
   0..1 -- * Card hand; 

   // The tricks won by a player this game
   1 -- * Trick; 
   
   // All hands and tricks are cleared at the end of each game
   // ready for dealing again

   // The following is used only in Oh Hell
   Integer currentTricksBid;
}

class ScoringTeam {
   // for Oh Hell, it is each player for himself, so there is one player
   // for Whist there are partners, so there are two players
   1 -- 1..2 Player;
   
   // The score that each team has accumulated so far
   // based on tricks taken or difference between tricks and bid
   Integer score;
}

class Match {
  // A match is played in a number of games
  Boolean isWhist; // True if whist; false if Oh Hell  

  // The following determines the players
  // the first player in the first team deals first
  * -- 2..* ScoringTeam; // Exactly 2 if Whist
  
  Integer scoreToWin; // The score agreed to in order to declare winner

  1 -- * Game games; // Games continue until a player or team wins
  // Assume that the last game in games is the current one
}

class Game {
   trumps; // a suit (if any) that is the trumps for this game
   
   // One player is the dealer each game
   // The dealer deals out all or most of the cards at the start
   // Players take turn laying down cards to form the next trick
   * -- 1 Player dealer;
   
   // As the cards are laid down the following set is created.
   // After all players have contributed a new trick is created from the
   // following and awarded to a player
   0..1 -- * Card currentTrickBeingBuilt;

   * gameLed -- 0..1 Player currentLead; // the player next to lay down a card
}

class Card
{
  position 125 15 135 100;
}

class CardSet
{
  position 186 153 109 45;
  position.association Card__CardSet 30,0 31,100;
}

class NotDealtCardSet
{
  position 129 244 123 45;
}

class Trick
{
  position 278 245 109 45;
}

class Player
{
  position 43 429 192 82;
  position.association Card:hand__Player 7,0 0,88;
}

class ScoringTeam
{
  position 561 411 122 64;
  position.association Player__ScoringTeam 0,31 192,55;
}

class Match
{
  position 532 48 159 82;
  position.association Match__ScoringTeam 120,82 60,0;
  position.association Game:games__Match 30,82 72,0;
}

class Game
{
  position 442 280 123 64;
  position.association Game__Player:currentLead 11,64 192,11;
  position.association Card:currentTrickBeingBuilt__Game 0,10 135,50;
  position.association Game:gameLed__Player:currentLead 24,64 192,30;
  position.association Game__Player:dealer 0,38 192,10;
}


      

Load the above code into UmpleOnline