Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //nhận vào hướng nhấn phím và phần tử ô cần kiểm tra
- //kiểm tra ô tiếp theo ở hướng nhấn phím là phần tử ô nào đó
- public boolean onTile(MapElement mapElement, Direction direction) {
- int x = bear.getTitleX();
- int y = bear.getTitleY();
- switch (mapElement) {
- case QUESTION:
- // kiểm nếu ô tiếp theo là ô câu hỏi, và ở hướng phải, đúng trả về true
- if (direction == Direction.RIGHT)
- return gameMap.getMap(x + 1, y).equals("q");
- else if (direction == Direction.LEFT)
- return gameMap.getMap(x - 1, y).equals("q");
- else if (direction == Direction.UP)
- return gameMap.getMap(x, y - 1).equals("q");
- else if (direction == Direction.DOWN)
- return gameMap.getMap(x, y + 1).equals("q");
- case ROCK:
- if (direction == Direction.RIGHT)
- return gameMap.getMap(x + 1, y).equals("r");
- else if (direction == Direction.LEFT)
- return gameMap.getMap(x - 1, y).equals("r");
- else if (direction == Direction.UP)
- return gameMap.getMap(x, y - 1).equals("r");
- else if (direction == Direction.DOWN)
- return gameMap.getMap(x, y + 1).equals("r");
- case HONEY:
- if (direction == Direction.RIGHT)
- return gameMap.getMap(x + 1, y).equals("h");
- else if (direction == Direction.LEFT)
- return gameMap.getMap(x - 1, y).equals("h");
- else if (direction == Direction.UP)
- return gameMap.getMap(x, y - 1).equals("h");
- else if (direction == Direction.DOWN)
- return gameMap.getMap(x, y + 1).equals("h");
- default:
- return false;
- }
- }
- public void moveBear(Direction direction) {
- this.hasMove = true;
- bear.move(direction);
- notifyChanged();
- this.hasMove = false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement