Decided To Stay With PHP Battle, but?
Posted: Wed Nov 12, 2014 8:01 am
Okay, I have decided to just stay with php battle, as JS is just getting too much for me. My next goal is looping the battle until it's done... here is the code:
Now I know I need to add a variable like $battlestart = 0; and then do a maxloop, but not sure where to place this. I've tried for awhile now, doing many trials, but getting nowhere, so I came to you good folks Any idears? I think one issue is that when you click the attack button? The attack button is in a JS popup, so I think the server is trying to run the code before I even am able to click attack.
Code: Select all
<?php
$outputList = '';
$outputList1 = '';
$outputList2 = '';
$outputList3 = '';
$outputList4 = '';
$outputList5 = '';
$sql = "SELECT * FROM npc_characters WHERE userid = '$_SESSION[userid]' AND defeated = '0'";
$user_query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($user_query);
$row = mysqli_fetch_array($user_query, MYSQLI_ASSOC);
$arena_id = $row['userid'];
$arena_char_name = $row['charname'];
$character = $row['charid'];
$arena_char_hp = $row['hpoints'];
$arena_char_maxhp = $row['maxhpoints'];
$sql = "SELECT * FROM characters where id ='$character'";
$user_query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($user_query);
while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {
$playerHp = $user_health;
$enemyHp = $arena_char_hp;
$playermaxhp = $user_maxhp;
$enemymaxhp = $arena_char_maxhp;
$playername = $user_username;
$enemyname = $arena_char_name;
//Player's Attack Turn
?>
<?php
$player_accuracy = mt_rand($user_accuracy, 100);
$player_atkdam = mt_rand(0,$user_strength);
$player_critical = mt_rand(0,$user_strength)*2;
if($player_accuracy > 80 && $player_critical>=$user_strength){
$outputList .= 'Your critical attack hits and ' . $arena_char_name . ' suffers ' . $player_critical . ' health <br />';
}elseif($player_accuracy < 80 || $player_accuracy > 80) {
$outputList .= 'Your attack hits and ' . $arena_char_name . ' suffers ' . $player_atkdam . ' health <br />';
}else{
$outputList .= 'Your attacked missed! You really suck ! <br />';
}
}
?>
<?php
///////////////NPC Attack Turn//////////////////////
$sql = "SELECT * FROM characters where id ='$character' LIMIT $character";
$user_query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($user_query);
$row = mysqli_fetch_array($user_query, MYSQLI_ASSOC);
$enemy_accuracy = mt_rand($characters_accuracy, 100);
$enemy_atkdam = mt_rand(0,$row['attack']);
$enemy_critical = mt_rand(0,$row['attack'])*2;
if($enemy_accuracy > 80 && $enemy_critical>=$row['attack']){
$outputList .= 'The enemies critical attack hit you. You suffer ' . $enemy_critical . ' health <br />';
}elseif($enemy_accuracy < 80 || $enemy_accuracy > 80) {
$outputList .= 'The enemy hits and you suffer ' . $enemy_atkdam . ' health <br />';
}else{
$outputList .= 'Your enemy missed. They really suck ! <br />';
}
?>
Code: Select all
<div style="visibility: hidden; height: 2em; background-color:#A78D84; font-size: 20px; color: black; vertical-align:middle" align="center" id="lose_bullets">
<?php echo $outputList; ?>
</div>
Now I know I need to add a variable like $battlestart = 0; and then do a maxloop, but not sure where to place this. I've tried for awhile now, doing many trials, but getting nowhere, so I came to you good folks Any idears? I think one issue is that when you click the attack button? The attack button is in a JS popup, so I think the server is trying to run the code before I even am able to click attack.