function people($arrayOfPeaple) { foreach ($arrayOfPeaple as $key => $str) { $sex = human::cut($str, 9, 1); if ($sex % 2 == 0) { $this->sexMap[$sex] = new woman($str); } else { $this->sexMap[$sex] = new man($str); } if (isset($this->sexMap[$sex])) { $this->ad1Person($this->sexMap[$sex], $str); } } }
public function setHeatRay($h) { $this->heatRay = $h; } public function getHeatRay() { return $this->heatRay; } public function useHeatRay(&$target) { $remaining = $target->getHP() - $this->heatRay; // $superman->setHP(90); $target->setHP($remaining); } } $achilleas = new human(100, 10); $achilleas->setUtilityDamage(1.2); $achilleas->setCritChance(10); $achilleas->setRagePower(2); $superman = new kryptonian(100, 10); $superman->setHeatRay(18); $superman->setCritChance(20); $br = 0; while ($achilleas->getHP() && $superman->getHP() > 0) { $br++; if ($br % 2 == 0) { if (rand(0, 1) < 1) { $achilleas->useRagePower(); $achilleas->attack($superman); if ($superman->getHP() > 0) { $superman->useHeatRay($achilleas);
<?php class human { public $gender; public function __construct($gender) { $this->gender = $gender; } public function set_gender($gen) { $this->gender = $gen; } public function get_gender() { return $this->gender; } } $Johnny = new human('male'); $Johnny->set_gender('female'); echo $Johnny->get_gender();
{ $this->table = "station"; } //継承+後処理 function load() { $station = $this->table; $sql = "select * from " . $station; global $pdo; $stmt = $pdo->prepare($sql); $stmt->execute(); $this->result = $stmt->fetchAll(PDO::FETCH_ASSOC); } function show() { foreach ($this->result as $key) { foreach ($key as $value) { echo $value . "<br>"; } } } } $human = new human(); $human->__constract(); $human->load(); $human->show(); echo "<br>"; $station = new station(); $station->__constract(); $station->load(); $station->show();
public function setHeatRay($h) { $this->heatRay = $h; } public function getHeatRay() { return $this->heatRay; } public function useHeatRay(&$target) { $remaining = $target->getHP() - $this->heatRay; // $superman->setHP(90); $target->setHP($remaining); } } $batman = new human(100, 10); $batman->setUtilityDamage(1.2); $batman->setCritChance(10); $superman = new kryptonian(100, 10); $superman->setHeatRay(18); $superman->setCritChance(20); /* $batman->attack($superman); $superman->attack($batman); $batman->useBelt(); $batman->attack($superman); $superman->useHeatRay($batman);*/ $alive = 1; $attack = 0;
public function setHeatRay($h) { $this->heatRay = $h; } public function getHeatRay() { return $this->heatRay; } public function useHeatRay(&$target) { $remaining = $target->getHP() - $this->heatRay; // $superman->setHP(90); $target->setHP($remaining); } } $batman = new human(100, 10, 4); $batman->setUtilityDamage(1.2); $batman->setBatarangsDamage(4); $batman->setCritChance(10); $superman = new kryptonian(200, 10, 3); $superman->setHeatRay(18); $superman->setCritChance(20); do { if ($batman->speed > $superman->speed) { $batman->attack($superman); $superman->attack($batman); $batman->useBelt(); $batman->useBatarangs(); $superman->useHeatRay($batman); } elseif ($batman->speed == $superman->speed) { do {
<?php require_once "kryptonian.class.php"; require_once "human.class.php"; $batman = new human(100, 10); $batman->setUtilityDamage(1.2); $batman->setCritChance(20); $superman = new kryptonian(100, 10); $superman->setHeatRay(8); $superman->setCritChance(15); $winner = 'Noone'; $i = 0; echo "<pre>"; do { if ($i % 2 == 1) { $batman->useBelt(); $superman->useHeatRay($batman); echo 'Superattacks executed.' . "<br>"; if ($superman->getHP() <= 0 && $batman->getHP() > 0) { $winner = 'Batman'; } if ($batman->getHP() <= 0 && $superman->getHP() > 0) { $winner = 'Superman'; } if ($batman->getHP() <= 0 && $superman->getHP() <= 0) { break; } } else { $batman->attack($superman); $superman->attack($batman); if ($superman->getHP() <= 0 && $batman->getHP() > 0) {
//BMI=体重(kg)÷(身長(m)×身長(m)) $bmi = $this->weight / ($this->height / 100 * ($this->height / 100)); $bmi = round($bmi, 2); //bmi値を小数点第2位で四捨五入 return $bmi; } public function __construct($n, $w, $h) { $this->setname($n); $this->setweight($w); $this->setheight($h); } } $post_flug = false; if (isset($_POST['name']) && isset($_POST['height']) && isset($_POST['weight'])) { $person = new human(h($_POST['name']), h($_POST['weight']), h($_POST['height'])); $post_flug = true; } else { $post_flug = false; } function h($v) { return htmlspecialchars($v, ENT_QUOTES); } ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <link type="text/css" rel="stylesheet" href="style.css"> <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
$this->healingFactor = $h * rand(5, 10); } public function getHeal() { return $this->healingFactor; } public function enrage($target) { $this->dmg = $this->dmg * $this->rage; } public function heal($target) { $this->hp = $this->hp + $this->healingFactor; } } $wolverine = new mutant(100, 10); $wolverine->setHeal(5); $wolverine->setEnrage(3); $wolverine->setCritChance(5); $batman = new human(100, 10); $batman->setUtilityDamage(1.2); $batman->setCritChance(10); $superman = new kryptonian(100, 10); $superman->setHeatRay(18); $superman->setCritChance(20); fight($superman, $wolverine); echo "<pre>"; print_r($batman); print_r($superman); print_r($wolverine); exit;
$this->setSpeed(); $this->setUseItems(); } function setUseItems() { $this->useItems = $this->intelligence * 2; } function getUseItems() { return $this->useItems; } function setArmor($a = '') { $this->armor = $this->useItems / 4; } function setSpeed() { $this->speed = $this->speed + $this->useItems / 2; } } $Mincho = new human(); $Mincho->setStats(rand(5, 10), rand(5, 10), rand(5, 30)); $Mincho->setArmor(); $Mincho->setSpeed(); $Pencho = new human(); $Pencho->setStats(rand(5, 10), rand(5, 10), rand(5, 30)); $Pencho->setArmor(); $Pencho->setSpeed(); echo "<pre>"; print_r($Mincho); print_r($Pencho);
public function setHeatRay($h) { $this->heatRay = $h; } public function getHeatRay() { return $this->heatRay; } public function useHeatRay(&$target) { $remaining = $target->getHP() - $this->heatRay; // $superman->setHP(90); $target->setHP($remaining); } } $batman = new human(100, 10); $batman->setUtilityDamage(1.2); $batman->setCritChance(10); $superman = new kryptonian(100, 10); $superman->setHeatRay(18); $superman->setCritChance(20); $firstAttacker; $secondAttacker; $numOfAttack = 2; // $firstAttackerSA=$superman->useHeatRay(); // $secondAttackerSA=$batman->useBelt(); if (rand(0, 100) >= 50) { $firstAttacker = $batman; $secondAttacker = $superman; $firstAttackerSA = $batman->useBelt($secondAttacker); $secondAttackerSA = $superman->useHeatRay($firstAttacker);