Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This class creates a creature and makes it possible for the creature to move to different cells.
- * @author Mees van der Meij
- */
- public abstract class Creature
- /**
- * This Class creature is abstract because it is not specified what kind of creature it is.
- */
- {
- private int dexterity =1;
- private Cell currentCell;
- public final void moveTo(Cell newCell)
- /**
- * the method moveTo checks if a creature is in an existing cell, if so removes it from this Cell.
- * then adds the creature to the new cell.
- */
- {
- if (currentCell!= null)
- {
- currentCell.removeCreature(this);
- }
- newCell.addCreature(this);
- currentCell = newCell;
- }
- public final Cell getCurrentCell()
- /**
- * getCurrentCell returns the cell this creature is currently in.
- */
- {
- return currentCell;
- }
- public abstract void move();
- /**
- * The method move allows the creature to move to a different cell
- */
- public abstract void act();
- /**
- * The method act allows the creature to do something.
- */
- public int getDexterity()
- /**
- * The method getDexteriy returns the dexterity of the creature
- */
- {
- return dexterity;
- }
- public final void die()
- /**
- * The method die kills the creature by moving its current cell to null.
- */
- {
- currentCell.removeCreature(this);
- currentCell= null;
- }
- public final boolean isAlive()
- /**
- * The method isAlive checks if a creature is alive by checking if it's current cell is null.
- */
- {
- if (currentCell != null)
- {
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement