gcusson Posted January 9, 2009 Share Posted January 9, 2009 hey guys im sure this is going to seem super easy for you but i am new at this and i am really struggling. Basically i am trying to make a simple game where the player clicks a radio button and presses submit and then it deducts points from the computer. Then the computer goes and it goes on like that until someone reaches 0. Right now however i am having 2 problems. #1- When i choose an attack and i press submit it doesnt update the score, it will take it down the right amount of points but then once i attack again it doesnt update it from that score it just changes to the total number minus the attack points. I hope that makes sense but basically what i am trying to say is that the points dont update. #2- the computer never attacks me. I dont know how to trigger it so it knows to attack me i guess i will copy and paste the coding, sorry if it is a little long <body> <?php extract($_POST); $hp_computer = "200"; $hp_player = "200"; //the above coding is the computer and player hit points if($player=="snarl") $player_attack_value=$hp_computer="2"; if($player=="ravage") $player_attack_value=$hp_computer="18"; if($player=="blast") $player_attack_value=$hp_computer="30"; //the above coding is the player attacks and player attack values $computer_value=array("growl","bite","chew"); $computer=$computer_value[rand(0,sizeof($computer_values)-1)]; if($computer_value=="growl") $computer_attack_value=$hp_player="1"; if($computer_value=="bite") $computer_attack_value=$hp_player="15"; if($computer_value=="chew") $computer_attack_value=$hp_player="25"; //the above coding is the computer attacks and the computer attack values $hp_computer=$hp_computer-$player_attack_value; $hp_player=$hp_player-$computer_attack_value; //print_r($hp_computer); //print_r($hp_player); //the above coding is the effect of the attacks on the player and the computer if($hp_computer<="0") echo "YOU WIN!"; if($hp_player<="0") echo "YOU LOSE! "; //the above coding is what happens if the player or the computer reach 0 hit points echo $hp_player; echo $hp_computer; ?> <form action="default.php" method="post"> <p> <input name="player" type="radio" value="snarl" /> Snarl</p> <p> <input name="player" type="radio" value="ravage" /> Ravage</p> <p> <input name="player" type="radio" value="blast" /> Blast </p> <p> <input type="submit" name="button" id="button" value="Submit" /> <label></label> </p> </form> </body> </html> thanks guys i appreciate your help Link to comment https://forums.phpfreaks.com/topic/140097-player-vs-computer-php-game-help/ Share on other sites More sharing options...
btherl Posted January 9, 2009 Share Posted January 9, 2009 This line: $player_attack_value=$hp_computer="2"; is equivalent to $hp_computer = "2"; $player_attack_value = $hp_computer; Is that what you intended? Link to comment https://forums.phpfreaks.com/topic/140097-player-vs-computer-php-game-help/#findComment-733064 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.