hp = $hp; $this->power = $power; $this->endurance = $endurance; } /** * 名前を設定します * * @param string $name */ public function setName($name) { $this->name = $name; } /** * 名前を取得します * * @return string */ public function getName() { return $this->name; } /** * 攻撃を行います * * @return int 攻撃力を返す */ public function attack() { return $this->power; } /** * ダメージ判定を行います * * @param int $attack * @return bool 体力が0になったら true、まだ残っていれば false */ public function damage($attack) { $calc = $attack - $this->endurance; if ($calc <= 0) { $calc = 1; } $this->hp -= $calc; if ($this->hp <= 0) { $this->hp = 0; return true; } return false; } /** * キャラクター情報を表示します * * @return string */ public function showParameter() { $str = nl2br('名 前:' . $this->name . "\r\n" . '体 力:' . $this->hp . "\r\n" . ' 力 :' . $this->power . "\r\n" . '耐 久:' . $this->endurance); return $str; } }