Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. require_once 'board.php';
  3. include 'functies.php';
  4. //session_start();
  5. $form_state = 0;
  6. // Display current difficulty
  7. echo "Difficulty: " . ($_SESSION['difficulty']);
  8. // Log out
  9. if (isset($_POST['btnLogOut'])) {
  10. session_destroy();
  11. header('Location: index.php');
  12. }
  13. // Shot vuren, ammo minder
  14. if (isset($_POST['btnShot'])) {
  15. $shot = $_POST['shot'];
  16. $_SESSION['shots'][] = $shot;
  17. $_SESSION['ammo'] = $_SESSION['ammo'] - 1;
  18. echo hitOrMis($shot);
  19. }
  20. ?>
  21. <!DOCTYPE html>
  22. <html lang="en">
  23. <head>
  24. <meta charset="UTF-8">
  25. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  26. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  27. <title>Game</title>
  28. </head>
  29. <body>
  30. <?php
  31. // Naar tweede form state na shot
  32. if (isset($_POST['shot'])) {
  33. $form_state = 1;
  34. $_SESSION['shot'] = $_POST['shot'];
  35. }
  36. ?>
  37. <?php if ($form_state !== 1) { ?>
  38. <form action="game.php" method="POST">
  39. <input type="submit" value="Uitloggen" name="btnLogOut">
  40. </form>
  41. <form action="game.php" method="POST">
  42. <h2>Vul uw schot in</h2>
  43. <div class="input-shot">
  44. <label>Shot</label>
  45. <input type="number" name="shot" required autofocus>
  46. <input type="submit" id="shot" value="Shoot!" name="btnShot">
  47. </div>
  48. <br>
  49. </form>
  50. <?php } ?>
  51. <?php if ($form_state == 1) { ?>
  52. <body>
  53. <h2><?php echo "Uw schot was: " . $_POST['shot']; ?></h2>
  54. <h2><?php echo "U heeft nog " . $_SESSION['ammo'] . " schoten."; ?></h2>
  55. <form action="game.php" method="POST">
  56. <?php
  57. if (empty($_SESSION['shipsPositions'][0]) && empty($_SESSION['shipsPositions'][1])) { ?>
  58. <input type="submit" name="btnPlayAgain" value="Play again">
  59. <?php } else { ?>
  60. <input type="submit" name="btnNextShot" value="Next shot">
  61. <?php } ?>
  62. </form>
  63. </body>
  64. <?php } ?>
  65. <?php
  66. // Als dezelfde speler opnieuw wilt spelen met dezelfde difficulty
  67. if (isset($_POST['btnPlayAgain'])) {
  68. assignShips($_SESSION['difficulty']);
  69. unset($_SESSION['shots']);
  70. }
  71. // Als ammo op is -> game over en game reset
  72. if ($_SESSION['ammo'] === 0) {
  73. echo "Game Over, your score is 0";
  74. assignShips($_SESSION['difficulty']);
  75. unset($_SESSION['shots']);
  76. }
  77. // Als currentships niet meer bestaat
  78. if (!isset($_SESSION['currentShips'])) {
  79. assignShips($_SESSION['difficulty']);
  80. }
  81. if (empty($_SESSION['shipsPositions'][0])) {
  82. echo $_SESSION['currentShips']->returnCurrentShips()[0]->returnName() . " vernietigd!<br>";
  83. }
  84. if (empty($_SESSION['shipsPositions'][1])) {
  85. echo $_SESSION['currentShips']->returnCurrentShips()[1]->returnName() . " vernietigd!<br>";
  86. }
  87. // Berekend score op basis van difficulty en ramaining ammo
  88. if (empty($_SESSION['shipsPositions'][0]) && empty($_SESSION['shipsPositions'][1])) {
  89. if ($_SESSION['difficulty'] == 'Easy'){
  90. echo "You win, your score is " . (($_SESSION['ammo'] / 30) * 100);
  91. }
  92. if ($_SESSION['difficulty'] == 'Normal'){
  93. echo "You win, your score is " . (($_SESSION['ammo'] / 24) * 100);
  94. }
  95. if ($_SESSION['difficulty'] == 'Hard'){
  96. echo "You win, your score is " . (($_SESSION['ammo'] / 16) * 100);
  97. }
  98. }
  99. // Var dumps (in commentline)
  100. // var_dump($_SESSION['currentShips']);
  101. // var_dump($_SESSION['shipsPositions']);
  102. // Als de functie gemaakt is, in board...
  103. echo $_SESSION['currentShips']->printBoard($_SESSION['shots']);
  104. ?>
  105. </body>
  106. </html>