Thursday, September 13, 2007

Starting Basic Strategy game

I have chosen to pick Action/Strategy as genre for our next game.
So basic ideas:

  • player has money (he gains it every hour - from his registration time)
  • he can train units (1 different type), and this unit can be equipped with weapon (1 out of 3)
  • he can build defensive or economical structures (to get more defense or gain more money)
  • he can attack others and steal their money
How to start?
We need database with 1 table. Structure will be like this:
ID / username / password (protect it, if nothing else then md5) / email
also we must add other things, so it would look like that:
ID / username / password / email / lastupdate / money / units / weapon1 / weapon2 / weapon3 / wall / bank

Do not forget to optimize table and set money, units, weapon1-3, wall, bank to 0 as default!
Lets say this table is called 'users' so we connect to it using config.php and selecting user that is logged in (SELECT * FROM users WHERE password='$password' AND username='$username'). We use php function to fetch this row:
$user = mysql_fetch_array($selection);
to use any thing from our logged user we can use $user[X], where X is thing we like to use. For example if we want to see how much money does logged user has, we use:
echo "Logged user has: ".$user[money]." money".
Also you must create login and registration system* (in registration when adding new user do not forget to add $time_now ($time_now = time();) variable to lastupdate column!

So lets create main page (main.php), where we will show user information:
<?
echo "Username: $user[username]<br>
E-mail: $user[email]<br>
Money: $user[money]<br>
Units: $user[units]<br>
Number of Weapon 1: $user[weapon1]<br>
Number of Weapon 2: $user[weapon2]<br>
Number of Weapon 3: $user[weapon3]<br>
Wall level: $user[wall]<br>
Bank level: $user[level]<br>";
?>

This is all we need to start our basic game.
In next post I will explain how to make that money updates automatically every hour.

*You can find tutorials on login/register system on several tutorial sites.

5 comments:

xions said...

kool, this looks really gd mate

Elite said...
This comment has been removed by the author.
Elite said...

Hey dude, would you be able to give me the table structure like what the types of each row is... unique/index identifiers etc.

Jake said...

could you give me the database tables please

Vaidotas said...

I think he means something like that:

CREATE TABLE `users` (
id INT(10) auto_increment PRIMARY KEY,
username VARCHAR(30) NOT NULL,
password CHAR(40) NOT NULL,
email VARCHAR(255) NOT NULL,
lastupdate TIMESTAMP NOT NULL,
money INT default 0,
units INT default 0,
weapon1 INT default 0,
weapon2 INT default 0,
weapon3 INT default 0,
wall INT default 0,
bank INT default 0
);

Good luck ;)