123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?php
-
- require_once 'board.php';
- include 'functies.php';
-
- //session_start();
-
- $form_state = 0;
-
- // Display current difficulty
-
- echo "Difficulty: " . ($_SESSION['difficulty']);
-
- // Log out
-
- if (isset($_POST['btnLogOut'])) {
- session_destroy();
- header('Location: index.php');
- }
-
- // Shot vuren, ammo minder
-
- if (isset($_POST['btnShot'])) {
- $shot = $_POST['shot'];
- $_SESSION['shots'][] = $shot;
- $_SESSION['ammo'] = $_SESSION['ammo'] - 1;
- echo hitOrMis($shot);
- }
-
-
-
- ?>
-
-
-
- <!DOCTYPE html>
- <html lang="en">
-
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Game</title>
-
- </head>
-
- <body>
-
-
-
- <?php
-
- // Naar tweede form state na shot
-
- if (isset($_POST['shot'])) {
- $form_state = 1;
- $_SESSION['shot'] = $_POST['shot'];
- }
- ?>
-
- <?php if ($form_state !== 1) { ?>
-
- <form action="game.php" method="POST">
- <input type="submit" value="Uitloggen" name="btnLogOut">
- </form>
- <form action="game.php" method="POST">
- <h2>Vul uw schot in</h2>
- <div class="input-shot">
- <label>Shot</label>
- <input type="number" name="shot" required autofocus>
- <input type="submit" id="shot" value="Shoot!" name="btnShot">
- </div>
- <br>
-
- </form>
- <?php } ?>
- <?php if ($form_state == 1) { ?>
-
- <body>
-
- <h2><?php echo "Uw schot was: " . $_POST['shot']; ?></h2>
- <h2><?php echo "U heeft nog " . $_SESSION['ammo'] . " schoten."; ?></h2>
-
- <form action="game.php" method="POST">
- <?php
-
- if (empty($_SESSION['shipsPositions'][0]) && empty($_SESSION['shipsPositions'][1])) { ?>
- <input type="submit" name="btnPlayAgain" value="Play again">
- <?php } else { ?>
- <input type="submit" name="btnNextShot" value="Next shot">
-
- <?php } ?>
- </form>
-
-
- </body>
-
- <?php } ?>
-
- <?php
-
- // Als dezelfde speler opnieuw wilt spelen met dezelfde difficulty
-
- if (isset($_POST['btnPlayAgain'])) {
- assignShips($_SESSION['difficulty']);
- unset($_SESSION['shots']);
- }
-
- // Als ammo op is -> game over en game reset
-
- if ($_SESSION['ammo'] === 0) {
- echo "Game Over, your score is 0";
- assignShips($_SESSION['difficulty']);
- unset($_SESSION['shots']);
- }
-
- // Als currentships niet meer bestaat
-
- if (!isset($_SESSION['currentShips'])) {
- assignShips($_SESSION['difficulty']);
- }
-
- if (empty($_SESSION['shipsPositions'][0])) {
- echo $_SESSION['currentShips']->returnCurrentShips()[0]->returnName() . " vernietigd!<br>";
- }
- if (empty($_SESSION['shipsPositions'][1])) {
- echo $_SESSION['currentShips']->returnCurrentShips()[1]->returnName() . " vernietigd!<br>";
- }
-
- // Berekend score op basis van difficulty en ramaining ammo
-
- if (empty($_SESSION['shipsPositions'][0]) && empty($_SESSION['shipsPositions'][1])) {
- if ($_SESSION['difficulty'] == 'Easy'){
- echo "You win, your score is " . (($_SESSION['ammo'] / 30) * 100);
- }
-
- if ($_SESSION['difficulty'] == 'Normal'){
- echo "You win, your score is " . (($_SESSION['ammo'] / 24) * 100);
- }
-
- if ($_SESSION['difficulty'] == 'Hard'){
- echo "You win, your score is " . (($_SESSION['ammo'] / 16) * 100);
- }
-
- }
-
- // Var dumps (in commentline)
-
- // var_dump($_SESSION['currentShips']);
- // var_dump($_SESSION['shipsPositions']);
-
-
- // Als de functie gemaakt is, in board...
- echo $_SESSION['currentShips']->printBoard($_SESSION['shots']);
-
- ?>
-
- </body>
-
- </html>
|