Battle Formula

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cbrian
Forum Commoner
Posts: 97
Joined: Sun Feb 27, 2005 12:29 pm

Battle Formula

Post by cbrian »

I'm working on a PHP text-based game, and I'm working on the battle formula. It will be something like

x = player agility/opponent agility

If x = 1.65, then Player would attack 1.65 times for every time the opponent attacks.

How could I put this into PHP?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

$your_attack = $your_agility / $opponent_agility;
Am i missing something??
cbrian
Forum Commoner
Posts: 97
Joined: Sun Feb 27, 2005 12:29 pm

Post by cbrian »

What I mean is how would I put it into PHP that for every 1 attack the opponent gets, the player would get 1.65(or whatever)?

But it would be a little random, too.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Your going to have to give us more information.

Specifically what is random?
Where is their agility coming from?
etc.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I don't really know what you want but how about.

Code: Select all

$player1_attacks = $player1_agility / $player2_agility;
$player2_attacks = $player2_agility / $player1_agility;

$possible_offset = 0.1; //10%

$player1_offset = $possible_offset * $player1_attacks;

$plus_min_array = array(1, -1);
shuffle ($plus_min_array);

$player1_this_move = ($player1_attacks + ($player1_offset * $plus_min_array[0]));
cbrian
Forum Commoner
Posts: 97
Joined: Sun Feb 27, 2005 12:29 pm

Post by cbrian »

Something like that, and it would keep going.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Well if we knew what the player agility was based upon it may help :lol:
cbrian
Forum Commoner
Posts: 97
Joined: Sun Feb 27, 2005 12:29 pm

Post by cbrian »

I get it from a database.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

cbrian wrote:I get it from a database.
So it never changes?

How much have this game have you written so far? It seems that we have answered your question but you need some more help?

I'm guessing that when a player makes an attack there is some sort of calculation to deduct points from the opponent depending upon what the attack was and various other factors?? What exactly do you need help with :?:
cbrian
Forum Commoner
Posts: 97
Joined: Sun Feb 27, 2005 12:29 pm

Post by cbrian »

I have written a lot of the game so far. It does change, by going to a Training Field and training your stats.

I have only just started on the battle engine, and I just need help on how to calculate who attacks when, and how many HP has been deducted, and that stuff.
Cronikeys
Forum Commoner
Posts: 35
Joined: Sun Jan 16, 2005 9:14 am

Post by Cronikeys »

Are the attacks whole numbers? if so then you can do it like this (change it to php yourself ;) ):


badguy attack
badguy attack + (random integer from -5 through 5 ) = meh
player hp - meh = new player hp

you attack
your attack power / enemy defense = moh
enemy hp - moh = new enemy hp

---
also, is it me or should this be in "PHP - Theory and Design" forum?
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post by Archy »

I would use a while statement, and keep looping it until one of the players dies.

To see whos player's turn it is, I would look at the current battle turn, and use a formula to see whos go it should be, and then let that person have his go. Once (s)he has had his/her go, the loop continues.

Too late, and tired to provide you with any sample code.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Archy wrote:I would use a while statement, and keep looping it until one of the players dies.

To see whos player's turn it is, I would look at the current battle turn, and use a formula to see whos go it should be, and then let that person have his go. Once (s)he has had his/her go, the loop continues.

Too late, and tired to provide you with any sample code.
I believe it is a turned based game...
and perhaps different attacks can be applied during the battle itself and whatnot..

so I don't think the whole fight should be automated.
Post Reply