@@ -1,22 +1,22 @@ | |||
{ | |||
// Use IntelliSense to learn about possible attributes. | |||
// Hover to view descriptions of existing attributes. | |||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | |||
"version": "0.2.0", | |||
"configurations": [ | |||
{ | |||
"name": "Listen for XDebug", | |||
"type": "php", | |||
"request": "launch", | |||
"port": 9000 | |||
}, | |||
{ | |||
"name": "Launch currently open script", | |||
"type": "php", | |||
"request": "launch", | |||
"program": "${file}", | |||
"cwd": "${fileDirname}", | |||
"port": 9000 | |||
} | |||
] | |||
} | |||
// Use IntelliSense to learn about possible attributes. | |||
// Hover to view descriptions of existing attributes. | |||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | |||
"version": "0.2.0", | |||
"configurations": [ | |||
{ | |||
"name": "Listen for XDebug", | |||
"type": "php", | |||
"request": "launch", | |||
"port": 9003 | |||
}, | |||
{ | |||
"name": "Launch currently open script", | |||
"type": "php", | |||
"request": "launch", | |||
"program": "${file}", | |||
"cwd": "${fileDirname}", | |||
"port": 9003 | |||
} | |||
] | |||
} |
@@ -1,21 +1,26 @@ | |||
<?php | |||
session_start(); | |||
require_once 'position.php'; | |||
require_once 'ship.php'; | |||
class Board | |||
{ | |||
private $board; | |||
private $gameBoard; | |||
private $ships; | |||
private $newShipPos; | |||
private $currentShips; | |||
// We constructen de array die het spelbord zal vullen | |||
function __construct() | |||
{ | |||
$this->board = array(); | |||
$this->gameBoard = array(); | |||
$this->initArray(); | |||
$this->initShips(); | |||
$this->displayBoard(); | |||
//$this->displayBoard(); | |||
} | |||
@@ -26,70 +31,79 @@ private function initArray(){ | |||
for ($x = 0; $x < 52; $x ++){ | |||
$this->board[$x]= new Position($x); | |||
$this->gameBoard[$x]= new Position($x); | |||
} | |||
} | |||
private function initShips() { | |||
if ($_POST['difficulty'] == 'Easy'){ | |||
$this->initVliegdekschip(); | |||
$this->initSlagschip(); | |||
if ($_SESSION['difficulty'] == 'Easy'){ | |||
$currentShips[] = $this->initVliegdekschip(); | |||
$currentShips[] = $this->initSlagschip(); | |||
} else if ($_POST['difficulty'] == 'Normal'){ | |||
$this->initSlagschip(); | |||
$this->initKruiser(); | |||
} else if ($_SESSION['difficulty'] == 'Normal'){ | |||
$currentShips[] = $this->initSlagschip(); | |||
$currentShips[] = $this->initKruiser(); | |||
} else if ($_POST['difficulty'] == 'Hard'){ | |||
$this->initTorpedojager(); | |||
$this->initDuikboot(); | |||
} else if ($_SESSION['difficulty'] == 'Hard'){ | |||
$currentShips[] = $this->initTorpedojager(); | |||
$currentShips[] = $this->initDuikboot(); | |||
} | |||
} | |||
public function returnShips(){ | |||
return $this->currentShips; | |||
} | |||
private function initVliegdekschip() { | |||
$this->ships[] = new Ship("Vliegdekschip", 5); | |||
$rand = rand(0, 46); | |||
$this->board[$rand] = "<"; | |||
$this->board[$rand+1] = "="; | |||
$this->board[$rand+2] = "="; | |||
$this->board[$rand+3] = "="; | |||
$this->board[$rand+4] = ">"; | |||
$this->gameBoard[$rand] = "<"; | |||
$this->gameBoard[$rand+1] = "="; | |||
$this->gameBoard[$rand+2] = "="; | |||
$this->gameBoard[$rand+3] = "="; | |||
$this->gameBoard[$rand+4] = ">"; | |||
} | |||
private function initSlagschip() { | |||
$this->ships[] = new Ship("Slagschip", 4); | |||
$rand = rand(0, 47); | |||
$this->board[$rand] = "<"; | |||
$this->board[$rand+1] = "="; | |||
$this->board[$rand+2] = "="; | |||
$this->board[$rand+3] = ">"; | |||
$this->gameBoard[$rand] = "<"; | |||
$this->gameBoard[$rand+1] = "="; | |||
$this->gameBoard[$rand+2] = "="; | |||
$this->gameBoard[$rand+3] = ">"; | |||
} | |||
private function initKruiser() { | |||
$this->ships[] = new Ship("Kruiser", 3); | |||
$rand = rand(0, 48); | |||
$this->board[$rand] = "<"; | |||
$this->board[$rand+1] = "="; | |||
$this->board[$rand+2] = ">"; | |||
$this->gameBoard[$rand] = "<"; | |||
$this->gameBoard[$rand+1] = "="; | |||
$this->gameBoard[$rand+2] = ">"; | |||
} | |||
private function initTorpedojager() { | |||
$this->ships[] = new Ship("Torpedojager", 2); | |||
$rand = rand(0, 49); | |||
$this->board[$rand] = "<"; | |||
$this->board[$rand+1] = ">"; | |||
$this->gameBoard[$rand] = "<"; | |||
$this->gameBoard[$rand+1] = ">"; | |||
} | |||
private function initDuikboot() { | |||
$this->ships[] = new Ship("Duikboot", 1); | |||
$rand = rand(0, 50); | |||
$this->board[$rand] = "="; | |||
$this->gameBoard[$rand] = "="; | |||
} | |||
public function getBoard() { | |||
return $this->board; | |||
return $this->gameBoard; | |||
} | |||
public function getShips() { | |||
@@ -123,7 +137,7 @@ public function displayBoard() { | |||
} else if ($x == 52){ | |||
echo "|" . "<br>"; | |||
} else { | |||
echo json_encode($this->board[$x]); | |||
echo " "; | |||
} | |||
} | |||
} | |||
@@ -132,4 +146,4 @@ public function displayBoard() { | |||
} | |||
?> | |||
?> |
@@ -1,3 +1,5 @@ | |||
<!DOCTYPE html> | |||
<html lang="en"> | |||
<head> | |||
@@ -7,7 +9,7 @@ | |||
<title>Difficulty</title> | |||
</head> | |||
<body> | |||
<form method="POST" action="game.php"> | |||
<form method="POST" action="#"> | |||
<div class="input-group"> | |||
<p>Select your difficulty</p> | |||
<label>Difficulty</label> | |||
@@ -22,8 +24,25 @@ | |||
<input type="radio" name="difficulty" value="Hard"> | |||
<label for="Hard">Hard</label> | |||
<br> | |||
<input type="submit" id="submit" value="Submit"> | |||
<input type="submit" name="submit" id="submit" value="Submit"> | |||
</div> | |||
</form> | |||
</body> | |||
</html> | |||
</html> | |||
<?php | |||
require_once 'board.php'; | |||
require_once 'ship.php'; | |||
require_once 'position.php'; | |||
session_start(); | |||
if (isset($_POST['submit'])){ | |||
$_SESSION['gaming'] = true; | |||
$_SESSION['difficulty'] = $_POST['difficulty']; | |||
header("Location: game.php"); | |||
} | |||
?> |
@@ -1,17 +1,23 @@ | |||
<?php | |||
session_start(); | |||
session_start(); | |||
require_once 'board.php'; | |||
require_once 'ship.php'; | |||
require_once 'position.php'; | |||
require_once 'board.php'; | |||
require_once 'ship.php'; | |||
require_once 'position.php'; | |||
$form_state = 0; | |||
var_dump($_SESSION['difficulty']); | |||
// ---HTML--- | |||
// ---HTML--- | |||
?> | |||
<!DOCTYPE html> | |||
<html lang="en"> | |||
<head> | |||
@@ -22,7 +28,15 @@ | |||
</head> | |||
<body> | |||
<form action="shotform.php" method="POST"> | |||
<?php | |||
if ($_POST['shot']){ | |||
$form_state = 1; | |||
$_SESSION['shot'] = $_POST['shot']; | |||
} | |||
?> | |||
<?php if ($form_state !== 1) { ?> | |||
<form action="game.php" method="POST"> | |||
<h2>Vul uw schot in</h2> | |||
<div class="input-shot"> | |||
<label>Shot</label> | |||
@@ -30,15 +44,40 @@ | |||
<input type="submit" id="shot" value="Shoot!"> | |||
</div> | |||
<br> | |||
</form> | |||
<?php } ?> | |||
<?php if ($form_state == 1) { ?> | |||
<body> | |||
<pre><?php $test = new Board();?> | |||
</pre> | |||
<h2><?php echo "Uw schot was: " . $_POST['shot']; ?></h2> | |||
<form action="game.php" method="POST"> | |||
<input type="submit" value="Next shot"> | |||
</form> | |||
</body> | |||
<?php } ?> | |||
<pre><?php | |||
//if ($_SESSION['gaming']){ | |||
//$_SESSION['gaming']->displayBoard(); | |||
$test = new Board(); | |||
$_SESSION['newBoard'] = $test; | |||
$_SESSION['gaming'] = false; | |||
//} | |||
$_SESSION['newBoard']->displayBoard(); | |||
var_dump($_SESSION['newBoard']->returnShips()); | |||
?> | |||
</pre> | |||
</body> | |||
</html> |
@@ -24,7 +24,6 @@ | |||
?> | |||
<!DOCTYPE html> | |||
<html lang="en"> | |||
<head> |
@@ -1,6 +1,5 @@ | |||
<?php | |||
session_start(); | |||
if (isset($_POST['login'])){ |
@@ -19,9 +19,8 @@ class Position | |||
public function displayPos() { | |||
if($this->shipPos && $this->shotStatus) { | |||
return 'x'; | |||
} else if ($this->shipPos) { | |||
return '='; | |||
} else if ($this->shotStatus) { | |||
} | |||
else if ($this->shotStatus) { | |||
return '+'; | |||
} else { | |||
return' '; |
@@ -1,4 +1,5 @@ | |||
<?php | |||
session_start(); | |||
unset($_SESSION['errormsg']); | |||
@@ -85,14 +86,5 @@ function validateShot($shot) { | |||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |||
<title>Shotform</title> | |||
</head> | |||
<body> | |||
<h2><?php echo "Uw schot was: " . $_POST['shot']; ?></h2> | |||
<form action="game.php" method="POST"> | |||
<input type="submit" value="Back to board"> | |||
</form> | |||
</body> | |||
</html> |