Class AbstractPlayer

java.lang.Object
  extended by AbstractPlayer
All Implemented Interfaces:
IPlayer
Direct Known Subclasses:
AbstractAutoPlayer, HumanPlayer

public abstract class AbstractPlayer
extends java.lang.Object
implements IPlayer

Supplies default implementation and state for a player. Allows a player to access a model, a view, and to store words found in a game. This implementation uses a set to store strings/words and updates score for new words added to the player. Words are not checked for being in a lexicon or on a board.

Author:
Owen Astrachan

Field Summary
protected  BoggleModel myModel
           
protected  int myScore
           
protected  IPlayerView myView
           
protected  java.util.TreeSet<java.lang.String> myWords
           
 
Constructor Summary
AbstractPlayer()
           
 
Method Summary
 void add(java.lang.String word)
          Add a word to this player's list of words, adjust score if word is new to this player.
abstract  java.lang.String getName()
          Return the name of a player.
 int getScore()
          Get the score for this player, see BoggleModel for how scores are calculated.
 void initialize(BoggleModel model)
          Make this player have an associated model, and initialize other state appropriately.
 void setView(IPlayerView view)
          Set a veiw for this player, if not called the player will have a null view.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myModel

protected BoggleModel myModel

myView

protected IPlayerView myView

myWords

protected java.util.TreeSet<java.lang.String> myWords

myScore

protected int myScore
Constructor Detail

AbstractPlayer

public AbstractPlayer()
Method Detail

initialize

public void initialize(BoggleModel model)
Make this player have an associated model, and initialize other state appropriately.

Specified by:
initialize in interface IPlayer
Parameters:
model - is the model for this player

setView

public void setView(IPlayerView view)
Set a veiw for this player, if not called the player will have a null view.

Specified by:
setView in interface IPlayer
Parameters:
view - is this player's view

getScore

public int getScore()
Description copied from interface: IPlayer
Get the score for this player, see BoggleModel for how scores are calculated.

Specified by:
getScore in interface IPlayer
Returns:
current score for this player

add

public void add(java.lang.String word)
Add a word to this player's list of words, adjust score if word is new to this player. Duplicate words are not added, board and lexicon are not checked.

Specified by:
add in interface IPlayer
Parameters:
word - is the word added to this player

getName

public abstract java.lang.String getName()
Description copied from interface: IPlayer
Return the name of a player.

Specified by:
getName in interface IPlayer
Returns:
this player's name