Class Trainer

java.lang.Object
  |
  +--java.awt.Component
        |
        +--MapObject
              |
              +--People
                    |
                    +--Trainer
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.lang.Runnable, java.io.Serializable

public class Trainer
extends People
implements java.lang.Runnable

Implementation of a Trainer, a Person with a Badge, and not able to move around the Grid. Name still needs to be unique for a Grid as this is used for equals.

See Also:
Person, People, Grid, Serialized Form

Field Summary
protected  java.lang.String badge
          The name of the badge
protected static java.awt.Image bimg
          The Images associated with the Four directions, Up, Left, Down, Right/
protected  Grid g
          The Grid I am on
protected static java.awt.Image img
          The Images associated with the Four directions, Up, Left, Down, Right/
protected static java.awt.Image limg
          The Images associated with the Four directions, Up, Left, Down, Right/
protected static java.awt.Image rimg
          The Images associated with the Four directions, Up, Left, Down, Right/
 
Fields inherited from class People
activeMon, battling, beaten, behind, dir, dlg, hmon, items, MAXMON, mon, money, name
 
Fields inherited from class MapObject
BUILDING, enterable, FLOOR, GRASS, MONSTER, PERSON, PLAYER, REDIRECT, ROCK, TRAINER, type, WALL
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Trainer()
          Constructs a default Trainer No money, Grass as behind MapObject Name of NPC Badge of Name No Monsters No Dialogue
Trainer(int dir)
          Constructs a Trainer facing in direction dir No money, Grass as behind MapObject Name of NPC Badge of Name No Monsters No Dialogue
Trainer(MapObject behind)
          Constructs a Trainer with MapObject underneath No money, Name of NPC Badge of Name No Monsters No Dialogue
Trainer(MapObject behind, int dir)
          Constructs a Trainer with MapObject underneath and facing dir.
Trainer(java.lang.String name)
          Constructs a Trainer with Name name.
Trainer(java.lang.String name, MapObject behind, int dir)
          Constructs a Trainer with Name name, Standing on behind, and facing dir.
 
Method Summary
 java.lang.String getBadge()
          Gets the name of the Badge carried.
 MapObject getClone()
          Returns a clone of this, a Trainer with the same name and direction facing.
 void paint(java.awt.Graphics g)
          Draws the image associated with Trainer, and the MapObject this is on.
 MapObject peopleNextTo(int i, int j)
          Determines the Player that is next to this, that are within one square any direction including diagonally.
 void run()
          Check if there is a Player to battle, and sleep for one second between checks.
 void setBadge(java.lang.String bad)
          Sets the name of the badge carried by the Trainer.
 void setGrid(Grid g)
          Sets the Grid that this is on, and starts the Thread for checking if a Player enters the sight of this.
 void setImage(java.awt.Image[] img)
          Sets the static Image for this class.
 void setName(java.lang.String name)
          Sets the name of the Trainer.
 
Methods inherited from class People
addItem, addMonster, addMonsterHome, battle, beat, getActiveMonster, getBehind, getDialogue, getDirection, getItem, getItemCount, getItems, getMoney, getMonster, getMonsterAtHome, getMonsterAttacks, getMonsters, getName, getNumberOfMonsters, getNumberOfMonstersAtHome, healAllMonsters, isBattling, isBeaten, isEnterable, setActiveMonster, setBehind, setDialogue, setDirection, setMoney, stopBattle, switchMonster, useItem
 
Methods inherited from class MapObject
canBeEntered, getType
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

img

protected static java.awt.Image img
The Images associated with the Four directions, Up, Left, Down, Right/


bimg

protected static java.awt.Image bimg
The Images associated with the Four directions, Up, Left, Down, Right/


limg

protected static java.awt.Image limg
The Images associated with the Four directions, Up, Left, Down, Right/


rimg

protected static java.awt.Image rimg
The Images associated with the Four directions, Up, Left, Down, Right/


badge

protected java.lang.String badge
The name of the badge


g

protected Grid g
The Grid I am on

Constructor Detail

Trainer

public Trainer()
Constructs a default Trainer No money, Grass as behind MapObject Name of NPC Badge of Name No Monsters No Dialogue


Trainer

public Trainer(int dir)
Constructs a Trainer facing in direction dir No money, Grass as behind MapObject Name of NPC Badge of Name No Monsters No Dialogue

Parameters:
dir - the direction to face, specified in Grid
See Also:
Grid

Trainer

public Trainer(MapObject behind)
Constructs a Trainer with MapObject underneath No money, Name of NPC Badge of Name No Monsters No Dialogue

Parameters:
behind - The MapObject standing on

Trainer

public Trainer(MapObject behind,
               int dir)
Constructs a Trainer with MapObject underneath and facing dir. No money, Name of NPC Badge of Name No Monsters No Dialogue

Parameters:
behind - The MapObject standing on
dir - the Direction facing, specified in Grid
See Also:
Grid

Trainer

public Trainer(java.lang.String name)
Constructs a Trainer with Name name. No money, Grass as behind MapObject Badge of Name No Monsters No Dialogue

Parameters:
name - The name of the Trainer

Trainer

public Trainer(java.lang.String name,
               MapObject behind,
               int dir)
Constructs a Trainer with Name name, Standing on behind, and facing dir. No money, Badge of Name No Monsters No Dialogue

Parameters:
name - The Name of the Trainer
behind - The MapObject standing on
dir - The direction facing, specified in Grid
See Also:
Grid
Method Detail

setImage

public void setImage(java.awt.Image[] img)
Sets the static Image for this class. Requires a call to this before a call to paint.

Specified by:
setImage in class MapObject
Parameters:
img - the Image of the Trainer

setName

public void setName(java.lang.String name)
Sets the name of the Trainer.

Overrides:
setName in class People
Parameters:
name - The Name of the Trainer, must be unique on a Grid.

setBadge

public void setBadge(java.lang.String bad)
Sets the name of the badge carried by the Trainer.


getBadge

public java.lang.String getBadge()
Gets the name of the Badge carried.

Returns:
The name of the badge carried.

getClone

public MapObject getClone()
Returns a clone of this, a Trainer with the same name and direction facing.

Specified by:
getClone in class MapObject
Returns:
A new MapObject of this.

peopleNextTo

public MapObject peopleNextTo(int i,
                              int j)
Determines the Player that is next to this, that are within one square any direction including diagonally.

Parameters:
i - the i'th location in Grid.
j - the j'th location in Grid.
Returns:
The MapObject of the Player near this.
See Also:
Grid, Player, People

setGrid

public void setGrid(Grid g)
Sets the Grid that this is on, and starts the Thread for checking if a Player enters the sight of this.

Parameters:
g - the Grid this is on, set to null to stop this Thread

run

public void run()
Check if there is a Player to battle, and sleep for one second between checks. Ends when this.grid is null or the name of this.badge is not "".

Specified by:
run in interface java.lang.Runnable

paint

public void paint(java.awt.Graphics g)
Draws the image associated with Trainer, and the MapObject this is on.

Overrides:
paint in class java.awt.Component
See Also:
MapObject