Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/zazof/jteg/CardList.java


1   /**
2   *
3   *  This class is responsible for maintaining a cardlist.
4   * 
5   *  @author Yves Vandewoude
6   */
7   
8   package org.zazof.jteg;
9   
10  import java.util.Vector;
11  import java.util.Enumeration;
12  
13  
14  public class CardList {
15    
16    public CardList() {
17            $cards = new Vector();
18            $cards.add(new Card(1));
19            $cards.add(new Card(2));
20            $cards.add(new Card(3));
21            $cards.add(new Card(4));
22            $cards.add(new Card(5));
23        }
24  
25      
26  /**
27    *  DeActivate the card with the specified CountryID. If no card exists with the countryID, nothing happens
28    *
29    *  @param The countryID
30    *
31    *  
32    */
33    public void deActivateCard(int countryID) {
34      Vector activeCards = getActiveCards();
35      Card currentCard;
36      for (int index=0; index < activeCards.size(); index++)
37      {
38        currentCard = (Card) activeCards.elementAt(index);
39        if (currentCard.getCountry().getID() == countryID)
40          {
41            if (DEBUG) System.out.println("Card with countrycode " + countryID + " ("+currentCard.getCountry().getCountryName()+") will be deActivated now..."); 
42            currentCard.deActivate();
43            if (DEBUG) System.out.println("Card with countrycode " + countryID + " ("+currentCard.getCountry().getCountryName()+") is deActivated"); 
44          }
45           }
46             
47    }
48  
49  
50  /**
51    *
52    *  Get a free card
53    *
54    *  @return A card which is currently not used
55    *
56    */
57    public Card getFreeCard()
58      throws NoFreeCardException
59    {
60      Card currentCard;
61      for (int i = 0; i < 5; i++)
62        {
63          currentCard = (Card) $cards.elementAt(i);
64          if (!(currentCard.isActive()))
65                      return currentCard;
66        }
67      throw new NoFreeCardException("Sorry, all 5 cards seem to be in use");
68    }
69  
70  /**
71    *
72    *  Get the cards in this cardlist
73    *
74    */
75    public Enumeration getCards()
76      {
77        return $cards.elements();
78      }
79  
80  /**
81    *
82    *  Get the selected (and active) cards in this cardlist
83    *
84    */
85    public Vector getSelectedCards()
86    {
87      Vector baseVector = new Vector(5);
88      Card currentCard;
89      for (int i = 0; i < 5; i++)
90        {
91          currentCard = (Card) $cards.elementAt(i);
92          if (currentCard.isActive() && currentCard.isSelected())
93            baseVector.add(currentCard);
94        }
95      return baseVector;  
96      
97    }
98  
99  /**
100   *
101   *  Get the active cards in this cardlist. These are the cards this player HAS
102   *
103   */
104   public Vector getActiveCards()
105   {
106     Vector baseVector = new Vector(5);
107     Card currentCard;
108     for (int i = 0; i < 5; i++)
109       {
110         currentCard = (Card) $cards.elementAt(i);
111         if (currentCard.isActive())
112           baseVector.add(currentCard);
113       }
114     return baseVector;  
115     
116   }
117 
118     
119 /**
120   *  Get the number of selected (and active) cards.
121   *
122   */    
123   public int getNumberOfSelectedCards()
124     {
125     Card currentCard;
126     int selectedCards = 0;
127     for (int i = 0; i < 5; i++)
128       {
129         currentCard = (Card) $cards.elementAt(i);
130         if (currentCard.isActive() && currentCard.isSelected())
131           selectedCards++;
132       }
133     return selectedCards;
134     }
135 
136       
137           
138     private Vector $cards;
139     private static boolean DEBUG = false;
140 }