How to design an attack section

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
carcaix
Forum Newbie
Posts: 12
Joined: Sun Aug 29, 2010 9:33 am

How to design an attack section

Post by carcaix »

Hi all,

I have just registered in this forum 5 minutes ago. I am 18 years old spanish bloke who has started with php 3 years ago. My English isn't enought good but I think that I could make me understand. (A bit introduction to know my situation).

Ok, so I have started to programme a "php game" you know like ogame and travian but in a small size, and well I have got this clue at least 2 years ago when I started to play that sort of games. Then I got bored and I left the games and I strated to get interest in how to do these things. Now that I will start the second year of computer engineer i have understood lots of things in php. Going to the point is that the game works as I was expected but I don't know how to design and then programme one of the mainly sections of the game, the attack ones. The description is that the user who attack select the number of units to send and then also the username who will be attacked, all of these in a form which validates all the things. I was wondering if someone have an idea to make a war between the 2 users and then generate probably a text file reporting the 2 users how the battle was it like.

If more information is needed only reply it.

I think this is the correct place to post it.

Thanks a lot.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: How to design an attack section

Post by Jonah Bron »

I don't know about the type of game you're talking about. The best thing I can suggest is to start trying something and asking us if you hit a problem.
User avatar
MindOverBody
Forum Commoner
Posts: 96
Joined: Fri Aug 06, 2010 9:01 pm
Location: Osijek, Croatia

Re: How to design an attack section

Post by MindOverBody »

Hy there! I played Ogame for a while, so i can understand your problem. Few weaks ago, i was brainstorming about this same problem and its implementation with my future MMORPG project. Simplest solution for this is to make "skirmish" class which will handle array of participating users, predefined battle formulas and at grand finale, return result object. Here is some basic scheme:

Image

If you are doing "ogame flight time" way, you'll need some all-time active javascript which will from time to time refresh future attack events array, and at key time run early mentioned "skirmish" class.

Otherwise, do skirmish class at "attack" click.

Let me know about progress! :D
Bojan
carcaix
Forum Newbie
Posts: 12
Joined: Sun Aug 29, 2010 9:33 am

Re: How to design an attack section

Post by carcaix »

Thanks for your 2 reply.

MindOverBody I share more a less your idea of scheme. In the skirmish object I know how to get the attack units and the defender's one but probably I it was my fault to specify that I was asking for how to think with a battle formula. I have thought two ideas. The attack will be instantaneous so no javascript or countdown is needed.

1... It's very simple. To bring each kind of unit from the attacker into conflict with the defender and if there are 5 vs. 2 the result is 3 survivals from the attacker, but it has lots of cons and the most important is that if there are different type of units it doesn't work.

2... During these few last days I have been thinking to assign some life and attack to each unit and then depending with the amount of units that they send multiply the life and leave the same attack. But almost I have the same trouble again, how to do the algorithm for the battle (the order, and keep the attack report writing).


As I said the game is a bit sample but it has a section of producers, army, researches.. and the attack one which is my last section to finish it.

I have been searching in Internet but I haven't found anything so if you know where I could find some insiration I would be so grateful.
User avatar
MindOverBody
Forum Commoner
Posts: 96
Joined: Fri Aug 06, 2010 9:01 pm
Location: Osijek, Croatia

Re: How to design an attack section

Post by MindOverBody »

carcaix wrote:1... It's very simple. To bring each kind of unit from the attacker into conflict with the defender and if there are 5 vs. 2 the result is 3 survivals from the attacker, but it has lots of cons and the most important is that if there are different type of units it doesn't work.
I think the best approach is to think of users attacking army as sum of it's individual power. Diferent types of units should have different attack levels, experience, advantages, etc. So, make a sum of all unit fire powers to get total horde attack power, do same with defender, then clash those two together. The most important thing with this approach is to arrange attack points fairly. For example, one tank should have attack points as twenty soldiers or so. Take a lot of time to do this right becouse this is crucial.
carcaix wrote:2... During these few last days I have been thinking to assign some life and attack to each unit and then depending with the amount of units that they send multiply the life and leave the same attack. But almost I have the same trouble again, how to do the algorithm for the battle (the order, and keep the attack report writing).
Do the battle through few rounds. Number of rounds should be based on ratio of attacker units and defender units. For each round of fight, apply formula.

Hm, formula... thats the most important part of this "skirmish" object. It must be strong, bugless and fair. Let's say that you need in every round apply same formula for defender and attacker, to get his loses in round, and the loser is one who loose all of his units. To make formula, you'll need to include ratio of army fire power to get percentage, and based on that percentage reduce number of army units on weaker side on every round. You can also add some luck factor in this with randomisation functions to get +/- casulties for every fight to look more "natural". Making this kind of formula is very difficult becouse it can not be done i first try. It need to be tested, and adjusted many times, to get quality results.

To make result just make array of result objects, and in final stage, show that objects. Lets say that like in ogame, every round of battle make table of current status. At end of round, call methow which will make table of current unit status, and push it into result array, so on the end of fight you should have array of round result objects, and just bind them. It should'nt be hard.
carcaix
Forum Newbie
Posts: 12
Joined: Sun Aug 29, 2010 9:33 am

Re: How to design an attack section

Post by carcaix »

Thanks for your reply, I have read the same day you post it.

Eventually I get more a less inspired and now my fundamental issue is looking for a round condition, therefore, when the round should be finished. Well my formula it's not enought hard and strong but it may work. I have thought using attack and defense of each unit to make a whole and then decide who attack first. Then when someone is attacking randomly i get acces to the array of who is being attacked and if the unit has less defense than the whole attack of the attacker it's being delete (and I also take away these units of defense of who has dead to the whole attack, but i'm not sure doing that), then i should stop the round attack in too many different conditions if the defensor has no units if the attack leaves with less atack than the weakeness unit defense but if none of this conditions come true I dont know how to stop the round, when the attacker has killed 40% of defense units, when the attacker makes a precentatge of hits linked with his whole attack.

Well, I think this post could be understable, please reply some ideas if any.
User avatar
MindOverBody
Forum Commoner
Posts: 96
Joined: Fri Aug 06, 2010 9:01 pm
Location: Osijek, Croatia

Re: How to design an attack section

Post by MindOverBody »

This part can be complex and tricky. It can be solved either with predefined number of rounds so every round shoud end when percentage reach some predefined value of killed at any side (this case makes possible for battle to end with draw), or even with "Take no prisioner" policy, so every round is one hit (formula application), which is resulting with confronted sides fighting until "last man standing".
Post Reply