123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <?php
- require_once "dbase.inc";
- require_once "gamefunction.inc";
-
- //tables
- //display number for each table cell
- function theadVisualTable()
- {
- if (isset($_SESSION['game'])) {
- for ($i = 0; $i < $_SESSION["game"]->ships[0]->printDokLengte(); $i++) {
- ?>
- <th>
- <?= $i; ?>
- </th>
- <?php }
- }
- }
-
- //show if there was hit, miss or endresult in table.
- function tbodyVisualTable()
- {
- if (isset($_SESSION['game'])) {
- for ($i = 0; $i < $_SESSION["game"]->ships[0]->printDokLengte(); $i++) { ?>
- <td>
- <?php
-
- if (in_array($i, $_SESSION["game"]->hitCoor)) {
-
- echo 'X';
- } elseif (isset($_SESSION["game"]) && $_SESSION["game"]->ammo <= 0 || $_SESSION['game']->gameResult == 1) {
- $shipArray = [$_SESSION["game"]->ships[0]->printCoord(), $_SESSION["game"]->ships[1]->printCoord()];
-
- if (($i >= $shipArray[0][0] && $i <= $shipArray[0][1]) ||
- ($i >= $shipArray[1][0] && $i <= $shipArray[1][1])
- ) {
-
- echo '=';
- } elseif ($i == $shipArray[0][0] - 1 && $i == $shipArray[1][1] + 1 || $i == $shipArray[1][0] - 1 && $i == $shipArray[0][1] + 1) {
- echo '><';
- } elseif ($i == $shipArray[0][0] - 1 || $i == $shipArray[1][0] - 1) {
- echo '<';
- } elseif ($i == $shipArray[0][1] + 1 || $i == $shipArray[1][1] + 1) {
- echo '>';
- } elseif (in_array($i, $_SESSION["game"]->shotCoor)) {
- echo 'O';
- }
- } elseif (in_array($i, $_SESSION["game"]->shotCoor)) {
-
- echo 'O';
- }
-
- ?>
- </td><?php
- }
- }
- }
-
- //show highscores of all users
- function tbodyHighScores()
- {
- global $dbase;
- $queryHighScore = $dbase->highScoreQuery();
- while ($result = $queryHighScore->fetchArray(SQLITE3_NUM)) {
- ?>
- <tr>
- <td>
- <?= $result[0]; ?>
- </td>
- <td>
- <?= $result[1]; ?>
- </td>
- </tr>
-
- <?php
- }
- }
-
- //show higscores of current users
- function tbodyUserScores()
- {
- global $dbase;
- $queryUserScore = $dbase->userScoreQuery($_SESSION['spelerId']);
- while ($result = $queryUserScore->fetchArray(SQLITE3_NUM)) {
- ?>
- <tr>
- <td>
- <?= $result[0]; ?>
- </td>
- <td>
- <?php
- if ($result[1] == 1) {
- echo "win";
- } else {
- echo "loss";
- }
- ?>
- </td>
- <td>
- <?= $result[2]; ?>
- </td>
- </tr>
- <?php
- }
- }
-
- // forms
- //select difficulty at start game
- function difficultyForm()
- {
- if (!(isset($_SESSION['game']))) {
- ?>
- <label for="difficulty-select">Choose difficulty:</label>
- <select name="difficulty" id="difficulty-select" class="difficulty__selection">
- <option value="">--please choose the difficulty--</option>
- <option value="easy">easy</option>
- <option value="medium">medium</option>
- <option value="hard">hard</option>
- </select>
- <?php
- }
- }
-
- //input shot during game
- function shotForm()
- {
- if (isset($_SESSION['game']) && $_SESSION['game']->gameResult === null) {
- ?>
- <label for="shot">Shot: </label><br>
- <input type="number" id="shot" name="shot" class="game__selection" required autofocus>
- <?php
- }
- }
-
- //change name submit button at end game.
- function submitButtonValue()
- {
- if (isset($_SESSION['game']) && $_SESSION['game']->gameResult !== null) {
- ?> value="try again"
- <?php } else { ?>
- value="submit"
- <?php
- }
- }
-
- //show if player has won or lost at end game.
- function showGameResult()
- {
- if (isset($_SESSION['game']) && $_SESSION['game']->gameResult === 0) {
- ?>
- <h3> <?= "lost"; ?> </h3>
- <?php
- } elseif (isset($_SESSION['game']) && $_SESSION['game']->gameResult === 1) {
- ?>
- <h3> <?= "win"; ?> </h3>
- <?php
- }
- }
-
- //show shots left during game, or at end game if player has won.
- function showShotsLeft()
- {
- if (isset($_POST['shot']) && $_SESSION['game']->ammo > 0 || isset($_POST['difficulty'])) {
- ?>
- shots left:
- <?php echo $_SESSION['game']->ammo;
- }
- }
|