Jump to content

Making a text map with php


jabbaonthedais

Recommended Posts

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. :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

</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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.