Class Player

java.lang.Object
  extended by java.lang.Thread
      extended by Player
All Implemented Interfaces:
java.lang.Runnable

public class Player
extends java.lang.Thread

This class contains information and methods related to Players and their pieces.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  Board b
           
protected  Piece[] checkers
           
protected  java.awt.Color color
           
protected  int direction
           
protected  boolean hasWon
           
protected  boolean isMyTurn
           
protected  java.lang.String name
           
protected  Player opponent
           
protected  int playerNumber
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Player(int pNum, int dir, java.lang.String n, Board boardRef)
          Constructor
Player(int pNum, int dir, java.lang.String n, Player otherPlayer, Board boardRef)
          Constructor
 
Method Summary
 int endTurn()
          This method ends the current players turn and updates the opponent that it is now their turn.
 int getPlayerNumber()
          This method gets the number of the player
 boolean mayMove(Board b)
          This methods determines whether a player has any moves.
 boolean playerMustJump(Board b)
          This methods determines whether a player has any pieces it must jump.
 boolean playerMustJump(Board b, int chNo)
          This methods determines whether a given piece must jump.
 int playerType()
           
 void run()
           
 void sendMove(int col1, int row1, int col2, int row2)
          This method is overridden in the NetPlayer class
 void setCheckersArray(Piece[] pieces)
          This method sets the checker array to the appropriate piece
 void setOpponent(Player otherPlayer)
          This method sets the players opponent
 int setTurn()
          This method returns the interger representing the players number and it calls threads notify.
 void waitForTurn(Board b)
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

direction

protected int direction

playerNumber

protected int playerNumber

isMyTurn

protected boolean isMyTurn

color

protected java.awt.Color color

opponent

protected Player opponent

checkers

protected Piece[] checkers

name

protected java.lang.String name

hasWon

protected boolean hasWon

b

protected Board b
Constructor Detail

Player

public Player(int pNum,
              int dir,
              java.lang.String n,
              Board boardRef)
Constructor

Parameters:
pNum - Number of player
dir - Direction
n - String for name
boardRef - Board reference

Player

public Player(int pNum,
              int dir,
              java.lang.String n,
              Player otherPlayer,
              Board boardRef)
Constructor

Parameters:
pNum - interger for player number
dir - interger for direction
n - String for name
otherPlayer - Player for opponent
boardRef - reference to the board
Method Detail

setOpponent

public void setOpponent(Player otherPlayer)
This method sets the players opponent

Parameters:
otherPlayer - Player

getPlayerNumber

public int getPlayerNumber()
This method gets the number of the player

Returns:
int that is the number of the player

endTurn

public int endTurn()
This method ends the current players turn and updates the opponent that it is now their turn.

Returns:
The player number of the player whose turn it now is.

setTurn

public int setTurn()
This method returns the interger representing the players number and it calls threads notify.

Returns:
int

sendMove

public void sendMove(int col1,
                     int row1,
                     int col2,
                     int row2)
This method is overridden in the NetPlayer class

Parameters:
col1 - column
row1 - row
col2 - column
row2 - row

setCheckersArray

public void setCheckersArray(Piece[] pieces)
This method sets the checker array to the appropriate piece

Parameters:
pieces - Piece class

playerMustJump

public boolean playerMustJump(Board b,
                              int chNo)
This methods determines whether a given piece must jump. It is an overloaded method.

Parameters:
b - A reference to the board for determining jump capabilities
chNo - Lets the method which piece to check for jump capabilities
Returns:
True if the given piece must jump

playerMustJump

public boolean playerMustJump(Board b)
This methods determines whether a player has any pieces it must jump. It is an overloaded method.

Parameters:
b - A reference to the board for determining jump capabilities
Returns:
True if any piece must jump

mayMove

public boolean mayMove(Board b)
This methods determines whether a player has any moves.

Parameters:
b - A reference to the board for determining jump capabilities
Returns:
True if any moves are possible

playerType

public int playerType()

waitForTurn

public void waitForTurn(Board b)

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread