📄 mazeengine.java
字号:
package mazeImplementation;// -----------------------------------------------// Programming 2 -- Semester 2, 2007// Maze Engine implementation// Peter Tilmanis, 3 September 2007// -----------------------------------------------// Maze engine class// -----------------------------------------------import java.util.*;public class MazeEngine implements Buildable, Traversable{ private Player player; private MazeSpace maze; private int initialHealth; public MazeEngine(MazeRef size) { this(size, "Unknown", 50); } public MazeEngine(MazeRef size, String name, int initialHealth) { this.initialHealth = initialHealth; player = new Player(name, initialHealth); maze = new MazeSpace(size); } public MazeRef getMazeSize() { return maze.getMazeSize(); } public Room getRoom(MazeRef loc) { return maze.getRoom(loc); } public Room[] getAllRooms() { return maze.getAllRooms(); } public boolean setStartPoint(MazeRef loc) { return maze.setStartPoint(loc); } public boolean setFinishPoint(MazeRef loc) { return maze.setFinishPoint(loc); } public boolean createRoom(MazeRef loc, String name) { if (!maze.isValidReference(loc)) return false; Room temp = new Room(loc, name); return maze.addRoom(temp); } public boolean addItem(MazeRef loc, String name, int health) { if (!maze.roomExists(loc)) return false; Item temp = new Item(name, health); maze.getRoom(loc).addItem(temp); return true; } public boolean removeItem(MazeRef loc, String name) { if (!maze.roomExists(loc)) return false; return maze.getRoom(loc).removeItem(name); } public boolean addExitPoint(MazeRef loc, String name, MazeRef destination) { if (!maze.roomExists(loc) || !maze.roomExists(destination)) return false; ExitPoint temp = new ExitPoint(name, destination); maze.getRoom(loc).addExit(temp); return true; } public boolean removeExitPoint(MazeRef loc, String name) { if (!maze.roomExists(loc)) return false; return maze.getRoom(loc).removeExit(name); } public boolean reset() { // check start and end points if (!maze.roomExists(maze.getStartPoint())) return false; if (!maze.roomExists(maze.getFinishPoint())) return false; // reset player String playerName = player.getName(); player = new Player(playerName, initialHealth); player.setLocation(maze.getStartPoint()); return true; } public Player getPlayer() { return player; } public boolean move (String exitPointName) throws GameException { // get exit point ExitPoint ep = maze.getRoom(player.getLocation()).getExit(exitPointName); // move to new room if (ep == null) return false; else player.setLocation(ep.getDestination()); // apply health, die if necessary Item[] items = maze.getRoom(player.getLocation()).getItemList(); for (int i = 0; i < items.length; i++) { player.applyHealth(items[i].getHealth()); } // check for finish point if (player.getLocation().equals(maze.getFinishPoint())) throw new SolvedException(); return true; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -