function getPlayerCount() { echo "\nHow many players (excluding yourself) would you like to have participate? "; $players = getStdin(); if (!is_numeric($players)) { echo "\nYou entered an invalid value for the number of players. Please try again.\n"; return getPlayerCount(); } if ($players > 10) { echo "\nUnfortuantely, " . $players . " is too many. Please enter a number less than 10.\n"; return getPlayerCount(); } return $players; }
addHistory($_GET['gameid'], $_GET['text']); echo json_encode('history added'); } } else { echo json_encode('gameid and text must be set'); } } elseif ($action == 'getPlayerCount') { if (isset($_GET['gameid'])) { $count = getPlayerCount($_GET['gameid']); echo json_encode($count); } else { echo json_encode('gameid must be set'); } } elseif ($action == 'gameStart') { if (isset($_GET['gameid'])) { $count = getPlayerCount($_GET['gameid']); if ($count > 1) { $resultQuery = mysqli_query($link, "SELECT started FROM gamestatus WHERE gameid = " . mysqli_real_escape_string($link, $_GET['gameid']) . ";"); while ($row = $resultQuery->fetch_object()) { $started = $row->started; } if (!$started) { $resultQuery = mysqli_query($link, "UPDATE gamestatus SET started = true WHERE gameid = " . mysqli_real_escape_string($link, $_GET['gameid']) . ";"); for ($i = 1; $i < 18; $i++) { createCityInstance($_GET['gameid'], $i); } addHistory($_GET['gameid'], 'game started'); echo json_encode('Game Started'); } else { echo json_encode('Game already started'); }