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

Quick Search    Search Deep

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


1   /**
2   *
3   *  This class is responsible for maintaining a countrylist.
4   * 
5   *  @author Yves Vandewoude
6   *     @author Jef De Geeter
7   */
8   
9   package org.zazof.jteg;
10  
11  import java.util.Vector;
12  import java.util.Enumeration;
13  import java.awt.*;
14  import java.awt.image.*;
15  import org.zazof.jteg.gui.*;
16  
17  
18  public class CountryList {
19      public CountryList() {
20          countries = new Vector(50);
21      }
22  
23      public Country getCountry(int country_id) throws Exception {
24          Country c;
25          Enumeration elements = countries.elements();
26          while (elements.hasMoreElements()) {
27              c = (Country)elements.nextElement();
28              if (c.getID() == country_id) return c;
29          }
30          throw new Exception("There exists no country with id: " + country_id);
31      }
32  
33      public void addCountry(Country c) {
34          countries.add(c);
35      }
36  
37    /**
38     *  unselects all countries
39     */
40    public void unselectAll(){
41      Country c;
42      Enumeration e;
43      e = countries.elements();
44      while (e.hasMoreElements()){
45        c = (Country) e.nextElement();
46        c.unselect();
47      }
48    }
49  
50    public Country getCountryByOwner(Player owner) throws Exception{
51      Country tmp;
52      int player_id = owner.getID();
53      Enumeration e = getCountryElements();
54      while(e.hasMoreElements()){
55        tmp = (Country) e.nextElement();
56        if (tmp.getOwner().getID() == player_id) return tmp;
57      }
58      throw new Exception("The player " + owner.getName() + " doesn't own any country");
59    }
60  
61      public Enumeration getCountryElements()
62      {
63          return countries.elements();
64      }
65  
66      private Vector countries;
67  }