Code: Select all
$Acounter = 0;
$Bcounter = 0;
$Ccounter = 0;
...
// when a round ends
...
$Acounter++;
$Bcounter++;
$Ccounter++;
if($Acounter == 2){
// attack!
$Acounter = 0;
}
if($Bcounter == 3){
// attack!
$Bcounter = 0;
}
...
Code: Select all
$Acounter = 0;
$Bcounter = 0;
$Ccounter = 0;
...
// when a round ends
...
$Acounter++;
$Bcounter++;
$Ccounter++;
if($Acounter == 2){
// attack!
$Acounter = 0;
}
if($Bcounter == 3){
// attack!
$Bcounter = 0;
}
...
Code: Select all
<?php
//skipping any other setup you need in the page
//string for outputting results of battle:
$result = "";
//boolean flag to cut off battle when done
$done = false;
//loop for incrementing turns
for ($x = 0; !$done; $x++) {
checkPlayerTurn($x);
checkMonsterTurn($x);
checkIfBattleOver();
}
function checkPlayerTurn($x) {
for ($y = 0; y < count($partyMembers); y++) {
/*Probably needs some explaining here. I am assuming you have an object for each player stored in the
* $partyMembers array with a stat called "speed" that can be checked. The modulus operator "%" returns the
* remainder of division (remember the way you learned division in 3rd grade or so, where you didn't deal with
* decimal places?). This way you can see if the character's speed stat is completely divisible by the turn number.
* If someone's speed was 1, they would act every iteration of the loop. If 4, it would be every 4 iterations of the loop.
*/
if ($x % $partyMembers[$y]->$speed == 0) {
playerAttack($partyMembers[$y]);
}
}
}
function playerAttack($player) {
//Custom battle logic put here using $player->attack and other stats for battle.
//Prepare the HTML list items for output to the player to show results of battle
$result += "<li>" + $attackResultString + "</li>";
}
function checkIfBattleOver() {
//Custom logic to see if battle is over. If it is....
$done = true;
//....to stop the main loop.
}
function checkMonsterTurn($x) {
//basically the same as checkPlayerTurn(), but
// ...with an array of monsters the player is attacking
}
function monsterAttack($monster) {
//called by checkMonsterTurn. Basically the same as playerAttack()
}
?>
<!-- skipping head of HTML file and any other banners or anything needed in HTML. Basically just getting to the battle results list -->
<ul>
<?php echo $result; ?>
</ul>Code: Select all
$result += "<li>" + $player->name + " missed " + $player->target + "!</li>"; Code: Select all
$result += "some stuff"; Code: Select all
$result .= "some stuff"; Code: Select all
for ($x = 100; $x > 0; $x--) {
//code here
} I think you're looking at the wrong number. If you have a speed of 4, then you divide 100 by that and get 25 for you're attack increment position. The speed of 4 matters and the higher it is, the better off you are.Oroton wrote:Yes, how would you do a count down
It seems if your points were 25, you'd go on turn 100, 75, 50, and 25. But if your score was 20 you'd go on 100, 80 60 40 and 20, so again lower numbers would be better.. How would u invert that.
Code: Select all
$participantsinbattle=2;
$playerspeed[1]=4;
$playerspeed[2]=10;
for ($x = 100; $x > 0; $x--)
{
for ($check = 1; $check <= $participantsinbattle; $check++)
{
$speedtocheck=$playerspeed[$check];
if (floor($x/$speedtocheck)==$x/$speedtocheck) echo "Player ".$check." has a turn at position: ".$x."<br>";
}
}