public function run() { echo '<br><br><br><br>'; $game = new game(); foreach (range(1, 10) as $item) { $sql = "SELECT group_concat(roll_one_id) as '1',\n group_concat(Roll_Two_ID) as '2',\n group_concat(Roll_Three_ID) as '3',\n Frame_Number\n FROM frame where Game_ID = 1 and Player_ID = 1 and Frame_Number = {$item};"; $conn = connectToDatabase(); $result = $conn->query($sql); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { if ($row['Frame_Number'] == 10) { echo '<br>row 1 is: ' . $row['1']; echo '<br>row 2 is: ' . $row['2']; echo '<br>row 3 is: ' . $row['3']; $game->frame(getIntegerNumberOfPinsHitForRollID($row['1']), getIntegerNumberOfPinsHitForRollID($row['2']), getIntegerNumberOfPinsHitForRollID($row['3'])); } else { echo '<br>row 1 is: ' . $row['1']; echo '<br>row 2 is: ' . $row['2']; $game->frame(getIntegerNumberOfPinsHitForRollID($row['1']), getIntegerNumberOfPinsHitForRollID($row['2'])); } } } } echo '<br><br><br><br>'; $game->stats(); echo NL; echo '<br><br><br><br>'; }
function calculateAverageScoreFor($gameID, $teamID) { $sql = "SELECT group_concat(DISTINCT player_id) as 'ids' from Frame where Team_ID = {$teamID} and Game_ID = {$gameID}"; $conn = connectToDatabase(); $result = $conn->query($sql); $totalScore = 0; if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $allPlayers = explode(',', $row['ids']); foreach ($allPlayers as $player) { $game = new \bowling\game(); $getAllFrames = "SELECT Frame_Number, Roll_One_ID, Roll_Two_ID, Roll_Three_ID From Frame where Team_ID = {$teamID} and Game_ID = {$gameID} and Frame.Player_ID = {$player}"; $resultOfPlayers = $conn->query($getAllFrames); if ($resultOfPlayers) { while ($rowOfPlayers = $resultOfPlayers->fetch_assoc()) { if ($rowOfPlayers['Frame_Number'] == 10) { if (isset($rowOfPlayers['Roll_Three_ID'])) { $game->frame(getIntegerNumberOfPinsHitForRollID($rowOfPlayers['Roll_One_ID']), getIntegerNumberOfPinsHitForRollID($rowOfPlayers['Roll_Two_ID']), getIntegerNumberOfPinsHitForRollID($rowOfPlayers['Roll_Three_ID'])); } else { if (isset($rowOfPlayers['Roll_Two_ID'])) { $game->frame(getIntegerNumberOfPinsHitForRollID($rowOfPlayers['Roll_One_ID']), getIntegerNumberOfPinsHitForRollID($rowOfPlayers['Roll_Two_ID'])); } else { $game->frame(getIntegerNumberOfPinsHitForRollID($rowOfPlayers['Roll_One_ID'])); } } } else { if (isset($rowOfPlayers['Roll_Two_ID'])) { $game->frame(getIntegerNumberOfPinsHitForRollID($rowOfPlayers['Roll_One_ID']), getIntegerNumberOfPinsHitForRollID($rowOfPlayers['Roll_Two_ID'])); } else { $game->frame(getIntegerNumberOfPinsHitForRollID($rowOfPlayers['Roll_One_ID'])); } } } $totalScore += $game->score(); } } } } else { return 0; } return round($totalScore / count($allPlayers), 3); }
function calculateTotalScore($playerID, $gameID, $teamID) { $game = new \bowling\game(); $conn = connectToDatabase(); $getAllFrames = "SELECT Frame_Number, Roll_One_ID, Roll_Two_ID, Roll_Three_ID From Frame where Team_ID = {$teamID} and Game_ID = {$gameID} and Frame.Player_ID = {$playerID}"; $resultOfPlayers = $conn->query($getAllFrames); if ($resultOfPlayers) { while ($rowOfPlayers = $resultOfPlayers->fetch_assoc()) { if ($rowOfPlayers['Frame_Number'] == 10) { if (isset($rowOfPlayers['Roll_Three_ID'])) { $game->frame(getIntegerNumberOfPinsHitForRollID($rowOfPlayers['Roll_One_ID']), getIntegerNumberOfPinsHitForRollID($rowOfPlayers['Roll_Two_ID']), getIntegerNumberOfPinsHitForRollID($rowOfPlayers['Roll_Three_ID'])); } else { if (isset($rowOfPlayers['Roll_Two_ID'])) { $game->frame(getIntegerNumberOfPinsHitForRollID($rowOfPlayers['Roll_One_ID']), getIntegerNumberOfPinsHitForRollID($rowOfPlayers['Roll_Two_ID'])); } else { $game->frame(getIntegerNumberOfPinsHitForRollID($rowOfPlayers['Roll_One_ID'])); } } } else { if (isset($rowOfPlayers['Roll_Two_ID'])) { $game->frame(getIntegerNumberOfPinsHitForRollID($rowOfPlayers['Roll_One_ID']), getIntegerNumberOfPinsHitForRollID($rowOfPlayers['Roll_Two_ID'])); } else { $game->frame(getIntegerNumberOfPinsHitForRollID($rowOfPlayers['Roll_One_ID'])); } } } } return $game; }