Example #1
0
 static function hitBee($inputBees)
 {
     $random_key = array_rand($inputBees);
     //$random_key=rand(0, count($inputBees));
     //print_r(GamePlay::$bees[$ramdon_key]);
     $inputBees[$random_key]->beingHit();
     echo "------------------------------------------------------" . "<br/>";
     echo "HITTING THIS RANDOM BEE ... HONEY!" . "<br/>";
     echo "TO WIN THE QUEEN MUST BE DEAD ... SHE IS THE KEY" . "<br/>";
     echo "<pre>";
     echo "RANDOM INDEX ==> " . $random_key . "<br/>";
     if ($random_key == 0) {
         echo "WELL DONE SHE WAS THE QUEEN" . "<br/>";
         if ($inputBees[$random_key]->getLifeSpan() <= 0) {
             echo "GAME OVER FOR THE QUEEN! YOU WIN!!!" . "<br/>";
             $_SESSION["myBees"] = GamePlay::startGame();
             return $_SESSION["myBees"];
         }
     }
     echo "HIT ==> " . $inputBees[$random_key]->getLifeSpan() . "<br/>";
     if ($inputBees[$random_key]->getLifeSpan() <= 0) {
         unset($inputBees[$random_key]);
         $inputBees = array_values($inputBees);
     }
     print_r($inputBees[$random_key]);
     echo "</pre>";
     echo "------------------------------------------------------" . "<br/>";
     echo "<pre>";
     print_r($inputBees);
     echo "</pre>";
     return $inputBees;
 }
Example #2
0
<html>
<body>

<h1>Bee Test</h1>

<p>Karim Abdeselam Canales</p>

<form action="http://127.0.0.1/BeeTest/index.php" method="get">
  <input type="text" name="play" value="start" hidden><br>
  <input type="submit" value="Start">
</form>

<form action="http://127.0.0.1/BeeTest/index.php" method="get">
  <input type="text" name="play" value="hit" hidden><br>
  <input type="submit" value="Hit">
</form>

<?php 
if (isset($_GET['play']) && $_GET['play'] == "start") {
    $_SESSION["myBees"] = GamePlay::startGame();
} else {
    if (isset($_GET['play']) && $_GET['play'] == "hit") {
        $_SESSION["myBees"] = GamePlay::hitBee($_SESSION["myBees"]);
    }
}
?>


</body>
</html>