de.kosi.model.game
Class Players

java.lang.Object
  |
  +--de.kosi.model.game.Players

public class Players
extends java.lang.Object

This class handles the four players who are playing the same game of Bridge. Since there are always four players palying one game this class provides the constant NUM_PLAYERS which is set to four. Each player gets a seating assigned to him and one of the players will be the so called opener who is the player who starts the bidding sequence which is the first phase in a game of Bridge.

ChangeLog:

 $Log: Players.java,v $
 Revision 1.5  2001/07/20 14:37:08  jiriki
 Fixed Bug 440605

 Revision 1.4  2001/05/30 10:19:18  pizarro
 Updated Documentation.

 Revision 1.3  2001/05/09 17:29:41  betacarotine
 Removed a bug in getDirection

 Revision 1.2  2001/05/09 11:44:40  betacarotine
 The Table interface got a getDirection method that returns the
 direction of the calling user.

 Revision 1.1.1.1  2001/04/29 18:05:18  jiriki
 Imported sources from zola.

 Revision 1.9  2001/03/05 20:55:22  login
 - Game (und zugehoerige Klassen) soweit fertig
 - package de.kosi.model.tournament angelegt
 - Pair angelegt
 - Round angelegt
 - Movement-Interface angelegt
 - KosiMovement fertig!!! :-)
 - KosiMovementTest um das KosiMovement zu testen
       (kann mit KOSI/kosimovementtest  aufgerufen werden)
 - Tournament und TournamentImpl in das package de.kosi.model.tournament
       verschoben
 - buildfile fuer die neuen klassen angepasst

 Revision 1.8  2001/03/01 20:31:32  wombat
 Worked on table implementation / updated documentation

 Revision 1.7  2001/02/26 11:21:45  wombat
 Worked on table.

 Revision 1.6  2001/02/21 11:38:47  wombat
 Worked on GameImpl and Board

 Revision 1.5  2001/02/09 19:26:33  login
 Doc-Update

 Revision 1.4  2001/02/07 10:28:52  login
 Updated documentation!!!!

 Revision 1.3  2001/02/06 14:37:09  login
 Updated docs


 

Version:
$Revision: 1.5 $ ($Date: 2001/07/20 14:37:08 $)
Author:
Timo, Niklas, Ole

Field Summary
static int NUM_PLAYERS
          Since there are always exactly four players needed to play a game of Bridge this class provides this constant.
 
Constructor Summary
Players()
          This constructor creates a new Players instance with no players.
Players(Pair northSouth, Pair eastWest)
          This constructor creates a new Players instance with the given pairs as players.
Players(UserImpl north, UserImpl east, UserImpl south, UserImpl west)
          This constructor creates a new Players instance with the specified users as players and the specified opener direction.
 
Method Summary
 boolean contains(Player player)
          This method checks whether the given player is part of this Players instance.
 boolean contains(User user)
           
 int getDirection(User user)
          Returns the direction of the given user
 int getDistance(Player from, Player to)
          This method returns the distance between the two given players.
 Player getPlayer(int direction)
          Returns the Player who is seated at the specified direction or null if there is no player seated yet.
 java.lang.String[] getPlayerNames()
          Returns all player names of this Players instance as array.
 Player[] getPlayers()
          Returns all players of this Players instance as array.
 boolean readyToPlay()
          Returns whether this Players instance contains enough information to start playing.
 void removePlayer(int direction)
          Removes the player at the given direction.
 void removePlayer(Player player)
          Removes the given player from this Players instance, e.g. when he left the game.
 void setPlayer(Player player)
          Seats the given player at the direction stored in his own direction attribute.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NUM_PLAYERS

public static final int NUM_PLAYERS
Since there are always exactly four players needed to play a game of Bridge this class provides this constant.
Constructor Detail

Players

public Players()
This constructor creates a new Players instance with no players. This could be used if anybody opens a new table but there are no players yet to participate in the game.
Throws:
java.lang.IllegalArgumentException - If a not existing direction was given.

Players

public Players(Pair northSouth,
               Pair eastWest)
This constructor creates a new Players instance with the given pairs as players. The arguments may not be null.
Parameters:
northSouth - The pair seated north-south.
eastWest - The pair seated east-west.

Players

public Players(UserImpl north,
               UserImpl east,
               UserImpl south,
               UserImpl west)
This constructor creates a new Players instance with the specified users as players and the specified opener direction. The users may be null which would mean that there are players missing and the game cannot yet be started.
Parameters:
north - The user assigned to the player seated at north.
east - The user assigned to the player seated at east.
south - The user assigned to the player seated at south.
west - The user assigned to the player seated at west.
Method Detail

contains

public boolean contains(Player player)
This method checks whether the given player is part of this Players instance.
Parameters:
player - The player of whom we want to find out whether he is part of this Players instance.
Returns:
true if the given player is part of this Players instance, otherwise false.

contains

public boolean contains(User user)

getDistance

public int getDistance(Player from,
                       Player to)
This method returns the distance between the two given players. This means if it was player "from"'s turn, how long has player "to" to wait for his turn. If player "from" and player "to" were identical this method returns 0 - if player "to" was the next player after player "from" this method returns 1 - if there is one player seated between "from" and "to" this method returns 2 and so on.
Parameters:
from - The player from which we want to measure the distance.
to - The player to which we want to measure the distance.
Returns:
The distance between the two given players.
Throws:
java.lang.IllegalArgumentException - If one of the given players is not part of this Players instance.

getPlayer

public Player getPlayer(int direction)
Returns the Player who is seated at the specified direction or null if there is no player seated yet.
Parameters:
direction - The direction of the player we are interested in. Must be one of the constants Player.NORTH, Player.EAST, Player.SOUTH, Player.WEST.
Returns:
The Player who is seated at the specified direction.
Throws:
ArrayIndexOutOfBoundsException - If the given direction was illegal.

removePlayer

public void removePlayer(int direction)
Removes the player at the given direction. This must be done if a player leaves a game.
Parameters:
direction - The direction of the player who left the game. Must be one of the constants Player.NORTH, Player.EAST, Player.SOUTH, Player.WEST.
Throws:
ArrayIndexOutOfBoundsException - If the direction was invalid.

removePlayer

public void removePlayer(Player player)
Removes the given player from this Players instance, e.g. when he left the game.
Parameters:
player - The player to remove from this Players instance.
Throws:
java.lang.IllegalArgumentException - If the given player wasn't part of this players instance.

setPlayer

public void setPlayer(Player player)
Seats the given player at the direction stored in his own direction attribute. This replaces a user already seated in this direction.
Parameters:
player - The new player.

getPlayers

public Player[] getPlayers()
Returns all players of this Players instance as array. This method will never return null but some fields may be null if there is no player seated. The indexes are assigned to the directions in the following way: 0 - north, 1 - east, 2 - south, 3 - west. The length of the returned array will always be four.
Returns:
An array containing the players of this Players instance.

getPlayerNames

public java.lang.String[] getPlayerNames()
Returns all player names of this Players instance as array. This method will never return null but some fields may be null if there is no player seated. The indexes are assigned to the directions in the following way: 0 - north, 1 - east, 2 - south, 3 - west. The length of the returned array will always be four.
Returns:
An String array containing the player names of this Players instance.

readyToPlay

public boolean readyToPlay()
Returns whether this Players instance contains enough information to start playing. This means that a player has to be seated at each direction.
Returns:
true if we can start playing, otherwise false.

getDirection

public int getDirection(User user)
                 throws java.lang.IllegalArgumentException
Returns the direction of the given user
Parameters:
user - The user whose direction should be returned.
Returns:
The direction constant.
Throws:
java.lang.IllegalArgumentException - If the user isn't contained by the players object