Beispiel #1
0
 public function update(World $world)
 {
     if ($this->path !== null && $this->path->isEnd()) {
         $item = $world->getMap()->getItem($this->path->getDestination());
         if (1 == 1 || $item == MapBuilder::FLEUR) {
             $world->getLogger()->log(LogLevel::INFO, "le chat mange");
             $this->player->getEstomac()->setNouriture($this->player->getEstomac()->getNouriture() + 10);
             $world->getMap()->setItem($this->path->getDestination(), MapBuilder::HERBE);
         }
         $this->path = null;
     }
     if ($this->path === null) {
         $newPoint = $world->getMap()->findItem(MapBuilder::FLEUR);
         if ($newPoint !== null) {
             $world->getLogger()->log(LogLevel::INFO, "le chat part vers le point " . $newPoint->getX() . ", " . $newPoint->getY());
             $this->path = new PathPoint($this->player, $newPoint);
         }
     }
     if ($this->path !== null) {
         $world->getLogger()->log(LogLevel::INFO, "le chat est à la recherche de nourriture");
         $this->path->update($world);
     } else {
         $world->getLogger()->log(LogLevel::INFO, "le chat n'a plus de nourriture");
     }
 }
Beispiel #2
0
 public function update(World $world)
 {
     $positionPlayer = $this->player->getPosition();
     if ($positionPlayer->getX() == $this->destination->getX() && $positionPlayer->getY() == $this->destination->getY()) {
         $this->end = true;
         return;
     }
     $direction = array("X" => 0, "Y" => 0);
     $world->getMap()->setItem($positionPlayer, MapBuilder::HERBE);
     if ($positionPlayer->getX() < $this->destination->getX()) {
         $direction["X"] = 1;
     }
     if ($positionPlayer->getX() > $this->destination->getX()) {
         $direction["X"] = -1;
     }
     if ($positionPlayer->getY() < $this->destination->getY()) {
         $direction["Y"] = 1;
     }
     if ($positionPlayer->getY() > $this->destination->getY()) {
         $direction["Y"] = -1;
     }
     $positionPlayer->setDirection(new Direction($direction["X"], $direction["Y"]));
     $positionPlayer->move();
     $world->getLogger()->log(LogLevel::INFO, "le joeur " . get_class($this->player) . " est en X : " . $positionPlayer->getX() . " Y : " . $positionPlayer->getY() . " et il se déplace en X : " . $direction["X"] . " Y : " . $direction["Y"]);
 }