How to design tic tac toe in PHP ?

Started by
1 comment, last by Tom Sloper 9 years, 5 months ago

Need suggestions for PHP gaming .

Advertisement

PHP is for programming the server-side of an application and works with http requests, you need more than PHP to make a game, and the most "gaming" parts of the application will be done in that other language (JavaScript, for example).

With PHP you can store and retrieve information, with JavaScript you draw the game, handle input, all the animations, etc, etc. You could make a game just with JavaScript if you want, but not with PHP alone.

There are a lot of HTML5/JavaScript game engines and frameworks, try any of them: http://html5gameengine.com/

EDIT: For a tic tac toe multiplayer game played from different PC's (I guess you want something like that since PHP will work for the comunication only) you need to have a list of connected users, so you can start a match between 2 of them. Then, in the client side you check the state of the match requesting it to the PHP server. In the server you'll need to store the player who's turn just passed and the move he/she made, so the other player can retrieve that move and can update the board.

You can add more and more complexity, you could store the state of the board in the server instead of just the last move, and get the board on every check, to prevent cheating (javascript code can be edited pretty easily in any browser). Also, if you store the board you may also want to check for the winner in the server after each move, so players can't cheat sending a "I won" message.

EDIT2: Now that I think of it, you could be able to make a multiplayer tic tac toe game without much JavaScript, but with HTML elements, since nothing happens while waiting for the next move, but it'll take more time an effort. You can create a board with a table of buttons, and surround the table with a form. Each button submits the form with a different value so you know where the player "moved", and in PHP you setup the HTML response and reconstruct the board with disabled buttons on the already selected places.

Need suggestions for PHP gaming


Daisy, you need to provide more details with your question.

-- Tom Sloper -- sloperama.com

This topic is closed to new replies.

Advertisement