コード例 #1
0
  public String renderMap(Room nextRoom) {
    Room currentRoom;
    Map currentMap = nextRoom.getMap();
    String[] roomDrawing;
    Room[] roomsArray = currentMap.getRooms();
    String mapDrawing = "\n";

    for (int[] row : currentMap.getMapCoordinates()) {
      //            mapDrawing = mapDrawing + "\n";
      for (int x = 0; x < 7; x++) {
        mapDrawing = mapDrawing + "\n";
        for (int mapCoordinates : row) {
          if (mapCoordinates == -1) {
            mapDrawing = mapDrawing + Wall.empty.getWall();
          } else {
            currentRoom = roomsArray[mapCoordinates];
            if (currentRoom.getRoomDrawing() == null) {
              mapDrawing = mapDrawing + Wall.empty.getWall();
            } else {
              mapDrawing = mapDrawing + currentRoom.getRoomDrawing()[x];
            }
          }
        }
      }
    }
    return mapDrawing;
  }
コード例 #2
0
  public String playerNavigate(String direction, Player player) throws MapControlException {
    Game game = PemberleyGame.getCurrentGame();
    Room currentRoom = player.getLocation();
    Room nextRoom;
    switch (direction) {
      case "E":
      case "EAST":
        nextRoom = currentRoom.getEast();
        break;
      case "S":
      case "SOUTH":
        nextRoom = currentRoom.getSouth();
        break;
      case "N":
      case "NORTH":
        nextRoom = currentRoom.getNorth();
        break;
      case "W":
      case "WEST":
        nextRoom = currentRoom.getWest();
        break;

      default:
        return "Not sure where you are going.";
    }
    if (nextRoom == null) {
      throw new MapControlException("You can't go that direction");
    } else {
      player.setLocation(nextRoom);
      currentRoom = player.getLocation();
      String[] roomArray = currentRoom.getRoomDrawing();
      if (roomArray == null) {
        String[] roomDrawing = this.renderRoom(nextRoom);
        nextRoom.setRoomDrawing(roomDrawing);

        String mapDrawing = this.renderMap(nextRoom);
        Map currentMap = nextRoom.getMap();
        currentMap.setMapDrawing(mapDrawing);
      }

      GameControl gameControl = new GameControl();
      gameControl.updateGame();

      String playerMessage = nextRoom.getName() + "\n" + this.lookAtRoom();
      return playerMessage;
    }
  }