Exemplo n.º 1
0
 public static function getRange($start, $end)
 {
     if ($start < 0) {
         if ($end > $start) {
             return null;
         }
         $direction = "DESC";
         $start *= -1;
         $end *= -1;
     } else {
         if ($end < $start) {
             return null;
         }
         $direction = "ASC";
     }
     $mysqli = new mysqli("classroom.cs.unc.edu", "zrkaplan", "KMP4president", "zrkaplandb");
     $result = $mysqli->query("select id from Ai order by id " . $direction);
     $ais = array();
     if ($result) {
         for ($i = 1; $i < $start; $i++) {
             $result->fetch_row();
         }
         for ($i = $start; $i <= $end; $i++) {
             $next_row = $result->fetch_row();
             if ($next_row) {
                 $ais[] = Ai::findByID($next_row[0]);
             }
         }
     }
     return $ais;
 }
Exemplo n.º 2
0
                if ($result != null) {
                    header("Content-type: application/json");
                    print $result->getJSON();
                    exit;
                } else {
                    header("HTTP/1.0 400 Bad Request");
                    print "Username is already taken";
                    exit;
                }
            }
            if ($path_components[1] == "game") {
                $name = $path_components[2];
                $aiName = $path_components[3];
                $playerScore = $path_components[4];
                $aiScore = $path_components[5];
                $playerId = Player::findByUserName($name)->getID();
                $aiId = Ai::findByName($aiName)->getID();
                $result = Game::create($playerId, $aiId, $playerScore, $aiScore);
                if ($result != null) {
                    header("Content-type: application/json");
                    print $result->getJSON();
                    exit;
                } else {
                    header("HTTP/1.0 404 Bad Request");
                    print "Something went wrong";
                    exit;
                }
            }
        }
    }
}