Advertisement
pastetumlum

Untitled

Jul 14th, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1.     //nhận vào hướng nhấn phím và phần tử ô cần kiểm tra
  2.     //kiểm tra ô tiếp theo ở hướng nhấn phím là phần tử ô nào đó
  3.     public boolean onTile(MapElement mapElement, Direction direction) {
  4.         int x = bear.getTitleX();
  5.         int y = bear.getTitleY();
  6.         switch (mapElement) {
  7.         case QUESTION:
  8.             // kiểm nếu ô tiếp theo là ô câu hỏi, và ở hướng phải, đúng trả về true
  9.             if (direction == Direction.RIGHT)
  10.                 return gameMap.getMap(x + 1, y).equals("q");
  11.             else if (direction == Direction.LEFT)
  12.                 return gameMap.getMap(x - 1, y).equals("q");
  13.             else if (direction == Direction.UP)
  14.                 return gameMap.getMap(x, y - 1).equals("q");
  15.             else if (direction == Direction.DOWN)
  16.                 return gameMap.getMap(x, y + 1).equals("q");
  17.         case ROCK:
  18.             if (direction == Direction.RIGHT)
  19.                 return gameMap.getMap(x + 1, y).equals("r");
  20.             else if (direction == Direction.LEFT)
  21.                 return gameMap.getMap(x - 1, y).equals("r");
  22.             else if (direction == Direction.UP)
  23.                 return gameMap.getMap(x, y - 1).equals("r");
  24.             else if (direction == Direction.DOWN)
  25.                 return gameMap.getMap(x, y + 1).equals("r");
  26.         case HONEY:
  27.             if (direction == Direction.RIGHT)
  28.                 return gameMap.getMap(x + 1, y).equals("h");
  29.             else if (direction == Direction.LEFT)
  30.                 return gameMap.getMap(x - 1, y).equals("h");
  31.             else if (direction == Direction.UP)
  32.                 return gameMap.getMap(x, y - 1).equals("h");
  33.             else if (direction == Direction.DOWN)
  34.                 return gameMap.getMap(x, y + 1).equals("h");
  35.         default:
  36.             return false;
  37.         }
  38.     }
  39.  
  40.     public void moveBear(Direction direction) {
  41.         this.hasMove = true;
  42.         bear.move(direction);
  43.         notifyChanged();
  44.         this.hasMove = false;
  45.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement