Beispiel #1
0
 /**
  * GET/POST/PUT/DELETE запросы к маршруту
  *
  * @param string $path
  * @param Closure $action
  * @param string $filter
  * @return boolean
  */
 protected function any_action($path, Closure $action, $filter = null)
 {
     if (static::$found) {
         return false;
     }
     $path = $this->route_patterns($path);
     if (preg_match("#^" . $path . "\$#", static::$path, $match)) {
         if (!is_null($filter)) {
             $filters = $this->filters_result($filter);
             if (!array_all(true, $filters)) {
                 return false;
             }
         }
         $params = $this->params($action, $match);
         static::$action = $action;
         static::$match = $params;
         static::$found = true;
         return true;
     }
     return false;
 }
Beispiel #2
0
 private static function findPath($curX, $curY)
 {
     //failsafe check here
     static::$failSafe++;
     if (static::$failSafe >= static::$failSafeLimit) {
         static::$found = true;
     }
     if (static::$found != true) {
         //resetting the default values for this current square
         $lowestEstimatedCost = 0;
         $shortestX = 0;
         $shortestY = 0;
         //looping through all the nearby squares
         for ($x = -1; $x <= 1; $x++) {
             if (static::$found == false) {
                 for ($y = -1; $y <= 1; $y++) {
                     if (static::$found == false) {
                         $checkX = $x + $curX;
                         //$checkY=$y+$curY;
                         //4.4 tem q ir pra 3.3 mas tá indo pra 3.4
                         if ($curX == 0) {
                             $checkY = $y + $curY;
                         } else {
                             $checkY = $curX % 2 == 0 ? $y + $curY - 1 : $y + $curY;
                         }
                         //making sure the checked square is within map boundries
                         if ($checkX >= 0 && $checkY >= 0 && $checkX < static::getMapWidth() && $checkY < static::getMapHeight()) {
                             if ($checkX == $curX && $checkY == $curY) {
                                 //this is the current square we are on, so ignore for now
                             } else {
                                 if ($checkX == static::$destX && $checkY == static::$destY) {
                                     //we have found the destination!
                                     static::$found = true;
                                     static::$path[] = static::$destX . 'x' . static::$destY;
                                 } else {
                                     //if this square has not been 'walked' yet, then consider it as one of the next step
                                     if (!in_array($checkX . 'x' . $checkY, static::$walked)) {
                                         //$weight = static::$map[$checkX.'x'.$checkY]['weight'];
                                         $area = static::$mapa[$checkX][$checkY];
                                         $weight = 1.0;
                                         if ($area->getTipo() == AREA_PAREDE) {
                                             $weight = 10.0;
                                         } elseif (!is_null($area->getPersonagem())) {
                                             $weight = 10.0;
                                         }
                                         //$weight = (($x==-1 && $y==-1) || ($x==-1 && $y==1) || ($x==1 && $y==-1) || ($x==1 && $y==1))?$weight*1.4:$weight;
                                         $estimatedCost = static::estimatedCost($checkX, $checkY, $weight);
                                         //this makes sure the lowest cost square is used for next step
                                         if ($estimatedCost < $lowestEstimatedCost || $lowestEstimatedCost == 0) {
                                             $lowestEstimatedCost = $estimatedCost;
                                             $shortestX = $checkX;
                                             $shortestY = $checkY;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (static::$found != true) {
         if ($shortestX == 0 || $shortestY == 0) {
             //if the shortest locations are 0 then calculation must have gotten stuck and we clear the walked path
             //and try to find a new path from where we got stuck, essentially a re-solve
             static::$walked = array();
             static::$walked[] = $curX . 'x' . $curY;
             static::findPath($curX, $curY, static::$destX, static::$destY);
         } else {
             //we store the next step into walked array (so it is not checked again during this path)
             static::$walked[] = $shortestX . 'x' . $shortestY;
             //storing the location into path array
             static::$path[] = $shortestX . 'x' . $shortestY;
             static::findPath($shortestX, $shortestY, static::$destX, static::$destY);
         }
     }
 }