Hello everybody. Im new with this php codes. I am trying to make my own RPG game at home. Im stuck with this fighting script. what I have now is this:
<html>
<body>
$attacker['health']=30
$attacker['dodge']=3
$attacker['accuracy']=3
$attacker['weapondamage']=5-7
$defender['health']=30
$defender['dodge']=4
$defender['accuracy']=2
$defender['weapondamage']=5-7
<?php
if ( $attacker['accuracy']>= $defender['dodge']) // first attack is successful
echo "Attacker hit the defender with" $attacker['weapondamage'] . ;
elseif (( $attacker['accuracy']< $defender['dodge'])) // first attack is miss
echo "Defender dodge the Attacker";
?>
</body>
</html>
I want this to loop until one player is dead. I don't know how to do this. And also I want the echo to be continuous like this:
Attacker miss the Defender.
Defender miss the Attacker!
Attacker miss the Defender.
Defender hit the Attacker with 10 damage!
Attacker hit the Defender with 40 damage!
Defender hit the Attacker with 30 damage and died!
Defender wins!
Now my questions are:
What are the things I need to place in my current script to have those above results?
Is there a way to materialize my fighting script?
Help pls...
2 replies to this topic
#1
Posted 22 February 2011 - 08:07 PM
|
|
|
#2
Posted 22 February 2011 - 09:39 PM
Generally you can put it into a while/do-while loop, such as
Just visualize what will be done each loop, or you may end up with an infinite one.
You may want to utilize each player in to an object, so that object may contain user functions (i.e. $defender->attack() or $attacker->isDead(); ) and store data as members.
while($attacker["health"] > 0 && $defender["health"] > 0) {
//game logic here
}
//announce win or tie here
Just visualize what will be done each loop, or you may end up with an infinite one.
You may want to utilize each player in to an object, so that object may contain user functions (i.e. $defender->attack() or $attacker->isDead(); ) and store data as members.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#3
Posted 24 February 2011 - 05:17 AM
I see... thanks for the answer Alex... it really helps.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









