Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

i'm trying to develop a simple multiplayer turn base game, i'm start creating the grid map, i have already write the javascript script to display the range movement for the specific unit, but my problem is how to check if the grid position sent to server by the client is a valid position, i think this is a operation to do on server side (i use php) because javascript is easy editable by the user, my first throught is to save in a database each tile and its data (example: is a water tile, a forest tile...), so when the position is send to server i can read the db and check if the position is valid, but i think this method is very slow and require a lot of server resources, so there is a better way to do this? (i don't know if this is the correct site or is a question for StackOverflow)

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Your idea is not a bad solution in this case. Because your game is turn based, the amount of time it takes to do a database search shouldn't be noticeable. Because you are checking in a PHP script, which I assume is not constantly running, you can't keep the map data in memory at all times so storing it on the file system is the other solution (unless you want to use a in-memory database like Redis). If you want to ensure that the database lookup is quick...make sure the primary key is the index of the tile. To calculate the index of the tile, use the formula: x + (y*mapWidth) where mapWidth is the number of tiles in each row and x/y is the position of the tile in the grid. If you don't want to store the tile data per-row (I would recommend against storing each tile in a table row) you can store map data in a text blob as a comma-separated list of all the tiles, then convert that to an array and search by the index.

share|improve this answer
    
thanks for the fast reply, i'm using php socket on server side so the script is always running to send message to clients, and there will be multiple map active in the same moment so i think i will try the text blob solution –  user3544440 May 14 at 17:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.