Advertisement
Guest User

b

a guest
Oct 17th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. /**
  2. * This class creates a creature and makes it possible for the creature to move to different cells.
  3. * @author Mees van der Meij
  4. */
  5. public abstract class Creature
  6. /**
  7. * This Class creature is abstract because it is not specified what kind of creature it is.
  8. */
  9. {
  10. private int dexterity =1;
  11. private Cell currentCell;
  12. public final void moveTo(Cell newCell)
  13. /**
  14. * the method moveTo checks if a creature is in an existing cell, if so removes it from this Cell.
  15. * then adds the creature to the new cell.
  16. */
  17. {
  18. if (currentCell!= null)
  19. {
  20. currentCell.removeCreature(this);
  21. }
  22. newCell.addCreature(this);
  23. currentCell = newCell;
  24. }
  25. public final Cell getCurrentCell()
  26. /**
  27. * getCurrentCell returns the cell this creature is currently in.
  28. */
  29. {
  30. return currentCell;
  31. }
  32.  
  33. public abstract void move();
  34. /**
  35. * The method move allows the creature to move to a different cell
  36. */
  37. public abstract void act();
  38. /**
  39. * The method act allows the creature to do something.
  40. */
  41.  
  42. public int getDexterity()
  43. /**
  44. * The method getDexteriy returns the dexterity of the creature
  45. */
  46. {
  47. return dexterity;
  48. }
  49. public final void die()
  50. /**
  51. * The method die kills the creature by moving its current cell to null.
  52. */
  53. {
  54. currentCell.removeCreature(this);
  55. currentCell= null;
  56. }
  57. public final boolean isAlive()
  58. /**
  59. * The method isAlive checks if a creature is alive by checking if it's current cell is null.
  60. */
  61. {
  62. if (currentCell != null)
  63. {
  64. return true;
  65. }
  66. return false;
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement