Great development languages: PHP, MySQL, Javascript/Ajax For killer apps.
In case you're wondering how the new risk-like wargame works, I will explain some of the ways I designed it. if you haven't seen the game, it can be found here. This isn't to say that my design is the way it has to be done, or even that it's the best way. This is just the way that I decided to do it. One thing to keep in mind is that I wrote it quickly without much forethought and I did it while simultaneously working on multiple professional projects.
First, lets start with some simple MySQL. The game uses five tables, one of which is the User Accounts table from the HackWorks site. For security reasons, I won't go into detail on that table.
The other tables store data for Armies, Regions, and Games. The last table is a Game Index table that ties together User Id, Player Id, Game Id.
Let's look at the Armies table:
CREATE TABLE `armies` ( `a_id` int(11) NOT NULL AUTO_INCREMENT, `a_owner` int(11) NOT NULL, `a_r_id` int(11) NOT NULL, `a_infantry` int(11) NOT NULL, `a_armor` int(11) NOT NULL, `a_air` int(11) NOT NULL, PRIMARY KEY (`a_id`), KEY `a_owner_id` (`a_owner`,`a_r_id`) ) ENGINE=MyISAM;
As I've said, this is a simple game, so armies are comprised of three units: infantry, armor, and air. Each unit has static strength that is hard-coded into the game. This can be easily changed by storing strengths in the database so they can be modified. In the table, "a_owner" refers to the Player Id and "a_r_id" is the Region Id from the Regions table.
The Armies table is initially populated at the start of the game with all starting army data from an Army text file.
Let's look at the Regions table:
CREATE TABLE IF NOT EXISTS `regions` ( `r_id` int(11) NOT NULL AUTO_INCREMENT, `r_game_id` int(11) NOT NULL, `r_region_id` int(11) NOT NULL, `r_owner_id` int(11) NOT NULL, PRIMARY KEY (`r_id`) ) ENGINE=MyISAM;
The regions table is populated at the start of a new game with data from a "map" text file. This table keeps track of which regions each player controls at any given time in the game. Since this game does not require you to maintain armies in every region you control, we have to keep track without the help of the Armies table. To help the players, we display a country flag in all unoccupied regions. Whenever an army moves into an enemy region, we have to update the army's location (a_r_id) in the Army table, and the region owner in the Regions table.
Next time we will discuss the Games table and the Game Index table, and how they track multiple ongoing games. Maybe we can even get into some PHP code samples then.
Comments