I’m working on making a simple simulation for my website, and I’ve looked around but cannot find anything on how to accomplish this. Could someone please provide how I would achieve the following output with code:
There are two players, both level 2.
Player 1
Attack – 1
Defense – 2
Health – 10
Player 1
Attack – 2
Defense – 1
Health – 10
I want to to have a simulated turn-based battle between these two players. It would randomly choose who gets the first hit. For this we’ll say player 1 goes first.
The equation I would use to calculate the hit would be ($playerattack/$playerdefense) + rand(1,$level) (equation may work well, may not. just for testing purposes) I want to then have output like the following.
Player 1 (10 health) – hit a 2
Player 2 (8 health) – hit a 1
. . .
Player 1 (1 health) – hit a 2
Player 2 dies, Player 1 is victorious!
**Sorry to those who answered to the old example! Thanks for your feedback though
This allows only two players.
[Edited]
This allows more than two players and is turn based.