# [web] PHP War Game - need ideas for attack code

This topic is 5209 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Currently I'm working on an open-source web game, which uses php and mysql as its base. It's a war game, with 8 different units you can have. However, I'm having trouble thinking of a rather flexible attack system. I've gone through 3 different attack systems; none of them seem to work. The current version of attack I've implemented has unit1 of playerA attack unit5 of playerB, unit2 of playerA attack unit4 of playerB, and so on so forth (see, i want it to be flexible in relation to who each unit attacks, since I want this to be more of a moddable engine). In the end, any leftover "firepower" will determine how much land is gained in the end. However, this barely seems real... So the point is, I need some sort of schematic that is both real, AND flexible to include different types of units. below is a copy of my config.php, which is where admins set the basic configurations for units:
=============================================================

\$units = array(
"1" => array(
"name" => "soldier",
"dbname" => "unit1",
"prate" => 10,
"group" => 1,
"attack" => 5,
"defense" => 25,
"target" => 2,
"price" => 25,
"food" => 1,
"iron" => 2,
"silicon" => 0),

"2" => array(
"name" => "sniper",
"dbname" => "unit2",
"prate" => 10,
"group" => 1,
"attack" => 15,
"defense" => 50,
"target" => 1,
"price" => 50,
"food" => 1,
"iron" => 5,
"silicon" => 5 ),

"3" => array(
"name" => "tank",
"dbname" => "unit3",
"prate" => 3,
"group" => 2,
"attack" => 50,
"defense" => 50,
"target" => 4,
"price" => 200,
"food" => 0,
"iron" => 20,
"silicon" => 20 ),

"4" => array(
"name" => "missile-launcher",
"dbname" => "unit4",
"prate" => 2,
"group" => 2,
"attack" => 75,
"defense" => 75,
"target" => 5,
"price" => 300,
"food" => 0,
"iron" => 50,
"silicon" => 50 ),

"5" => array(
"name" => "fighter-jet",
"dbname" => "unit5",
"prate" => 1,
"group" => 3,
"attack" => 25,
"defense" => 75,
"target" => 6,
"price" => 250,
"food" => 0,
"iron" => 25,
"silicon" => 25 ),

"6" => array(
"name" => "bomber",
"dbname" => "unit6",
"prate" => 1,
"group" => 3,
"attack" => 90,
"defense" => 50,
"target" => 4,
"price" => 500,
"food" => 0,
"iron" => 50,
"silicon" => 50 ),

"7" => array(
"name" => "cruiser",
"dbname" => "unit7",
"prate" => 2,
"group" => 4,
"attack" => 50,
"defense" => 90,
"target" => 8,
"price" => 400,
"food" => 50,
"iron" => 100,
"silicon" => 50 ),

"8" => array(
"name" => "submarine",
"dbname" => "unit8",
"prate" => 1,
"group" => 4,
"attack" => 75,
"defense" => 100,
"target" => 7,
"price" => 500,
"food" => 75,
"iron" => 100,
"silicon" => 100 ),
);

=========================================================


as you can see, it's supposed to be truly moddable. In other words, I need a system that will seem real despite any minor changes to the stats. Many thanks!
evolutional - Please use source tags when posting code! [Edited by - evolutional on September 12, 2004 3:19:41 PM]

##### Share on other sites
Give us a little more info. For example, how many men can you send to battle at once? Can you assign specific units to specific enemy units? How does the battle play out? How do you know which units the other guy has?

I think a simple rock-paper-scissors type of scheme would work well though.

Infantry > Mechanics (mortal men, etc)
Mechanics > Tanks
Tanks > Infantry

Thank kind of thing. But you could have many more...like airplanes, etc.

##### Share on other sites
Wouldn't this be more appropriate in the "general programming" forum?

##### Share on other sites
Quote:
 Original post by visageGive us a little more info. For example, how many men can you send to battle at once? Can you assign specific units to specific enemy units? How does the battle play out? How do you know which units the other guy has?I think a simple rock-paper-scissors type of scheme would work well though. Infantry > Mechanics (mortal men, etc)Mechanics > TanksTanks > InfantryThank kind of thing. But you could have many more...like airplanes, etc.

As to knowing your opponent's stats, you can only find out how many units in total he has (ie combined units), not of each individual unit. The admin presets what each unit attacks, but the players cannot specify what to send to what.

I think I see what you're getting at with rock-paper-scissors...however, I was thinking more like having a weakness/resistence point value (preset in config) that each unit has with each other unit...

sorry evolutional! htanks for the edit

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
A4L
13
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633767
• Total Posts
3013738
×