public void print() {
int[][] pole = new int[width][height];
pole[snake.getSections().get(0).getY()][snake.getSections().get(0).getX()] = 2;
for (int i = 1; i < snake.getSections().size(); i++) {
pole[snake.getSections().get(i).getY()][snake.getSections().get(i).getX()] = 1;
}
pole[mouse.getY()][mouse.getX()] = 3;
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++){
if (pole[i][j] == 1) {
System.out.print("x");
} else if (pole[i][j] == 2) {
System.out.print("X");
} else if (pole[i][j] == 3) {
System.out.print("^");
} else {
System.out.print(".");
}
}
System.out.println();
}
}
не пропускает 2 и 3 пункты. В чем проблема?package com.javarush.task.task23.task2312;
import java.util.ArrayList;
public class Room {
private int width;
private int height;
private Snake snake;
private Mouse mouse;
public static Room game;
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 Room(int width, int height, Snake snake) {
this.width = width;
this.height = height;
this.snake = snake;
}
public void run(){
}
public void print() {
int[][] pole = new int[width][height];
pole[snake.getSections().get(0).getY()][snake.getSections().get(0).getX()] = 2;
ArrayList<SnakeSection> sections = new ArrayList<SnakeSection>(snake.getSections());
for (SnakeSection snakeSection : sections) {
pole[snakeSection.getY()][snakeSection.getX()] = 1;
}
pole[mouse.getY()][mouse.getX()] = 3;
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++){
if (pole[i][j] == 1) {
System.out.print("x");
} else if (pole[i][j] == 2) {
System.out.print("X");
} else if (pole[i][j] == 3) {
System.out.print("^");
} else {
System.out.print(".");
}
}
System.out.println();
}
}
public void createMouse(){
int x = (int) (Math.random() * width);
int y = (int) (Math.random() * height);
this.mouse = new Mouse(x,y);
}
public void eatMouse(){
createMouse();
}
public void sleep() throws InterruptedException {
if (snake.getSections().size() <= 10) Thread.sleep(500);
else if (snake.getSections().size() <= 14) Thread.sleep(300);
else Thread.sleep(200);
}
public static void main(String[] args) {
Snake snake1 = new Snake(10,10);
game = new Room(20, 20, snake1);
game.snake.setDirection(SnakeDirection.DOWN);
game.createMouse();
game.run();
game.print();
}
}