Hej.
Jeg er igang med at lave et angrebssystem. Det virker korrekt, undtagen en lille detalje.
Prøv at kigge på "your damage" og "damage taken".
ReTaRD
Your damage 194
6425
Andreas
Your damage 137
Damage taken: 194
1806
ReTaRD
Your damage 152
Damage taken: 189
6236
Andreas
Your damage 189
Damage taken: 152
1654
ReTaRD
Your damage 126
Damage taken: 191
6045
Andreas
Your damage 191
Damage taken: 126
1528
Jeg fårstår ikke hvorfor, at "your damage" hos $duelist[2] går op i $duelist[1] "damage taken".
Her er koden:
Class duelist {
private $firsthit;
public $username, $hp, $sideend;
public function etslag($firsthit) {
if (($firsthit) == 1){
$dmgonshow = "";
}else{
$this->hp -= $this->dmgon;
$dmgonshow = "Damage taken: ".$this->dmgon."<br />";
}
if (($this->hp) >0) {
$dmgshow = "<br />Your damage ".$this->dmg;
}else{
$dmgshow = "";
}
echo $this->username.$dmgshow."<br />".$dmgonshow.$this->hp."<br /><br />";
}
}
function doattack($attacker, $attacking, $attackerhealth) {
$duelist[1] = new duelist();
$duelist[1]->hp = $attackerhealth;
$duelist[1]->username = $attacker;
$duelist[2] = new duelist();
$duelist[2]->hp = 2000;
$duelist[2]->username = $attacking;
$i=1;
while(($duelist[1]->hp) > 0 && ($duelist[2]->hp) > 0) {
$duelist[1]->dmg = rand(100, 200);
$duelist[2]->dmg = rand(100, 200);
$duelist[1]->dmgon = $duelist[2]->dmg;
$duelist[2]->dmgon = $duelist[1]->dmg;
if (($duelist[2]->hp) > 0) {
$duelist[1]->etslag($i);
$i++;
}
if (($duelist[1]->hp) > 0) {
$duelist[2]->etslag($i);
}
}
}
Indlæg senest redigeret d. 26.10.2008 15:44 af Bruger #14181