@@ -4,9 +4,6 @@ require_once 'ship.php'; | |||
class Board | |||
{ | |||
// protected $gameBoard; | |||
// protected $ships; | |||
protected $currentShips; | |||
@@ -18,6 +15,7 @@ class Board | |||
$this->initShips($difficulty); | |||
} | |||
// We zetten een difficulty | |||
protected function initShips($difficulty) | |||
{ | |||
@@ -25,12 +23,15 @@ class Board | |||
if ($difficulty == 'Easy') { | |||
$this->currentShips[] = new torpedojager(); | |||
$this->currentShips[] = new duikboot(); | |||
$_SESSION['ammo'] = 20; | |||
} else if ($difficulty == 'Normal') { | |||
$this->currentShips[] = new slagSchip(); | |||
$this->currentShips[] = new kruiser(); | |||
$_SESSION['ammo'] = 18; | |||
} else if ($difficulty == 'Hard') { | |||
$this->currentShips[] = new vliegdekSchip(); | |||
$this->currentShips[] = new slagSchip(); | |||
$_SESSION['ammo'] = 16; | |||
} | |||
} | |||
@@ -8,17 +8,30 @@ session_start(); | |||
$form_state = 0; | |||
var_dump($_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); | |||
} | |||
// Als ammo op is | |||
if ($_SESSION['ammo'] == 0) { | |||
echo "Game Over, try again"; | |||
assignShips($_SESSION['difficulty']); | |||
unset($_SESSION['shots']); | |||
} | |||
?> | |||
@@ -63,6 +76,7 @@ if (isset($_POST['btnShot'])) { | |||
<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 | |||
@@ -82,16 +96,19 @@ if (isset($_POST['btnShot'])) { | |||
<?php | |||
// Als dezelfde speler opnieuw wilt spelen met dezelfde difficulty | |||
if (isset($_POST['btnPlayAgain'])) { | |||
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>"; | |||
} | |||
@@ -99,11 +116,10 @@ if (isset($_POST['btnShot'])) { | |||
echo $_SESSION['currentShips']->returnCurrentShips()[1]->returnName() . " vernietigd!<br>"; | |||
} | |||
// Var dumps (in commentline) | |||
// var_dump($_SESSION['currentShips']); | |||
var_dump($_SESSION['shipsPositions']); | |||
// var_dump($_SESSION['shipsPositions']); | |||
// Als de functie gemaakt is, in board... |
@@ -1,5 +1,6 @@ | |||
<?php | |||
// Ship class | |||
class Ships | |||
{ | |||
protected $length; | |||
@@ -25,32 +26,38 @@ class Ships | |||
} | |||
// Eerste positie van ship | |||
protected function calcposBegin() | |||
{ | |||
$this->posBegin = $this->posMidden - floor($this->length / 2); | |||
} | |||
// Laatste positie van ship | |||
protected function calcposEind() | |||
{ | |||
$this->posEind = $this->posBegin + $this->length - 2; | |||
} | |||
// Begin van ship wordt berekend adhv het midden, wat een random getal is tussen 4 en 47 | |||
public function calcposMidden() | |||
{ | |||
$this->posMidden = rand(4, 47); | |||
} | |||
// Opvragen van eerste positie van ship | |||
public function returnPosBegin() | |||
{ | |||
return $this->posBegin; | |||
} | |||
// Opvragen van laatste positie van ship | |||
public function returnPosEind() | |||
{ | |||
return $this->posEind; | |||
} | |||
// | |||
protected function initPosArr() | |||
{ | |||
for ($i = $this->posBegin; $i <= $this->posEind; $i++) { | |||
@@ -58,11 +65,6 @@ class Ships | |||
} | |||
} | |||
//aanpassen!! | |||
public function ammo() | |||
{ | |||
return $this->ammo = $this->length; | |||
} | |||
public function posArr() | |||
@@ -90,7 +92,6 @@ class vliegdekSchip extends Ships | |||
$this->calcposBegin(); | |||
$this->calcposEind(); | |||
$this->initPosArr(); | |||
//$this->ammo = $this-length + 4; | |||
$this->shipName = "Vliegdekship"; | |||
} | |||