Dynadot

MySQL rooms for a game - Intermediate directions like northeast?

Spaceship Spaceship
Watch
Impact
4
I'm trying to conceive a game where there are rooms in a mysql database and each room has directions that point to other rooms, which enables players to traverse the rooms. My problem is not traversing the rooms, but constructing them.

If you're only using north, south, east, west, then when you create a new room, you just point one of it's directions back at wherever it came from, depending on the direction it was constructed in.

For example (in sort of php (I originally did something like this in c++))
PHP:
class Room{
       function Room($north, $south, $east, $west){
       query = "INSERT INTO rooms(north, south, east, west) VALUES('$north', '$south', '$east', '$west')";
       mysql_query(query);
       }
}

function CreateRoom($direction, $title){
       if($direction == "north")
                $room = new Room($title, null, null, null);
      else if($direction == "south")
                $room = new Room(null, $title, null, null);
      else if($direction == "east")
                $room = new Room(null, null, $title, null);
      else if($direction == "west")
                $room = new Room(null, null, null, $title);
       //or something like that 
}

Not sure if the above works, it's my current (basic) understanding of how the c++ code would work in php.

Now I have NO IDEA how to implement intermediate directions like southwest. I know it can be done. . .somehow. Games like Urban Dead use all 8 directions.

Anyone care to enlighten me?

NOTE: I obviously could just manually input all the rooms, but that would require a life's worth of aspirin.

UPDATE: Dunno why I was only thinking I would have this problem with intermediate directions. The real problem I am having is that my rooms are connected interactive-fiction style, like MUDs. I actually need the rooms to be connected more like a map, with nearby rooms automatically setting connections when I place a new room in.
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
I would probably have another table, one with the rooms and one for "connections".
Have the room id, a numeric direction 0-7 (0 for north, 1 for ne, 2 for east, etc), and the room it's connecting to. If you're really clever, you have have only 1 entry in the database (eg, room 1 --> north --> room 2 would imply room 2 --> south --> room 1), or just have both entries in there. Index by the room ids and throw in a few joins, you're good to go.


Bruce
 
0
•••
Thanks

Thanks for the reply. I'm having trouble seeing how doing it that way is very different from the way I'm doing it now, though. Also, I understand that joins are supposed to be very resource heavy?

I just realized another problem. It's actually the same problem but I wasn't thinking that it would affect me without intermediate directions for some reason.

The rooms are connected in text-adventure-game style. Unfortunately, they need to be connected more like a map. That is, when I add rooms, nearby rooms need to automatically connect to them with the proper directions. THAT is the real problem.
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back