Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public TickResult tick() {
- SnakeElement head = getSnakeHead();
- if (Direction.DOWN.equals(currentdirection)) {
- snakeBody.add(new SnakeElement(head.getX(), head.getY() + 1));
- } else if (Direction.RIGHT.equals(currentdirection)) {
- snakeBody.add(new SnakeElement(head.getX() + 1, head.getY()));
- } else if (Direction.LEFT.equals(currentdirection)) {
- snakeBody.add(new SnakeElement(head.getX() - 1, head.getY()));
- } else if (Direction.UP.equals(currentdirection)) {
- snakeBody.add(new SnakeElement(head.getX(), head.getY() - 1));
- }
- remove = true;
- head = getSnakeHead();
- if (head.getX() >= GAME_FIELDS || head.getX() <= -1 || head.getY() >= GAME_FIELDS || head.getY() <= -1) {
- return TickResult.GAME_OVER;
- }
- if (head.getX() == food.getX() && head.getY() == food.getY()) {
- remove = false;
- }
- return TickResult.RUNNING;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement