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

Quick Search    Search Deep

Source code: org/livingpaper/hansa/TurnQueue.java


1   //
2   //  TurnQueue.java
3   //  Hansa
4   //  Provides a queue of players that automatically wraps
5   //
6   //
7   //  Created by mikel evins on Mon Aug 19 2002.
8   //  Version: $Id: TurnQueue.java,v 1.1 2003/03/15 07:23:26 mikel Exp $
9   //  Copyright (c) 2002 by mikel evins
10  //  
11  //
12  package org.livingpaper.hansa;
13  
14  import java.util.Vector;
15  
16  public class TurnQueue {
17    private int mIndex = 0;
18    private Vector mPlayers;
19    
20    public TurnQueue(){
21      mPlayers = new Vector();
22    }
23    
24    public Player getPlayer(int i){
25      return (Player)mPlayers.elementAt(i);
26    }
27  
28    public void addPlayer(Player player){
29      if (!mPlayers.contains(player)){
30        mPlayers.addElement(player);
31      }
32    }
33  
34    public void removePlayer(Player player){
35      if (!mPlayers.contains(player)){
36        mPlayers.removeElement(player);
37      }
38    }
39  
40    public int advance(){
41      mIndex++;
42      if(mIndex>=mPlayers.size()){
43        mIndex = 0;
44      }
45      return mIndex;
46    }
47  }