//////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// abstract class Sprite { private int row; private int col; private int width; private int height; private color backgroundColor; public Sprite(int _w, int _h) { setWidth(_w); setHeight(_h); } public int getRow() { return row; } public int getCol() { return col; } public int getWidth() { return width; } public int getHeight() { return height; } public int getColor() { return backgroundColor; } public void setRow(int _r) { row = _r; } public void setCol(int _c) { col = _c; } public void setWidth(int _w) { width = _w; } public void setHeight(int _h) { height = _h; } public void setColor(color _c) { backgroundColor = _c; } } //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// class Player extends Sprite { public static final int up = 1; public static final int left = 2; public static final int down = 3; public static final int right = 4; public Player() { super(0, 0); setColor(color(153, 217, 234)); // blue knight } } //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// class EmptySpace extends Sprite { public EmptySpace() { super(0, 0); setColor(color(0, 0, 0)); // plain darkness } } //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// class Wall extends Sprite { public Wall() { super(0, 0); setColor(color(255, 126, 0)); // orange brick } } //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// class World { private Player player; private int rows; private int cols; Sprite[][] maze; public World(int _r, int _c) { player = new Player(); rows = _r; cols = _c; maze = new Sprite[rows][cols]; } public void setPlayer(Player _p) { player = _p; player.setWidth(getCellWidth()); player.setHeight(getCellHeight()); } public int getCellWidth() { return getWidth() / getRows(); } public int getCellHeight() { return getHeight() / getCols(); } public Player getPlayer() { return player; } public int getWidth() { return width; } public int getHeight() { return height; } public Sprite[][] getMaze() { return maze; } public int getRows() { return rows; } public int getCols() { return cols; } public boolean isValidPlayerMove(int r, int c) { if (r < 0 || c < 0) return false; if (r >= getRows() || c >= getCols()) return false; if(maze[r][c] instanceof Wall) // Do not break into walls. return false; return true; } private void buildMaze() { for(int r=0; r