The code seems to work as required, but fails all of them.
Am I missing something?
package com.codegym.task.task23.task2312;
import java.security.PrivateKey;
import java.util.List;
public class Room {
public static void main(String[] args) {
Snake snake = new Snake(3,1);
game = new Room(5,2,snake);
snake.setDirection(SnakeDirection.DOWN);
game.createMouse();
game.run();
game.print();
}
private int width;
private int height;
private Snake snake;
private Mouse mouse;
public Room(int width, int height, Snake snake) {
this.width = width;
this.height = height;
this.snake = snake;
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public Snake getSnake() {
return snake;
}
public Mouse getMouse() {
return mouse;
}
public void setWidth(int width) {
this.width = width;
}
public void setHeight(int height) {
this.height = height;
}
public void setSnake(Snake snake) {
this.snake = snake;
}
public void setMouse(Mouse mouse) {
this.mouse = mouse;
}
public static Room game;
public void run() {
}
public void print() {
int[][] canvas = new int[height][width];
List<SnakeSection> list = snake.getSections();
for (SnakeSection s : list) {
canvas[s.getY()-1][s.getX()-1] = 1;
}
canvas[snake.getY()-1][snake.getX()-1] = 2;
canvas[mouse.getY()][mouse.getX()] = 3;
for (int[] h : canvas) {
System.out.println();
for (int v : h) {
if (v == 1) {
System.out.print("x");
}
else if (v == 2) {
System.out.print("X");
}else if (v == 3){
System.out.print("^");
}else
System.out.print(".");
}
}
}
public void createMouse() {
mouse = new Mouse((int) (Math.random()*width), (int) (Math.random()*height));
}
public void eatMouse() {
createMouse();
}
public void sleep() throws InterruptedException {
Thread.sleep(500);
if (snake.getSections().size() == 11) {
Thread.sleep(300);
}
if (snake.getSections().size() >= 15) {
Thread.sleep(200);
}
}
}