Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void doTurn(IGame game) {
- if (food == 0)
- hp--;
- else
- food--;
- if (hp < 1)
- return;
- List<GridDirection> possibleMoves = game.getPossibleMoves();
- IMapView map = game.getMap();
- for (GridDirection dir: possibleMoves) {
- ILocation loc = map.getNeighbour(game.getLocation(),dir);
- for (IItem item : map.getAll(loc)) {
- if (item instanceof IPlayer) {
- game.attack(dir, item);
- System.out.println("Attacked player");
- return;
- }
- else if (item.isEdible()) {
- System.out.println("found "+ item.getName());
- int eaten = item.handleDamage(game, this, 5);
- if (eaten > 0) {
- System.out.println("ate carrot worth " + eaten + "!");
- food += eaten;
- game.displayMessage("You hear a faint crunching (" + getName() + " eats " + item.getArticle() + " "
- + item.getName() + ")");
- return;
- }
- }
- }
- }
- if (possibleMoves.size() == 0) {
- return;
- }
- game.move(possibleMoves.get(0));
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement