@@ -0,0 +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": 9003 | |||
}, | |||
{ | |||
"name": "Launch currently open script", | |||
"type": "php", | |||
"request": "launch", | |||
"program": "${file}", | |||
"cwd": "${fileDirname}", | |||
"port": 9003 | |||
} | |||
] | |||
} |
@@ -43,6 +43,4 @@ class db | |||
return $res; | |||
} | |||
} | |||
$db = new db; | |||
?> | |||
$db = new db; |
@@ -1,17 +1,18 @@ | |||
<?php | |||
require_once "dbase.php"; | |||
<?php | |||
require_once "dbase.inc"; | |||
function checkLogin($usrName, $password){ | |||
function checkLogin($usrName, $password) | |||
{ | |||
unset($_SESSION['mess']); | |||
global $db; | |||
$login = $db->checkLogin($usrName, $password); | |||
if($login){ | |||
if ($login) { | |||
$_SESSION['usr_id'] = $login['usr_id']; | |||
$_SESSION['usr_name'] = $login['usr_name']; | |||
$_SESSION['cur_session_time'] = time(); | |||
unset($_SESSION['err_mess']); | |||
}else { | |||
} else { | |||
unset($_SESSION['usr_id']); | |||
unset($_SESSION['usr_name']); | |||
unset($_SESSION['mess']); | |||
@@ -21,48 +22,51 @@ function checkLogin($usrName, $password){ | |||
return; | |||
} | |||
function registerUser($usrName, $password, $cPassword){ | |||
function registerUser($usrName, $password, $cPassword) | |||
{ | |||
global $db; | |||
if($password === $cPassword){ | |||
if ($password === $cPassword) { | |||
unset($_SESSION['err_mess']); | |||
$register = $db->registerUser($usrName, $password); | |||
if($register){ | |||
if ($register) { | |||
printMessage("Signed up succesfully", "success"); | |||
// $_SESSION['mess'] = "<span class='success'>Signed up succesfully</span>"; | |||
header('location: index.php'); | |||
}else { | |||
} else { | |||
printMessage("Username already exists", "alert"); | |||
// $_SESSION['err_mess'] = "<span class='alert'>Username already exists</span>"; | |||
} | |||
}else { | |||
} else { | |||
printMessage("Passwords do not match!", "alert"); | |||
// $_SESSION['mess'] = "<span class='alert'>Passwords do not match!</span>"; | |||
} | |||
} | |||
function printMessage($message, $type){ | |||
function printMessage($message, $type) | |||
{ | |||
unset($_SESSION['mess']); | |||
unset($_SESSION['err_mess']); | |||
if ($type === "success"){ | |||
if ($type === "success") { | |||
$message = "<span class='success'>" . $message . "</span>"; | |||
} elseif($type === "alert"){ | |||
} elseif ($type === "alert") { | |||
$message = "<span class='alert'>" . $message . "</span>"; | |||
}else{ | |||
$message = "<span>" . $message . "</span>"; | |||
} else { | |||
$message = "<span>" . $message . "</span>"; | |||
} | |||
$_SESSION['mess'] = $message; | |||
} | |||
function checkSession(){ | |||
function checkSession() | |||
{ | |||
$now = time(); | |||
$delta = $now - $_SESSION['cur_session_time']; | |||
$timeSpan = 30*60; | |||
$timeSpan = 30 * 60; | |||
// $timeSpan = 10; //debug mode | |||
if($delta <= $timeSpan){ | |||
if ($delta <= $timeSpan) { | |||
$_SESSION['cur_session_time'] = $now; | |||
}else { | |||
} else { | |||
// unset maakt het leeg | |||
header('Location: index.php'); | |||
session_unset(); | |||
@@ -75,31 +79,29 @@ function checkSession(){ | |||
} | |||
} | |||
function printShotMessage($usrShot, $arr, $index){ | |||
function printShotMessage($usrShot, $arr, $index) | |||
{ | |||
// hitOrMis if hit the shot will be deleted from original arr | |||
if($arr->hitOrMis($usrShot)){ | |||
if ($arr->hitOrMis($usrShot)) { | |||
$_SESSION['gameMessage'][$index] = "Hit!"; | |||
$fullArr = $arr->getLocArrUntouched(); | |||
$key = array_search($usrShot,$fullArr); | |||
$key = array_search($usrShot, $fullArr); | |||
if($usrShot == $fullArr[0]){ | |||
if ($usrShot == $fullArr[0]) { | |||
$_SESSION['hits'][$index][$key] = "<"; | |||
} elseif($usrShot == $fullArr[count($fullArr) -1]){ | |||
} elseif ($usrShot == $fullArr[count($fullArr) - 1]) { | |||
$_SESSION['hits'][$index][$key] = ">"; | |||
}else { | |||
} else { | |||
$_SESSION['hits'][$index][$key] = "X"; | |||
} | |||
}else{ | |||
} else { | |||
$_SESSION['gameMessage'][$index] = "Missed!"; | |||
} | |||
if(empty($arr->getLocArr())){ | |||
if (empty($arr->getLocArr())) { | |||
$_SESSION['gameMessage'][$index] = $_SESSION['curShips'][$index]->getName() . " destroyed!"; | |||
} | |||
} | |||
// FIXME: | |||
// function getCurSymbol($usrShot, $arr){ | |||
@@ -118,40 +120,40 @@ function printShotMessage($usrShot, $arr, $index){ | |||
// } | |||
// } | |||
function randomGenerator($min, $max, $amount){ | |||
function randomGenerator($min, $max, $amount) | |||
{ | |||
$numbers = range($min, $max); | |||
shuffle($numbers); | |||
return array_slice($numbers, 0, $amount); | |||
} | |||
function generateShips(){ | |||
function generateShips() | |||
{ | |||
$ships = []; | |||
// unset($_SESSION['curShips']); | |||
//Lengte in classe steken | |||
$ships[0] = new Sub(); | |||
$ships[1] = new Destroyer(); | |||
$ships[2] = new Cruiser(); | |||
$ships[3] = new BattleShip(); | |||
$ships[4] = new AircraftCarrier(); | |||
$currentShips = []; | |||
// var_dump($arrRandomNumber); | |||
if(!isset($_SESSION['curShips'])){ | |||
$arrRandomNumber = randomGenerator(0,4,2); | |||
if (!isset($_SESSION['curShips'])) { | |||
$arrRandomNumber = randomGenerator(0, 4, 2); | |||
// FIXME: Make sure random number does not repeat; | |||
for($i = 0; $i<2; $i++){ | |||
for ($i = 0; $i < 2; $i++) { | |||
// $randomShip = rand(0,4); | |||
// $currentShips[$i] = $ships[$randomShip]; | |||
$currentShips[$i] = $ships[$arrRandomNumber[$i]]; | |||
} | |||
$_SESSION['curShips'] = $currentShips; | |||
} | |||
} | |||
?> | |||
} |
@@ -1,5 +1,5 @@ | |||
<?php | |||
session_start(); | |||
<?php | |||
session_start(); | |||
?> | |||
<html> | |||
@@ -21,26 +21,26 @@ | |||
<div class="header__logo"> | |||
<a href="./index.php"><img src="./files/img/logo.png"></a> | |||
<span class="header__name"> | |||
<?php | |||
if(isset($_SESSION['usr_name'])){ | |||
echo "Welcome back, {$_SESSION["usr_name"]}!"; | |||
} | |||
?> | |||
<?php | |||
if (isset($_SESSION['usr_name'])) { | |||
echo "Welcome back, {$_SESSION["usr_name"]}!"; | |||
} | |||
?> | |||
</span> | |||
</div> | |||
<nav class="header__nav main-nav"> | |||
<?php | |||
<?php | |||
// TODO: BEST PRACTICE vragen aan Ruben | |||
if(!strpos($_SERVER['REQUEST_URI'], 'naval_battle')){ | |||
if( basename("../index.php") == "index.php" && !strpos($_SERVER['REQUEST_URI'], 'signup') && !strpos($_SERVER['REQUEST_URI'], 'scores')){ | |||
if (!strpos($_SERVER['REQUEST_URI'], 'naval_battle')) { | |||
if (basename("../index.php") == "index.php" && !strpos($_SERVER['REQUEST_URI'], 'signup') && !strpos($_SERVER['REQUEST_URI'], 'scores')) { | |||
echo '<a class="main-nav__item" href="signup.php">Sing Up</a>'; | |||
} | |||
if(strpos($_SERVER['REQUEST_URI'], 'signup')){ | |||
if (strpos($_SERVER['REQUEST_URI'], 'signup')) { | |||
echo '<a class="main-nav__item" href="index.php">Log In</a>'; | |||
} | |||
} | |||
if(strpos($_SERVER['REQUEST_URI'], 'naval_battle')|| strpos($_SERVER['REQUEST_URI'], 'scores')){ | |||
if (strpos($_SERVER['REQUEST_URI'], 'naval_battle') || strpos($_SERVER['REQUEST_URI'], 'scores')) { | |||
echo '<a class="main-nav__item" href="naval_battle.php">Home</a> | |||
<a class="main-nav__item" href="scores.php">Scores</a> | |||
<a class="main-nav__item" href="index.php?logout=true">Log out</a>'; |
@@ -1,6 +1,7 @@ | |||
<?php | |||
<?php | |||
// TODO: Overlappen fixen! | |||
class Ship { | |||
class Ship | |||
{ | |||
protected $shipLength; | |||
protected $locStart; | |||
protected $locEnd; | |||
@@ -10,14 +11,15 @@ | |||
protected $name; | |||
protected $arrLocUntouched; | |||
// protected $arrSymbols; | |||
function __construct() | |||
{ | |||
$this->createShip(); | |||
} | |||
protected function createShip(){ | |||
protected function createShip() | |||
{ | |||
$this->calcLocMiddle(); | |||
$this->calcLocStart(); | |||
$this->calcLocEnd(); | |||
@@ -25,24 +27,27 @@ | |||
} | |||
protected function calcLocStart(){ | |||
protected function calcLocStart() | |||
{ | |||
$this->locStart = $this->locMiddle - floor($this->shipLength / 2); | |||
} | |||
protected function calcLocEnd(){ | |||
protected function calcLocEnd() | |||
{ | |||
$this->locEnd = $this->locStart + $this->shipLength - 1; | |||
} | |||
protected function calcLocMiddle(){ | |||
protected function calcLocMiddle() | |||
{ | |||
$this->locMiddle = rand(4, 46); | |||
} | |||
protected function createLocArr(){ | |||
for($i = $this->locStart; $i<=$this->locEnd; $i++){ | |||
protected function createLocArr() | |||
{ | |||
for ($i = $this->locStart; $i <= $this->locEnd; $i++) { | |||
//FIXME: Zoek betere methode | |||
$this->arrLoc[] = $i; | |||
$this->arrLocUntouched[] = $i; | |||
} | |||
// for($j = $this->locStart; $j<$this->locEnd; $j++){ | |||
// //FIXME: Zoek betere methode | |||
@@ -57,8 +62,9 @@ | |||
// } | |||
} | |||
public function getLocArr(){ | |||
return $this->arrLoc; | |||
public function getLocArr() | |||
{ | |||
return $this->arrLoc; | |||
} | |||
//FIXME: | |||
@@ -66,30 +72,34 @@ | |||
// return $this->arrSymbols; | |||
// } | |||
public function getLocArrUntouched(){ | |||
return $this->arrLocUntouched; | |||
public function getLocArrUntouched() | |||
{ | |||
return $this->arrLocUntouched; | |||
} | |||
public function hitOrMis($userShot){ | |||
public function hitOrMis($userShot) | |||
{ | |||
// if($userShot >= $this->locStart && $userShot <= $this->locEnd){ | |||
// return true; | |||
// } | |||
if(in_array($userShot, $this->arrLoc)){ | |||
$key = array_search($userShot,$this->arrLoc); | |||
if (in_array($userShot, $this->arrLoc)) { | |||
$key = array_search($userShot, $this->arrLoc); | |||
unset($this->arrLoc[$key]); | |||
return true; | |||
} | |||
return false; | |||
} | |||
} | |||
class Sub extends Ship { | |||
class Sub extends Ship | |||
{ | |||
protected function createShip(){ | |||
protected function createShip() | |||
{ | |||
$this->shipLength = 4; | |||
$this->calcLocMiddle(); | |||
$this->calcLocStart(); | |||
@@ -98,16 +108,17 @@ class Sub extends Ship { | |||
$this->name = "Submarine"; | |||
} | |||
public function getName(){ | |||
public function getName() | |||
{ | |||
return $this->name; | |||
} | |||
} | |||
// OF OP DEZE MANIER: | |||
class Destroyer extends Ship { | |||
class Destroyer extends Ship | |||
{ | |||
protected function createShip(){ | |||
protected function createShip() | |||
{ | |||
$this->shipLength = 5; | |||
$this->calcLocMiddle(); | |||
$this->calcLocStart(); | |||
@@ -116,13 +127,16 @@ class Destroyer extends Ship { | |||
$this->name = "Destroyer"; | |||
} | |||
public function getName(){ | |||
public function getName() | |||
{ | |||
return $this->name; | |||
} | |||
} | |||
class Cruiser extends Ship { | |||
protected function createShip(){ | |||
class Cruiser extends Ship | |||
{ | |||
protected function createShip() | |||
{ | |||
$this->shipLength = 6; | |||
$this->calcLocMiddle(); | |||
$this->calcLocStart(); | |||
@@ -131,14 +145,16 @@ class Cruiser extends Ship { | |||
$this->name = "Cruiser"; | |||
} | |||
public function getName(){ | |||
public function getName() | |||
{ | |||
return $this->name; | |||
} | |||
} | |||
class BattleShip extends Ship { | |||
protected function createShip(){ | |||
class BattleShip extends Ship | |||
{ | |||
protected function createShip() | |||
{ | |||
$this->shipLength = 7; | |||
$this->calcLocMiddle(); | |||
$this->calcLocStart(); | |||
@@ -147,13 +163,16 @@ class BattleShip extends Ship { | |||
$this->name = "Battleship"; | |||
} | |||
public function getName(){ | |||
public function getName() | |||
{ | |||
return $this->name; | |||
} | |||
} | |||
class AircraftCarrier extends Ship{ | |||
protected function createShip(){ | |||
class AircraftCarrier extends Ship | |||
{ | |||
protected function createShip() | |||
{ | |||
$this->shipLength = 8; | |||
$this->calcLocMiddle(); | |||
$this->calcLocStart(); | |||
@@ -162,8 +181,8 @@ class AircraftCarrier extends Ship{ | |||
$this->name = "Aircraft Carrier"; | |||
} | |||
public function getName(){ | |||
public function getName() | |||
{ | |||
return $this->name; | |||
} | |||
} | |||
?> | |||
} |
@@ -1,20 +1,20 @@ | |||
<?php | |||
if($_GET['logout']){ | |||
unset($_SESSION['usr_id']); | |||
unset($_SESSION['usr_name']); | |||
unset($_SESSION['mess']); | |||
unset($_SESSION['err_mess']); | |||
unset($_SESSION['gameMessage']); | |||
// session_destroy(): Trying to destroy uninitialized session | |||
// vandaar session_start(); | |||
session_start(); | |||
session_destroy(); | |||
} | |||
// SESSION STARTS IN includes/head.php | |||
require_once 'includes/dbase.php'; | |||
include 'includes/functions.php'; | |||
include 'includes/head.php'; | |||
<?php | |||
if ($_GET['logout']) { | |||
unset($_SESSION['usr_id']); | |||
unset($_SESSION['usr_name']); | |||
unset($_SESSION['mess']); | |||
unset($_SESSION['err_mess']); | |||
unset($_SESSION['gameMessage']); | |||
// session_destroy(): Trying to destroy uninitialized session | |||
// vandaar session_start(); | |||
session_start(); | |||
session_destroy(); | |||
} | |||
// SESSION STARTS IN includes/head.php | |||
require_once 'includes/dbase.inc'; | |||
include 'includes/functions.inc'; | |||
include 'includes/head.inc'; | |||
?> | |||
@@ -23,11 +23,13 @@ | |||
<form action="./index.php" method="POST" class="content__form form"> | |||
<label class="form__label" for="usr-name">Username</label> | |||
<input class="form__input" type="text" name="usr-name" id="usr-name" required autofocus | |||
value="<?php if(isset($_POST['usr-name'])){ echo $_POST['usr-name'];} ?>"> | |||
<input class="form__input" type="text" name="usr-name" id="usr-name" required autofocus value="<?php if (isset($_POST['usr-name'])) { | |||
echo $_POST['usr-name']; | |||
} ?>"> | |||
<label class="form__label" for="password">Password </label> | |||
<input class="form__input" type="password" name="password" id="password" required | |||
value="<?php if(isset($_POST['password'])){ echo $_POST['password'];} ?>"> | |||
<input class="form__input" type="password" name="password" id="password" required value="<?php if (isset($_POST['password'])) { | |||
echo $_POST['password']; | |||
} ?>"> | |||
<input class="form__input" type="submit" value="Log In" name="btn-login"> | |||
</form> | |||
@@ -36,30 +38,30 @@ | |||
<div class="main__content message"> | |||
<?php | |||
<?php | |||
// FIXME:Wanneer een nieuw user is aangemaakt en dan foutief inloggen -> message session not updated | |||
// Voor de signup. | |||
if(isset($_SESSION['mess'])){ | |||
echo $_SESSION['mess']; | |||
} | |||
if(isset($_POST['btn-login'])){ | |||
unset($_SESSION['mess']); | |||
checkLogin($_POST['usr-name'],$_POST['password']); | |||
if(isset($_SESSION['usr_id'])){ | |||
header('location: naval_battle.php'); | |||
//stop het script | |||
exit(); | |||
} | |||
if(isset($_SESSION['err_mess'])){ | |||
unset($_SESSION['mess']); | |||
echo $_SESSION['err_mess']; | |||
} | |||
} | |||
// Voor de signup. | |||
if (isset($_SESSION['mess'])) { | |||
echo $_SESSION['mess']; | |||
} | |||
if (isset($_POST['btn-login'])) { | |||
unset($_SESSION['mess']); | |||
checkLogin($_POST['usr-name'], $_POST['password']); | |||
if (isset($_SESSION['usr_id'])) { | |||
header('location: naval_battle.php'); | |||
//stop het script | |||
exit(); | |||
} | |||
?> | |||
if (isset($_SESSION['err_mess'])) { | |||
unset($_SESSION['mess']); | |||
echo $_SESSION['err_mess']; | |||
} | |||
} | |||
?> | |||
</div> | |||
<div class="main__content content"> | |||
@@ -71,16 +73,16 @@ | |||
</tr> | |||
<?php | |||
$arr = $db->spoofDbTemporarily(); | |||
while($row = $arr->fetchArray(SQLITE3_ASSOC)){ | |||
echo '<tr><td>' . $row['usr_name'] .'</td><td>'. $row['password'] . "</td></tr>"; | |||
} | |||
?> | |||
$arr = $db->spoofDbTemporarily(); | |||
while ($row = $arr->fetchArray(SQLITE3_ASSOC)) { | |||
echo '<tr><td>' . $row['usr_name'] . '</td><td>' . $row['password'] . "</td></tr>"; | |||
} | |||
?> | |||
</table> | |||
</center> | |||
</div> | |||
<?php | |||
include 'includes/foot.php'; | |||
?> | |||
include 'includes/foot.inc'; | |||
?> |
@@ -1,34 +1,34 @@ | |||
<?php | |||
require_once 'includes/dbase.php'; | |||
include 'includes/functions.php'; | |||
include 'includes/ships.php'; | |||
<?php | |||
require_once 'includes/dbase.inc'; | |||
include 'includes/functions.inc'; | |||
include 'includes/ships.inc'; | |||
// session_start(); | |||
// Session wordt gestart in include (TODO:Best practice aan ruben vrange) | |||
include "includes/head.php"; | |||
if(!isset($_SESSION['gameState'])){ | |||
include "includes/head.inc"; | |||
if (!isset($_SESSION['gameState'])) { | |||
$_SESSION['gameState'] = false; | |||
} | |||
if(isset($_POST['startGame'])){ | |||
} | |||
if (isset($_POST['startGame'])) { | |||
$_SESSION['gameState'] = true; | |||
} | |||
// FIXME: Make page more dynamic, be able to choose how many ships? | |||
// TODO: Vraagje voor ruben -> Werken op 2 branches tegelijk? Hoe best practice? | |||
generateShips(); | |||
if(isset($_POST['shoot'])){ | |||
checkSession(); | |||
if (isset($_POST['shoot'])) { | |||
checkSession(); | |||
$_SESSION['shots'][] = $_POST['usrShot']; | |||
// TODO: add game state-> maybe start button? etc… | |||
for($i = 0; $i < count($_SESSION['curShips']); $i++){ | |||
printShotMessage($_POST['usrShot'], $_SESSION['curShips'][$i], $i); | |||
for ($i = 0; $i < count($_SESSION['curShips']); $i++) { | |||
printShotMessage($_POST['usrShot'], $_SESSION['curShips'][$i], $i); | |||
} | |||
if(empty($_SESSION['curShips'][0]->getLocArr()) && empty($_SESSION['curShips'][1]->getLocArr()) ){ | |||
if (empty($_SESSION['curShips'][0]->getLocArr()) && empty($_SESSION['curShips'][1]->getLocArr())) { | |||
$_SESSION['gameState'] = false; | |||
unset($_SESSION['curShips']); | |||
unset($_SESSION['shots']); | |||
@@ -36,139 +36,143 @@ | |||
} | |||
} | |||
?> | |||
?> | |||
<!-- valid?? --> | |||
<fieldset class="main__content content"> | |||
<legend> | |||
<?php if($_SESSION['gameState'] === false){ echo "Do you dare?";}else { echo "Choose location";} ?> | |||
<?php if ($_SESSION['gameState'] === false) { | |||
echo "Do you dare?"; | |||
} else { | |||
echo "Choose location"; | |||
} ?> | |||
</legend> | |||
<form action="naval_battle.php" method="POST" class="content-item form"> | |||
<?php | |||
if($_SESSION['gameState'] === false){ | |||
if ($_SESSION['gameState'] === false) { | |||
?> | |||
<input class="form__input" type="submit" name="startGame" value="Start Game!"> | |||
<?php | |||
}else { | |||
?> | |||
} else { | |||
?> | |||
<input class="form__input" name="usrShot" id="usr-shot" type="number" max="50" min="1" autofocus required> | |||
<input class="form__input" type="submit" name="shoot" value="Shoot!"> | |||
<?php }?> | |||
<?php } ?> | |||
</form> | |||
</fieldset> | |||
<!-- //TODO: Een startknop maken en van daaruit de game state starten. Deze terug tonen wanneer spel geindigd is | |||
--> | |||
<?php | |||
<?php | |||
// if($_SESSION['gameState'] === true){ | |||
?> | |||
?> | |||
<div class="main__content content"> | |||
<div class="content__container"> | |||
<span class="content-item"> | |||
<span class="content-item__title"> <?= $_SESSION['curShips'][0]->getName() ?></span> | |||
<span class="content-item__mess"> | |||
<?php | |||
if(isset($_POST['shoot'])){ | |||
if (isset($_POST['shoot'])) { | |||
echo $_SESSION['gameMessage'][0]; | |||
} | |||
?> | |||
} | |||
?> | |||
</span> | |||
</span> | |||
<span class="content-item"> | |||
<span class="content-item__title"> <?= $_SESSION['curShips'][1]->getName() ?></span> | |||
<span class="content-item__mess"> | |||
<?php | |||
if(isset($_POST['shoot'])){ | |||
if (isset($_POST['shoot'])) { | |||
echo $_SESSION['gameMessage'][1]; | |||
} | |||
?> | |||
} | |||
?> | |||
</span> | |||
</span> | |||
</div> | |||
</div> | |||
<div class="main__content content"> | |||
<table> | |||
<pre><?php | |||
for($i = 0; $i < 5; $i++){ | |||
<pre><?php | |||
for ($i = 0; $i < 5; $i++) { | |||
echo "<tr>"; | |||
for($j = 0; $j <10; $j++){ | |||
for ($j = 0; $j < 10; $j++) { | |||
$tdLoc = intval($i . $j) + 1; | |||
echo "<td id='". $tdLoc ."'>"; | |||
echo "<span class='td_number'>". $tdLoc. "</span>"; | |||
if($_SESSION['gameState'] === true){ | |||
if(isset($_POST['shoot'])){ | |||
echo "<td id='" . $tdLoc . "'>"; | |||
echo "<span class='td_number'>" . $tdLoc . "</span>"; | |||
if ($_SESSION['gameState'] === true) { | |||
if (isset($_POST['shoot'])) { | |||
// echo "test"; | |||
// if(isset($_SESSION['shots'])){ | |||
if(in_array($tdLoc, $_SESSION['shots'])){ | |||
// FIXME: Aan ruben vragen!! | |||
// for($i = 0; $i < count($_SESSION['curShips']); $i++){ | |||
// if(in_array($tdLoc, $_SESSION['curShips'][$i]->getLocArrUntouched())) { | |||
// if($tdLoc == $_SESSION['curShips'][$i]->getLocArrUntouched()[0]){ | |||
// echo "<"; | |||
// }elseif ($tdLoc == $_SESSION['curShips'][0]->getLocArrUntouched()[count($_SESSION['curShips'][0]->getLocArrUntouched()) -1]){ | |||
// echo ">"; | |||
// }else { | |||
// echo "X"; | |||
// } | |||
// }else { | |||
// // TODO:Methode vinden om een < XXX > te kunnen schrijven | |||
// echo "O"; | |||
// } | |||
// } | |||
// TODO:Create print function-> if hit print X if front hit print < if missed print O; | |||
if(in_array($tdLoc, $_SESSION['curShips'][0]->getLocArrUntouched()) | |||
|| in_array($tdLoc, $_SESSION['curShips'][1]->getLocArrUntouched())){ | |||
if($tdLoc == $_SESSION['curShips'][0]->getLocArrUntouched()[0] || $tdLoc == $_SESSION['curShips'][1]->getLocArrUntouched()[0]){ | |||
echo "<"; | |||
}elseif ($tdLoc == $_SESSION['curShips'][0]->getLocArrUntouched()[count($_SESSION['curShips'][0]->getLocArrUntouched()) -1] | |||
|| $tdLoc == $_SESSION['curShips'][1]->getLocArrUntouched()[count($_SESSION['curShips'][1]->getLocArrUntouched()) -1]){ | |||
echo ">"; | |||
}else { | |||
echo "X"; | |||
} | |||
}else { | |||
echo "O"; | |||
if (in_array($tdLoc, $_SESSION['shots'])) { | |||
// FIXME: Aan ruben vragen!! | |||
// for($i = 0; $i < count($_SESSION['curShips']); $i++){ | |||
// if(in_array($tdLoc, $_SESSION['curShips'][$i]->getLocArrUntouched())) { | |||
// if($tdLoc == $_SESSION['curShips'][$i]->getLocArrUntouched()[0]){ | |||
// echo "<"; | |||
// }elseif ($tdLoc == $_SESSION['curShips'][0]->getLocArrUntouched()[count($_SESSION['curShips'][0]->getLocArrUntouched()) -1]){ | |||
// echo ">"; | |||
// }else { | |||
// echo "X"; | |||
// } | |||
// }else { | |||
// // TODO:Methode vinden om een < XXX > te kunnen schrijven | |||
// echo "O"; | |||
// } | |||
// } | |||
// TODO:Create print function-> if hit print X if front hit print < if missed print O; | |||
if ( | |||
in_array($tdLoc, $_SESSION['curShips'][0]->getLocArrUntouched()) | |||
|| in_array($tdLoc, $_SESSION['curShips'][1]->getLocArrUntouched()) | |||
) { | |||
if ($tdLoc == $_SESSION['curShips'][0]->getLocArrUntouched()[0] || $tdLoc == $_SESSION['curShips'][1]->getLocArrUntouched()[0]) { | |||
echo "<"; | |||
} elseif ( | |||
$tdLoc == $_SESSION['curShips'][0]->getLocArrUntouched()[count($_SESSION['curShips'][0]->getLocArrUntouched()) - 1] | |||
|| $tdLoc == $_SESSION['curShips'][1]->getLocArrUntouched()[count($_SESSION['curShips'][1]->getLocArrUntouched()) - 1] | |||
) { | |||
echo ">"; | |||
} else { | |||
echo "X"; | |||
} | |||
} else { | |||
echo "O"; | |||
} | |||
// } | |||
} | |||
} | |||
}else { | |||
echo " "; | |||
} | |||
echo "</td>"; | |||
} else { | |||
echo " "; | |||
} | |||
echo "</td>"; | |||
} | |||
echo "</tr>"; | |||
} | |||
?></pre> | |||
?></pre> | |||
</table> | |||
</div> | |||
</div> | |||
<?php | |||
// } | |||
?> | |||
<?php | |||
$_SESSION['loc'][0] = $_SESSION['curShips'][0]->getLocArrUntouched(); | |||
$_SESSION['loc'][2] = $_SESSION['curShips'][1]->getLocArrUntouched(); | |||
// var_dump($_SESSION['loc']); | |||
var_dump($_SESSION['curShips'][0]->getLocArr()); | |||
var_dump($_SESSION['curShips'][1]->getLocArr()); | |||
// session_destroy(); | |||
// var_dump( $_SESSION['hits']); | |||
include "includes/foot.php"; | |||
?> | |||
<?php | |||
// } | |||
?> | |||
<?php | |||
$_SESSION['loc'][0] = $_SESSION['curShips'][0]->getLocArrUntouched(); | |||
$_SESSION['loc'][2] = $_SESSION['curShips'][1]->getLocArrUntouched(); | |||
// var_dump($_SESSION['loc']); | |||
var_dump($_SESSION['curShips'][0]->getLocArr()); | |||
var_dump($_SESSION['curShips'][1]->getLocArr()); | |||
// session_destroy(); | |||
// var_dump( $_SESSION['hits']); | |||
include "includes/foot.inc"; | |||
?> |
@@ -1,5 +1,5 @@ | |||
<?php | |||
include "includes/head.php"; | |||
<?php | |||
include "includes/head.inc"; | |||
?> | |||
<div class="main__content"> | |||
<table> | |||
@@ -14,6 +14,6 @@ | |||
</div> | |||
<?php | |||
include "includes/foot.php"; | |||
<?php | |||
include "includes/foot.inc"; | |||
?> |