public String getShortDescription() { String str = Convert.ToString(this.getRoomNumber()) + ":"; for (int iPassage = 1; iPassage <= this.getNumPassages(); iPassage++) { str = str + " " + this.getPassage(iPassage).getRoomNumber(); } if (this.hasDoor()) { str += " ("; if (!this.isDoorLocked()) { Room door = this.fDoor; if (door.isExit()) { str += "exit"; } else { str += door.getRoomNumber(); } } str += ")"; } return(str); }
public void setVisited(Room room) { if (!room.isExit()) { bool wasVisited = sVisitedRooms[fRoom.getRoomNumber() - 1]; sVisitedRooms[fRoom.getRoomNumber() - 1] = true; if (!wasVisited) { GameEngine.instance.fMaze.setExplored(room); } } }
public static bool hasVisited(Room room) { Utility.Assert(room.getRoomNumber() <= sVisitedRooms.Length, "Player.hasVisited - room.getRoomNumber() < sVisitedRooms.length"); if (room.getRoomNumber() > sVisitedRooms.Length) { return(false); } if (room.isExit()) { return(false); } return(sVisitedRooms[room.getRoomNumber() - 1]); }
public bool isExplored(Room room) { Utility.Assert(room.getRoomNumber() <= sExploredRooms.Length, "Maze.isExplored - room.getRoomNumber() < sExploredRooms.length"); if (room.getRoomNumber() > sExploredRooms.Length) { return(false); } if (room.isExit()) { return(false); } return(sExploredRooms[room.getRoomNumber() - 1]); }
public String getAdjacentPlayerDescription() { String str = ""; for (int iPassage = 0; iPassage <= this.getNumPassages(); iPassage++) { Room room = null; if (iPassage == 0) { if (!this.hasDoor() || !this.isDoorOpen()) { continue; } room = this.fDoor; } else { room = this.getPassage(iPassage); } if (!room.isExit()) { String strPlayers = ""; Player player = GameEngine.instance.getCurrentPlayer(); for (int iPlayer = 1; iPlayer <= GameEngine.instance.fNumPlayers; iPlayer++) { Player pl = GameEngine.instance.getPlayer(iPlayer); if (pl != player && pl.isAlive() && pl.fRoom == room) { if (strPlayers != "") { strPlayers += " "; } strPlayers += pl.fName; } } if (strPlayers != "") { str += room.getRoomNumber() + ": " + strPlayers + "\n"; } } } return(str); }
public void setExplored(Room room) { if (!room.isExit()) { // bool wasExplored = sExploredRooms[room.getRoomNumber() - 1]; sExploredRooms[room.getRoomNumber() - 1] = true; // if (!wasExplored) // { // bool done = true; // for (int i = 0; i < this.getNumRooms(); i++) // { // if (!sExploredRooms[i]) // { // done = false; // break; // } // } // if (done) // { // fExplored = true; // } // } } }
public bool hasEscaped() { return(fRoom.isExit()); }
public Room[] findRoute(Room fromRoom, Room toRoom, Player player, int useDoors) { // Utility.Assert(player == null || useDoors != USE_LOCKED_DOORS, "player == null || useDoors != USE_LOCKED_DOORS"); Utility.Assert(fromRoom != null, "Maze.findRoute - fromRoom != null"); Utility.Assert(toRoom != null, "Maze.findRoute - toRoom != null"); String str = "null"; if (player != null) { str = player.fName; } Utility.Trace("Maze.findRoute: " + fromRoom.toString() + ", " + toRoom.toString() + ", " + str + ", " + useDoors); if (fromRoom == toRoom) { Utility.Trace("from equals to, return empty path"); Room[] path = new Room[0]; return(path); } int[] room_path = new int[fNumRooms + 1]; for (int i = 0; i <= fNumRooms; i++) { room_path[i] = 999; } room_path[fromRoom.getRoomNumber()] = 1000 + fromRoom.getRoomNumber(); Utility.Trace("Maze.findRoute: searching maze..."); bool done = false; while (!done) { bool exhausted = true; for (int iRoom = 0; iRoom <= fNumRooms; iRoom++) { if (room_path[iRoom] >= 1000) { room_path[iRoom] = room_path[iRoom] - 1000; if (iRoom == toRoom.getRoomNumber()) { done = true; exhausted = false; break; } Room room = this.getRoom(iRoom); // if (player == null && room.hasMuck()) // continue; for (int iPassage = 1; iPassage <= room.getNumPassages(); iPassage++) { if (room.isPassable(iPassage) || useDoors >= USE_PORTCULLIS) { Room tmpRoom = room.getPassage(iPassage); if (player == null || Player.hasExplored(room) || Player.hasExplored(tmpRoom)) { if (room_path[tmpRoom.getRoomNumber()] == 999) { room_path[tmpRoom.getRoomNumber()] = -iRoom; } } } } if (room.hasDoor()) { bool allowDoor = true; if (player != null) { if (room.isDoorLocked()) { if (useDoors < Maze.USE_LOCKED_DOORS) { allowDoor = false; } } } else { if (room.isDoorLocked()) { if (useDoors < Maze.USE_LOCKED_DOORS) { allowDoor = false; } } else if (!room.isDoorOpen()) { if (useDoors < Maze.USE_CLOSED_DOORS) { allowDoor = false; } } else { if (useDoors < Maze.USE_OPEN_DOORS) { allowDoor = false; } } } // if ((player == null && useLockedDoors) || !room.isDoorLocked()) if (allowDoor) { Room door = room.fDoor; // Utility.Assert(player == null || player.hasVisited(room) || player.hasVisited(door), "Maze.findRoute - player == null || player.hasVisited(room) || player.hasVisited(door)"); if (player == null || Player.hasExplored(room) || Player.hasExplored(door)) { if (room_path[door.getRoomNumber()] == 999 && !door.isExit()) { room_path[door.getRoomNumber()] = -iRoom; } } } } exhausted = false; } } for (int iRoom = 0; iRoom <= fNumRooms; iRoom++) { if (room_path[iRoom] <= 0) { room_path[iRoom] = 1000 - room_path[iRoom]; } } if (exhausted) { done = true; } } if (room_path[toRoom.getRoomNumber()] == 999) { Utility.Trace("Maze.findRoute: found no path, return empty path"); Room[] aRoom = new Room[0]; return(aRoom); } Utility.Trace("Maze.findRoute: found path, backtracking..."); int count = 0; int current = toRoom.getRoomNumber(); while (current != fromRoom.getRoomNumber()) { count++; current = room_path[current]; Utility.Assert(current > 0, "Maze.findRoute - current > 0"); Utility.Assert(current < 999, "Maze.findRoute - current < 999"); } Utility.Trace("Maze.findRoute: path is " + count + " rooms"); Room[] rooms = new Room[count]; current = toRoom.getRoomNumber(); for (int i = count; i > 0; i--) { rooms[i - 1] = this.getRoom(current); current = room_path[current]; } Utility.Assert(current == fromRoom.getRoomNumber(), "Maze.findRoute - current == fromRoom.getRoomNumber()"); // Remove this code! Causes a crash... // if (GameEngine.rand.range(1, 5) == 1) // { // rooms[0] = null; // rooms[1] = null; // } str = "" + rooms[0].getRoomNumber(); for (int j = 1; j < rooms.Length; j++) { str += "-" + rooms[j].getRoomNumber(); } Utility.Trace("Maze.findRoute: returning path: " + str); return(rooms); }
override public void displayMove(Room room) { fShooting = false; String str = "There are passages leading to:"; System.Console.WriteLine(str); for (int i = 1; i <= room.getNumPassages(); i++) { if (room.isPassable(i)) { Room otherRoom = room.getPassage(i); str = "(" + otherRoom.getRoomNumber() + ")"; Player player = fEngine.getCurrentPlayer(); if (Player.hasVisited(otherRoom)) { if (player.fLastRoom == otherRoom) { str = "[" + Convert.ToString(otherRoom.getRoomNumber()) + "]"; } else { str = Convert.ToString(otherRoom.getRoomNumber()); } } str = str + " "; System.Console.Write(str); } } if (room.hasDoor() && room.isDoorOpen()) { str = "Door: "; System.Console.Write(str); Room otherRoom = room.fDoor; str = "(" + otherRoom.getRoomNumber() + ")"; Player player = fEngine.getCurrentPlayer(); if (otherRoom.isExit()) { str = "exit"; } else if (Player.hasVisited(otherRoom)) { if (player.fLastRoom == otherRoom) { str = "<" + Convert.ToString(otherRoom.getRoomNumber()) + ">"; } else { str = Convert.ToString(otherRoom.getRoomNumber()); } } str = str + " "; System.Console.Write(str); } System.Console.WriteLine(); int no = 0; Room toRoom = null; while (true) { no = this.readNumber(); toRoom = fMaze.getRoom(no); if (room.hasPassage(toRoom) || room.fDoor == toRoom) { break; } else { System.Console.WriteLine("No passage leads to " + no); } } fEngine.doMove(toRoom); }