• Advertisement

Archived

This topic is now archived and is closed to further replies.

Creating object from reading files

This topic is 5063 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am now hard-code my map like this.... Room room1 = new Room(name, description); Room room2 = new Room(name, description); . . . Door dr1 = new Door(room1, room2); . . . map.addRoom(room1); . . . But how can I do it from loading a file to create all these thing?

Share this post


Link to post
Share on other sites
Advertisement
Awww, f***!

I pressed back by accident and it erased my entire message.

Basically I said use XML and TinyXml (find them using Google), and gave an example... but it''s all gone now. Stupid Internet Explorer! :mad: :@

---
shurcooL`

Share this post


Link to post
Share on other sites
ACTUALLY now I use..

Hashtable gameMap = new Hashtable();

SiteFactory siteFactory = new SiteFactory();
File file = new File(fileName);
FileInputStream fis = new FileInputStream(file);

byte[] temp = new byte[(int)file.length()];
fis.read(temp);
fis.close();

String data = new String(temp);
String[] entries = data.split("\r\n");

for(int i=0; i
String[] info = entries.split("\t");

if(info[0]!="#"){

switch ((char)info[0]){

case ''R'':
case ''r'':

Room room = siteFactory.makeRoom(info[2], info[3]);
gameMap.put(info[1],room);

case ''D'':
case ''d'':

Room room1 = ((Room)gameMap.get(info[2]));
Room room2 = ((Room)gameMap.get(info[3]));
Door door = siteFactory.makeDoor(room1,room2);
room1.addDoor(door);
room2.addDoor(door);

}
}

}

return gameMap;

but there is a problem of using Switch, I dunno the problem...

Share this post


Link to post
Share on other sites
Your switch problem is probably caused by not using a break statement between cases. The syntax should be:

switch ( test )
{
case A:
case B:
break;

case C:
break;
}

Share this post


Link to post
Share on other sites

  • Advertisement