Class AbstractPlayer

java.lang.Object
  extended by AbstractPlayer
All Implemented Interfaces:
IPlayer, java.lang.Iterable<java.lang.String>
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 a view, a scorekeeper, a lexicon 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 int the add method.


Field Summary
protected  ILexicon myLexicon
           
protected  int myScore
           
protected  BoggleScore myScoreKeeper
           
protected  IPlayerView myView
           
protected  java.util.TreeSet<java.lang.String> myWords
           
 
Constructor Summary
AbstractPlayer()
           
 
Method Summary
 boolean add(java.lang.String word)
          Add a word to this player's list of words, adjust score if word is new to this player.
 void clear()
          Clear state of a player, e.g., as in a new game.
abstract  java.lang.String getName()
          Return the name of a player.
 int getScore()
          Return the player's score (as calculated via updates to the add method).
 void initialize(ILexicon lex)
          Make this player have an associated lexicon and initialize other state appropriately.
 java.util.Iterator<java.lang.String> iterator()
           
 void setView(IPlayerView view)
          Set a veiw for this player, if not called the player will have a null view.
 int wordCount()
          Return number of unique words added by this player.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myLexicon

protected ILexicon myLexicon

myView

protected IPlayerView myView

myWords

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

myScoreKeeper

protected BoggleScore myScoreKeeper

myScore

protected int myScore
Constructor Detail

AbstractPlayer

public AbstractPlayer()
Method Detail

initialize

public void initialize(ILexicon lex)
Make this player have an associated lexicon and initialize other state appropriately.

Specified by:
initialize in interface IPlayer
Parameters:
lex - is the lexicon 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()
Return the player's score (as calculated via updates to the add method).

Specified by:
getScore in interface IPlayer
Returns:
this player's score

add

public boolean 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
Returns:
TODO

iterator

public java.util.Iterator<java.lang.String> iterator()
Specified by:
iterator in interface java.lang.Iterable<java.lang.String>

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

clear

public void clear()
Description copied from interface: IPlayer
Clear state of a player, e.g., as in a new game.

Specified by:
clear in interface IPlayer

wordCount

public int wordCount()
Description copied from interface: IPlayer
Return number of unique words added by this player.

Specified by:
wordCount in interface IPlayer
Returns:
number of words