NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page MySQL rooms for a game - intermediate directions like northeast?

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Reply
 
LinkBack Thread Tools
Old 07-01-2009, 11:16 AM THREAD STARTER               #1 (permalink)
NamePros Regular
 
omegapandor's Avatar
Join Date: May 2008
Posts: 248
omegapandor has a spectacular aura aboutomegapandor has a spectacular aura about
 



Help! MySQL rooms for a game - intermediate directions like northeast?


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 Code:

class Room{
       function 
Room($north$south$east$west){
????: NamePros.com http://www.namepros.com/programming/593662-mysql-rooms-game-intermediate-directions-like.html
       
query "INSERT INTO rooms(north, south, east, west) VALUES('$north', '$south', '$east', '$west')";
       
mysql_query(query);
????: NamePros.com http://www.namepros.com/showthread.php?t=593662
       }
}

function 
CreateRoom($direction$title){
       if(
$direction == "north")
                
$room = new Room($titlenullnullnull);
      else if(
$direction == "south")
                
$room = new Room(null$titlenullnull);
      else if(
$direction == "east")
                
$room = new Room(nullnull$titlenull);
      else if(
$direction == "west")
                
$room = new Room(nullnullnull$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.
__________________
Are you tired of viruses and popups? Use Firefox!
Last edited by omegapandor; 07-02-2009 at 02:48 PM. Reason: syntax error
omegapandor is offline   Reply With Quote
Old 07-02-2009, 01:46 PM   #2 (permalink)
NamePros Member
Join Date: Sep 2006
Posts: 99
Bruce_KD will become famous soon enoughBruce_KD will become famous soon enough
 



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
Bruce_KD is offline   Reply With Quote
Old 07-02-2009, 02:46 PM THREAD STARTER               #3 (permalink)
NamePros Regular
 
omegapandor's Avatar
Join Date: May 2008
Posts: 248
omegapandor has a spectacular aura aboutomegapandor has a spectacular aura about
 



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.
__________________
Are you tired of viruses and popups? Use Firefox!
omegapandor is offline   Reply With Quote
Reply

Tags
games, mysql, php, rooms


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Online Game Programming (I offer) Darkfire001 For Sale / Advertising Board 14 04-09-2005 12:59 PM
Dream Machine Unknown The Break Room 9 12-28-2004 04:18 PM
WordGames.us For Sale Dillpup Domains For Sale - Make Offer 2 07-07-2004 02:53 PM
Not Sure? PlayGames.us Monsterman Domain Appraisals 4 06-10-2004 01:30 PM
PotterGame.com Tassos Domain Appraisals 11 07-11-2003 11:08 AM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 04:38 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger