   Map for Quest game
  I am using Java to write a quest game, I want to ask how I can write the class for the Map.just like some rooms in the map, room can coonect to the corridor or room, 1 room can connect to more than 1 rooms and corridor surely can connect to more than 1 room.I really don''t know to write the class, anyone can give me some advice?thanks.. 
  I dont know a thing about java, but I do know c++ and from what I hear they are similar in syntax.So explain a little more in detail what your trying to do, and I will see if I can help;  For exmaple...i need to create a map like:======================room1| c |room3|room5|_____| o |_____|_____|room2| r |room4| _____| r |_____|_____| i |_____| d |_____| o |_____| r |_____-----room1,2,3,4 can connect to corridorroom5 connect to room3then how can I write class for such kind of map? [edited by - vincent_cloudy on February 1, 2004 3:55:39 PM] [edited by - vincent_cloudy on February 1, 2004 3:56:30 PM] [edited by - vincent_cloudy on February 1, 2004 3:57:26 PM];  well, a possible answer is to implement the map each coridor as a hash table.from any door leaving the corridor u have a list of rooms , each of them have a pointer to previous room, one to the next room and eventually another two pointers(doors) to above and below room(like in your drawn map). if one of this pointer is to antoher corridor, than it''s a pointer to another hash table and so on. that si a quick solution and i dont'' think it''s ncessarely match your needs. generally speaking, when u are trying to design a data structure u must define what data to store and which are the operations defined on that data. u must design the structure for easy acces to specific data and for batch processing(or global processing of large structures). all u have to do is to project with a thing in mind:which operations are used more often and how to speed them up, but not using very much memory. a room in your example can store center coordinate in space and some offsets for corners(or dimensions). that''s all i have to say.   Mihai ;  Thanks for your help.But e.g.room1 cannot go to room2if you were in room1you should first go out to corridorthen enter to room2.Do i need to set pointer from room1 to room2? ;  Are you trying to produce that specific map, or do you want a randomly generated map that has the characteristics of that map: discreet rooms which may or may not be connected to their neighbors or a corridor, and can potentialy look exactly like it?If you know the position and dimensions of each room, then you can simply loop through every room to find which rooms share a wall with each other.  Then, decide which ones should be connected, pick a spot along the shared wall, and slap in a door.  In this example I'm treating corridoors as long narrrow rooms.Try this:Start with an empty map: no walls, no doors, nothing.  Pick an arbitrary spot to place an arbitrayily sized rectangluar room.  Now you have a room with four walls:#######oooo##oooo##oooo#######Decide how many other rooms you would like this room to connect to.  For each connection choose one spot along the perimeter of the room.  Let's go with two (denoted by a '+'):####+##oooo##oooo+#oooo#######Now, create one room for each connection which has a wall that includes the connection (with the rooms labeled 1, 2 and 3):ooo###########ooo#oooo2oooo#####+##########oooo#oooooo##oo1o+ooo3oo##oooo#oooooo#######oooooo#ooooo#oooooo#ooooo########In this case, I'm assuming that since there is a connection on the north wall of room 1, then that same connection must be on the south wall of room 2.  Also, the rooms can share walls but not overlap.Repeat the process for rooms 2 and 3 and so on until the map is filled to your satisfaction.EDIT: Bah!  Worthless <tt> tags!Live cheap.Live Free.Get it wrong the first time.   [edited by - Oh Gee Whoa on February 2, 2004 1:40:38 PM];  Hi! How will the player interact with your game? Real-time? Turn-based? Text-based? This may change your implementation needs...   "Senri no michi mo ippo kara (A journey of a thousand miles starts with a single step...)" ;  TO: Oh Gee WhoaThanks for your help, I will try to build a simple map first rather than a complex map.to: JoriathLionfortthe interface will show the pic of the room that the player is in, then player can click button to go to another room, then the pic will change(still pic).when the enemy come(determine by a random method or in specific room), it will change into a interface for fighting, it will be a turn-based fight, like ff7.(but I still not yet decide whether I can make that system of which one''s bar is filled then he can attack first.. ;  I''d build three classes,Exit class, Room class, and Map class.Map:Has a Room Vector that stores all the rooms.It also has whatever other map info is need.Room:Has an Exit Vector for all the exits from that room.It also has any other room info. Also a corridor is just a room.ExitHas an int corrisponding to the index in the Room Vector of Map to which that exit leads. It also has a postion in the room for the exit.as well as anyother exit info. So  for instance if you have 4 rooms.that look like this. 1#    4##*#  *   # ###   #*#3#   2 ###Room 1 has exit 1 that stores 2.Room 2 has exit 1 that stores 1 and exit 2 that stores 3.Room 3 has exit 1 that stores 2 and exit 2 that stores 4.Room 4 has exit 1 that stores 3.Did that answer your question?Also with this format you can start of just building the base classes and then add more detials to them as you go along. -----------------------------------------------------Writer, Programer, Cook, I''m a Jack of all TradesCurrent Design projectChaos Factor Design Document ;  Hi again! You could create a room class to hold the information about each room and corridor in your map, including pointers to the connected estances; ie, you could define some number of possible exits from a room as pointers to your room class.Thus, for every non-NULL pointer you know there''s a room connected to the one the player''s in. As you interface is made of static pics (whose path/name you would insert in the class, too...), you just would have to show the pic for the room/corridor you''re in, look for the available exits and put some buttons/links/whatever for each one of them. When the player clicks on one of those buttons, you can follow the pointer to get the information you need to ''render'' the next room. So, you could create your map class as some kind of linked list.And same goes for the enemies: add some pointers to your enemy class within the room class. For every non-NULL pointer you know there''s an enemy in that room. If the enemy is killed, delete the pointer and set it to NULL. And (an idea), for the random encounters, if there''s no enemy in the room the player is about to enter, then call the random generator function.I guess that''s somewhat confusing (and my english is not the best around... . If you need further explanations, please don''t hesitate to ask again.Keep it up!   "Senri no michi mo ippo kara (A journey of a thousand miles starts with a single step...)" 