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