Edit:
Я попытался заставить это работать снова, но я не мог понять это, мне было интересно, не пропало ли что-то, так что это весь код
public class GameEngine {
public static final int GameWidth = 28;
public static final int GameHeight = 42;
private List<Coordinate> walls = new ArrayList<>();
private List<Coordinate> snake = new ArrayList<>();
private Direction currentDirection = Direction.East;
private GameState currentGameState = GameState.Running;
public void Update(){
//snake
switch (currentDirection){
case North:
UpdateSnake(0,-1);
break;
case East:
UpdateSnake(1,0);
break;
case South:
UpdateSnake(0,1);
break;
case West:
UpdateSnake(-1,0);
break;
}
for (Coordinate W: walls){
if (snake.get(0).equals(W)){
currentGameState = GameState.Lost;
}
}
}
public GameEngine() {
}
public void initGame() {
AddSnake();
AddWalls();
}
public TileType[][] getMap (){
TileType[][] map = new TileType[GameWidth][GameHeight];
for (int x = 0; x < GameWidth; x++){
for (int y = 0; y < GameHeight; y++)
map [x][y] = TileType.Nothing;
}
for (Coordinate s: snake){
map [s.getX()][s.getY()] = TileType.SnakeTail;
}
map[snake.get(0).getX()][snake.get(0).getY()] = TileType.SnakeHead;
for (Coordinate wall: walls){
map[wall.getX()][wall.getY()] = TileType.Wall;
}
return map;
}
private void UpdateSnake (int x, int y){
TileType[][] map = getMap();
for (int i = snake.size() -1 ; i > 0 ; i--){
map[snake.get(0).getX()][snake.get(0).getY()] = TileType.SnakeTail;
snake.get(i).setY(snake.get(i-1).getY());
}
snake.get(0).setX(snake.get(0).getX()+x);
snake.get(0).setY(snake.get(0).getY()+y);
}
private void AddSnake(){
snake.clear();
snake.add(new Coordinate(7,7));
snake.add(new Coordinate(6,7));
snake.add(new Coordinate(5,7));
snake.add(new Coordinate(4,7));
snake.add(new Coordinate(3,7));
snake.add(new Coordinate(2,7));
}
private void AddWalls() {
for (int x = 0; x < GameWidth; x++) {
walls.add(new Coordinate(x, 0));
walls.add(new Coordinate(x, GameHeight - 1));
}
for (int y = 1; y < GameHeight; y++) {
walls.add(new Coordinate(0, y));
walls.add(new Coordinate(GameWidth - 1, y));
}
}
public GameState getCurrentGameState() {
return currentGameState;
}
Я попробовал ответ ниже, но ошибки продолжались, и я не могу понять, почему.
Когда я пытался вставить карту обновления, предполагалось, что карта всегда подчеркивалась, как и функции get