jabbaonthedais Posted November 14, 2007 Share Posted November 14, 2007 I've been racking my brain how to do this for days, but I'm stumped. A friend of mine is working on a game engine for a mud. I made a web-based admin to create rooms for areas. What I don't know how to do is map the rooms in php. My table looks like this: room_id | direction | destination_id The possible directions are north, south, east, west, northwest, northeast, southwest, and southeast. The destination_id is the id of the room that direction points to. I need to be able to map out general location of rooms based on the directions you take to get to them, but starting at any 1 room. Like if I clicked the middle room to edit, its going to create the map using only the list of destinations from the table above and the room id of the room I clicked. Here's an example of what I would like to do: XX X X X XX XX X X X X I am going to convert this to a nice table with some graphics, but if I can get it to do the text I can easily swap it for graphics. I've been trying to use foreach and while functions, but I can't get passed the first room. Sorry I know this isn't something important, but I know learning how to do it will better my php skills, so any advice you can give would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
jabbaonthedais Posted November 14, 2007 Author Share Posted November 14, 2007 Sorry if this post wasn't very clear. But here is more about the way I am trying to do this. I am pulling all the rows in my room_directions table into arrays. I am using an x and y axis (to determine how to position the rooms). I start at the selected room and it is at 1,1. So if it has a room to the west, I subtract 1 from its axis and store that number to that room. Then, when I'm showing the rooms, I find the lowest number of each axis and thats my start position. If that makes sense. My only problem is how do I get it to run through each room's destinations until it has mapped all the rooms using just the room_directions table? I can do the rest if I can just figure out how to do that. Quote Link to comment Share on other sites More sharing options...
Barand Posted November 15, 2007 Share Posted November 15, 2007 Give each room grid coordinates [pre] 11 012345678901 0 AB 1 C D E 2 FG HI 3 J 4 K L 5 M [/pre] So D is at (7,1) If you move South from there, is there a room with coords = (7,2) or (7,3) ... etc. If so, that's the destination in that direction. Quote Link to comment Share on other sites More sharing options...
jabbaonthedais Posted November 15, 2007 Author Share Posted November 15, 2007 Yeah, that's what I'm trying to do. My only problem is how to get my script to follow the directions to know the positions of the rooms. Here is the code I'm working on but its not working. $resulta = mysql_query("SELECT room_id, direction, destination_id FROM room_directions"); while($r=mysql_fetch_array($resulta)) { $roomdirec[$r[room_id]][$r[destination_id]]=$r["direction"]; } function check_rooms($roomid){ foreach($roomdirec[$roomid] as $tempid => $direction){ echo "id: $tempid, direction: $direction <br />"; check_rooms($tempid); } } check_rooms(5); // 5 being the room I have selected so I must start from If I can just get it to run through every direction of every room listed I could give each one a x and y coordinate, but I'm not sure how to do it. Thanks for the reply! Quote Link to comment Share on other sites More sharing options...
Barand Posted November 15, 2007 Share Posted November 15, 2007 </pre> [pre] 11 012345678901 0 A B 1 C D E 2 FG HI 3 J 4 K L 5 M [/pre] Your table would only need [pre] room | X | Y | -------+-------+-------+ A | 3 | 0 | B | 6 | 0 | C | 2 | 1 | D | 7 | 1 | E | 9 | 1 | [/pre] Given the room and direction you can then find the destination Quote Link to comment Share on other sites More sharing options...
jabbaonthedais Posted November 15, 2007 Author Share Posted November 15, 2007 Thanks Barand. I was trying to keep the database structured like it would appear in the game, but it would be easy to modify it just for the admin. I see I was making it more complicated than it really was. Thanks again. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.