TechSpott - Computer and technology forums

Go Back   TechSpott - Computer and technology forums > Webmasters > Programming > PHP
PHP The most widely used server-side programming language for web applications.

Reply
 
Thread Tools Display Modes
Old April 4th, 2010, 03:22 AM   #1 (permalink)
forsakenlegacy
Guest
 
Posts: n/a
Default Question about php + mysql. What is a better approach?

Well, I'm planning to make a browser based game which would run using php + mysql.
The concept is obsolete in the question so I'll spare you the details.
The game I want to make will have a map, of 50 x 50 blocks.
原帖地址: TechSpott - Computer and technology forums http://www.techspott.com//showthread.php?p=3818
That is a total of 2500 blocks. Players can navigate through the map, etc, etc.

I want to ask, how do I implement the map? do I make 2500 entries into my database? do I use OOP? (or after i've made 2500 entries, how do I arrange them into a square?)

I'm really excited about this and any suggestions would be nice
Edit: I'm going to use css. My brother does designing and will do the graphics and lay-out of the website
@ the array reply

I thought of that. But without a database it would merely impossible to keep track of what block each player was on. Let on the other stuff I thought about. I just wanted to know how to implement it in SQL
  Reply With Quote Share with Facebook
Old April 4th, 2010, 03:26 AM   #2 (permalink)
Angie
TechSpott Newbie
 
Join Date: Apr 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Angie is an unknown quantity at this point
Default

are you using tables or css div?

I would use css div's then flot them left.

querythe database and echo out all the div's have a containing div_wrapper which holds 50 entries per row.

HTH
Angie is offline   Reply With Quote Share with Facebook
Old April 4th, 2010, 03:27 AM   #3 (permalink)
lansingstudent09101
TechSpott Newbie
 
Join Date: Apr 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
lansingstudent09101 is an unknown quantity at this point
Default

Communication with a database is slow (relative to accessing data in memory), consider putting the map into a php file that you can require_once to bring it in. If you're not going to ever have the user write the map itself, this will speed up the game significantly.

User's positions can be stored in the database (or in the session and read back to the db on save).

Think of DB access as a necessary evil. It's like driving to the store to get food. You can do it, but you don't want to do it when you're starving. You always prefer to go to the kitchen and grab something. Memory is your kitchen, the db is the store.
原帖地址: TechSpott - Computer and technology forums http://www.techspott.com//showthread.php?p=3935

Without a database, it may be difficult if you want to know where every player is. The MAP however doesn't need to be in the database, simply a player table and that can be as simple as

PlayerID PlayerName X Y
lansingstudent09101 is offline   Reply With Quote Share with Facebook
Old April 4th, 2010, 03:27 AM   #4 (permalink)
Nigel
Guest
 
Posts: n/a
Default

Your probably best starting off with a table with simply x and y as it's primary key. It's probably best to hold just the information relevant to that square in this table and it's worth creating a PHP class to manage access to it ( just keeps things tidy IMHO ).
Then you can have a table ( or probably a set of tables ) which relate to each player. A player table can hold their basic information, other tables can be used if you need to store multiple items ( perhaps a history of moves if you wanted ). Again if you created a PHP class - then you can keep access simple - and change your mind when you work out a better way of solving the problems.
As pointed out - memory is faster to sun things, so if this was an issue then it could be worth reading in details to memory variables. But always write any changes back to the database, saves anything being lost if anything goes wrong with the server.
  Reply With Quote Share with Facebook
Old April 4th, 2010, 03:30 AM   #5 (permalink)
Ratchetr
TechSpott Newbie
 
Join Date: Apr 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Ratchetr is an unknown quantity at this point
Default

If you have 2500 blocks in your database, put an index column in the table. Start the indexes at 0. So you will have blocks from 0...2499.

From an index, you can compute the row and column of a given block:
row = index / 50
col = index % 50

From a row and col, you can compute the index:
index = row*50 + col

You can move N, S, E or W with simple math:
N - index = index - 50
S - index = index + 50
E - index = index + 1
W - index = index -1

Of course, you have to test first to make sure you aren't falling off an edge.
Ratchetr is offline   Reply With Quote Share with Facebook
Reply

Bookmarks

Tags
approach, mysql, php, question


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting PHP MySQL table by links? christopher wood MySQL 1 April 4th, 2010 02:59 AM
Multiple PHP Scripts in 1 MySQL Database? Robert M PHP 0 April 4th, 2010 02:56 AM
PHP mySQL multiple choice quiz? sometimes_rowan PHP 0 April 4th, 2010 02:51 AM
where can i get video tutorial for php - mysql web site development for free? sole MySQL 0 April 4th, 2010 02:49 AM
What is the easiest way to practise using PHP and mySQL? bob1704 MySQL 0 April 2nd, 2010 01:55 AM

 
Forum Stats
Members: 14,356
Threads: 20,363
Posts: 27,793
Total Online: 38

Newest Member: Drarsedak

Latest Threads

Advertisements

Support our advertisers!

Amazon
Sears
Macys
1800flowers.com
Drugstore.com


Carbonite Online-Backups
Tiger Direct
Tech Depot
Buy.com
Office Depot
Fatcow
HostGator


TripsNow.us
Marriott
Expedia
CheapTickets.com
OneTravel
Hotwire

Are you a Fan?

Share this on Facebook

Tag Cloud

Partner Links


Contact Us - Home - Archive - Privacy Statement - Top - Copyright © 2009-2010, TechSpott - All times are GMT -4. Time is 02:28 PM

Powered by vBulletin® Copyright © Jelsoft Enterprises Ltd. :: SEO by vBSEO