/** * Tests MW_Mano->defend() */ public function testDefend() { $this->MW_Mano = new MW_Mano('Gil'); $this->MW_Mano->setDef(5); $this->assertEquals(5, $this->MW_Mano->getDef()); $sgth = $this->MW_Mano->defend(); $this->assertGreaterThan(5, $sgth); }
public function attack(MW_Mano $victim) { $atk = $this->getAtk() + $this->getRandom(); $def = $victim->defend(); $dmgMultiplier = $this->getRandom(1, 100) / 100; if ($atk > $def) { $dmg = round($atk * $dmgMultiplier); $victim->hurt($dmg); $action = "%s did %d damage on %s"; } else { $dmg = round($def * $dmgMultiplier); $this->hurt($dmg); $action = "%s took %d damage from %s"; } return sprintf($action, $this->getName(), $dmg, $victim->getName()); }
public function attack(MW_Mano $victim) { $atk = $this->getAtk() + trim(file_get_contents('http://www.random.org/integers/?num=1&min=1&max=10&col=1&base=10&format=plain&rnd=new')); $def = $victim->defend(); $dmgMultiplier = trim(file_get_contents('http://www.random.org/integers/?num=1&min=1&max=10&col=1&base=10&format=plain&rnd=new')) / 10; if ($atk > $def) { $dmg = round($atk * $dmgMultiplier); $victim->hurt($dmg); $action = "%s did %d damage on %s"; } else { $dmg = round($def * $dmgMultiplier); $this->hurt($dmg); $action = "%s took %d damage from %s"; } return sprintf($action, $this->getName(), $dmg, $victim->getName()); }