I have tried everything and nothing seems to pass validation. Does anyone see what is wrong?
package com.codegym.task.task23.task2312;
import java.util.List;
public class Room {
private int width;
private int height;
private Snake snake;
private Mouse mouse;
static Room game;
public static void main(String[] args) {
Snake snake = new Snake(10,10);
snake.setDirection(SnakeDirection.DOWN);
game = new Room(20,20, snake);
game.createMouse();
game.run();
}
public Room(int width, int height, Snake snake) {
this.width = width;
this.height = height;
this.snake = snake;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public Snake getSnake() {
return snake;
}
public void setSnake(Snake snake) {
this.snake = snake;
}
public Mouse getMouse() {
return mouse;
}
public void setMouse(Mouse mouse) {
this.mouse = mouse;
}
public void run() {
print();
}
public void sleep() {
int sleepTime = 500;
int snakeLength = snake.getSections().size();
int algorithm = (snakeLength - 1) * 20;
if (snakeLength > 1 && snakeLength < 12) sleepTime -= algorithm;
if (snakeLength > 11 && snakeLength < 16) sleepTime -= algorithm + (5 * (snakeLength - 11));
if (snakeLength > 15) sleepTime = 200;
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void print() {
int[][] roomDisplay = new int[height][width];
List<SnakeSection> sections = snake.getSections();
// add snake location to roomDisplay
// head
SnakeSection head = snake.getHead();
roomDisplay[head.getY()][head.getX()] = 2;
// body
for (int i = 0; i < sections.size(); i++) {
SnakeSection section = sections.get(i);
roomDisplay[section.getY()][section.getX()] = 1;
}
// add mouse location to roomDisplay
roomDisplay[mouse.getY()][mouse.getX()] = 3;
// draw the room
for (int y = 0; y < height; y++) {
StringBuilder sb = new StringBuilder();
for (int x = 0; x < width; x++) {
if (roomDisplay[y][x] != 0) {
if (roomDisplay[y][x] == 1) sb.append("x");
if (roomDisplay[y][x] == 2) sb.append("X");
if (roomDisplay[y][x] == 3) sb.append("^");
} else {
// prints border section
if (y == 0 || y == height - 1) sb.append(".");
else if (x == 0 || x == width - 1) sb.append(".");
else sb.append(" ");
}
}
System.out.println(sb.toString());
}
}
void createMouse() {
int x = (int)(Math.random() * width);
int y = (int)(Math.random() * height);
mouse = new Mouse(x, y);
}
void eatMouse() {
createMouse();
}
}