Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1.     @Override
  2.     public void doTurn(IGame game) {
  3.         if (food == 0)
  4.             hp--;
  5.         else
  6.             food--;
  7.         if (hp < 1)
  8.             return;
  9.        
  10.         List<GridDirection> possibleMoves = game.getPossibleMoves();
  11.         IMapView map = game.getMap();
  12.         for (GridDirection dir: possibleMoves) {
  13.            
  14.             ILocation loc = map.getNeighbour(game.getLocation(),dir);
  15.             for (IItem item : map.getAll(loc)) {
  16.                 if (item instanceof IPlayer) {
  17.                     game.attack(dir, item);
  18.                     System.out.println("Attacked player");
  19.                     return;
  20.                 }
  21.                 else if (item.isEdible()) {
  22.                     System.out.println("found "+ item.getName());
  23.                     int eaten = item.handleDamage(game, this, 5);
  24.                     if (eaten > 0) {
  25.                         System.out.println("ate carrot worth " + eaten + "!");
  26.                         food += eaten;
  27.                         game.displayMessage("You hear a faint crunching (" + getName() + " eats " + item.getArticle() + " "
  28.                                               + item.getName() + ")");
  29.                         return;
  30.                       }
  31.                 }
  32.             }
  33.         }
  34.         if (possibleMoves.size() == 0) {
  35.             return;
  36.         }
  37.         game.move(possibleMoves.get(0));
  38.         return;
  39.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement