How To Develop Your Very Own PHP Game
Tutorial on making a PHP game, from scratch :)

Step 7: A Jumpstart

By justImagine
Oookay, I'm a little depressed here because there are so many things I need to talk about here and the lack of time I have. So, let's assume you've mastered several basic PHP Codes. You'll need the repetition statements (FOR, WHILE, DO-WHILE), conditional expressions (IF, IF-ELSE, IF-ELSEIF), and a basic like PRINT.

Now we're moving to MySQL database.

I kinda hope you can all understand MySQL. I must first warn you that MySQL systems are a bit different with PHP since MySQL works a a database. If you're about to make an MMORPG, you'll definitely need a database.
One good thing, is that PHP has the codes that integrates PHP codes with MySQL. Basically, when a player plays your game, the only thing he is doing is updating your database. Here's how it works:

A player registers >> When Register button is clicked, it wrote a new data entry in the database >> When account is verified, the data entered is updated into an Active Account >> Player logs in >> PHP Codes fetched the data based on the entered Username from database >> PHP Codes verified the input. If the Username and password match, then the result of the statement is TRUE. Else, it's FALSE >> Assume the result is TRUE, database updates the online-offline status of the player >> Player can start playing. Let's say the Player bought an item >> When the player verifies his buy, the Database will work on several things: 1) PHP Codes fetched the 'cash' the Player had. If it's enough to buy an item, no warning will be displayed. 2) PHP Codes calculates the remaining cash the player had. 3) The calculated remaining cash is re-written into the database. So now the database held the new cash data. 4) Data that a player bought the item is written into the database, so it won't be lost as the player lost his cash to buy it.

When a player asks for battle, here are the probable processes:
PHP Codes fetched the data available about players of the player's level >> PHP Codes displayed the results along with a link next to each shown username: Attack link. Making this can be done by using FOR or WHILE >> When the player decided to attack one other player, let's say Player2, PHP Codes fetched the attack points, defense points, and health points or anything else necessary from the Database. It calculates the fetched P2 data with the attacking P1's data. After the calculation, one will come out victorious. Let's say, P1 won. So he got the cash and Experience points. The way to add these is by fetching current cash and Exp, keeping them in one variable each, then using PHP to calculate the result of the current cash and Exp plus the gain. Then the current health minus the damage taken >> The calculations were kept in a variable each >> PHP is used to manipulate MySQL and update the current data with the results of the calculations.

If you could understand those, then you have almost enough to start learning MySQL. I'll talk about the scripts on the next post, alright?
 

0 comments so far.

Something to say?