Question: public static Maze loadMaze ( final String path ) throws IOException { BufferedReader reader = new BufferedReader ( new FileReader ( path ) ) ;
public static Maze loadMazefinal String path throws IOException
BufferedReader reader new BufferedReadernew FileReaderpath;
List lines new ArrayList;
Maze maze new Maze;
String line;
Map roomsMap new HashMap;
Map doorsMap new HashMap;
while line reader.readLine null
System.out.printlnline;
String words line.split;
System.out.printlnArraystoStringwords;
if wordslength
continue; Invalid line format, skip
String objectName words;
String objectId words;
if objectNameequalsroom
int roomNumber Integer.parseIntobjectId;
Room room new RoomroomNumber;
roomsMap.putroomNumber room;
maze.addRoomroom;
for int i ; i ; i
String side wordsi ;
Direction direction Direction.valuesi;
if sideequalswall
room.setSidedirection new Wall;
else if sidestartsWithd
Door will be set after door parsing
else if objectNameequalsdoor
int roomNumber Integer.parseIntwords;
int roomNumber Integer.parseIntwords;
boolean isOpen wordsequalsopen;
String isOpen words;
Room room roomsMap.getroomNumber;
Room room roomsMap.getroomNumber;
Door door new Doorroom room;
ifisOpenequalsopen
door.setOpentrue;
else
door.setOpenfalse;
doorsMap.putobjectId door;
Set the door on the correct sides of the rooms
for Direction direction : Direction.values
if roomgetSidedirection null
roomsetSidedirection door;
break;
for Direction direction : Direction.values
if roomgetSidedirection null
roomsetSidedirection door;
break;
reader.close;
Set the current room to the first room added if any
if roomsMap.isEmpty
maze.setCurrentRoomroomsMapvaluesiteratornext;
return maze;
This implementation works for small.maze below room wall d wall wall
room d wall d wall
room wall wall wall d
door d close
door d open. Fix the implementation so that it works for large.maze below room wall d wall wall
room d wall d wall
room wall wall wall d
door d close
door d open
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
