list of dots Digital Research Alliance of Canada logo  NSERC logo  University of Ottawa logo / UniversitĂ© d'Ottawa

User Manual    [Previous]   [Next]   

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

  1. // Umple class diagram representing card games  
  2. // in the Oh Hell and Whist family  
  3.   
  4. class Card {  
  5.   suit;  // "hearts", "clubs", "diamonds", "spades"   
  6.   rank;  // A23456789JQK  
  7.   Boolean isJoker; // suit and rank are null for a Joker  
  8. }  
  9.   
  10. class CardSet {  
  11.   // Could be a complete deck or a trick  
  12.   1 -- * Card;  
  13. }  
  14.   
  15. class NotDealtCardSet {  
  16.   // This would be initialized with a complete 52-card set  
  17.   // at the start of each game  
  18.   // During dealing, the cards would be distributed to players  
  19.   isA CardSet;  
  20. }  
  21.   
  22. class Trick {  
  23.   // A group of cards with one contributed by each player, and  
  24.   // eventually won by a player  
  25.   // One is built after each player has played a card  
  26.   isA CardSet;  
  27. }  
  28.   
  29. class Player {  
  30.    // These are the people playing.  
  31.    name;  
  32.   
  33.    // A hand is dealt at the start of a game  
  34.    // The cards a player has in his or her hand  
  35.    0..1 -- * Card hand;   
  36.   
  37.    // The tricks won by a player this game  
  38.    1 -- * Trick;   
  39.      
  40.    // All hands and tricks are cleared at the end of each game  
  41.    // ready for dealing again  
  42.   
  43.    // The following is used only in Oh Hell  
  44.    Integer currentTricksBid;  
  45. }  
  46.   
  47. class ScoringTeam {  
  48.    // for Oh Hell, it is each player for himself, so there is one player  
  49.    // for Whist there are partners, so there are two players  
  50.    1 -- 1..2 Player;  
  51.      
  52.    // The score that each team has accumulated so far  
  53.    // based on tricks taken or difference between tricks and bid  
  54.    Integer score;  
  55. }  
  56.   
  57. class CardsMatch {  
  58.   // A cards match is played in a number of games  
  59.   Boolean isWhist; // True if whist; false if Oh Hell    
  60.   
  61.   // The following determines the players  
  62.   // the first player in the first team deals first  
  63.   * -- 2..* ScoringTeam; // Exactly 2 if Whist  
  64.     
  65.   Integer scoreToWin; // The score agreed to in order to declare winner  
  66.   
  67.   1 -- * Game games; // Games continue until a player or team wins  
  68.   // Assume that the last game in games is the current one  
  69. }  
  70.   
  71. class Game {  
  72.    trumps; // a suit (if any) that is the trumps for this game  
  73.      
  74.    // One player is the dealer each game  
  75.    // The dealer deals out all or most of the cards at the start  
  76.    // Players take turn laying down cards to form the next trick  
  77.    * -- 1 Player dealer;  
  78.      
  79.    // As the cards are laid down the following set is created.  
  80.    // After all players have contributed a new trick is created from the  
  81.    // following and awarded to a player  
  82.    0..1 -- * Card currentTrickBeingBuilt;  
  83.   
  84.    * gameLed -- 0..1 Player currentLead; // the player next to lay down a card  
  85. }  
  86.   
  87.   
  88.         

Load the above code into UmpleOnline