@@ -109,7 +109,7 @@ if (isset($_POST['btnShot'])) { | |||
// Als ammo op is -> game over en game reset | |||
if ($_SESSION['ammo'] === 0) { | |||
echo "Game Over, try again"; | |||
echo "Game Over, your score is 0"; | |||
assignShips($_SESSION['difficulty']); | |||
unset($_SESSION['shots']); | |||
} | |||
@@ -127,6 +127,23 @@ if (isset($_POST['btnShot'])) { | |||
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']); |
@@ -0,0 +1,47 @@ | |||
<?php | |||
// Saving score. Score is verhouding van remaining ammo tov initieel ammo. | |||
// Vast gelopen, game draait goed, niet meer gelukt om werkend scoreboard te maken | |||
session_start(); | |||
if ($_SESSION['difficulty'] == 'Easy'){ | |||
$db = new SQLite3 ("scores.db"); | |||
$username = $_POST['username']; | |||
$score = ($_POST['ammo'] / 30) * 100; | |||
$stmt = $db->prepare("INSERT INTO scores (username, score) VALUES (:usrn, :scr)"); | |||
$stmt->bindValue(":usrn", $username, SQLITE3_TEXT); | |||
$stmt->bindValue(":scr", $email, SQLITE3_TEXT); | |||
$stmt->execute(); | |||
} | |||
if ($_SESSION['difficulty'] == 'Normal'){ | |||
$db = new SQLite3 ("scores.db"); | |||
$username = $_POST['username']; | |||
$score = ($_POST['ammo'] / 24) * 100; | |||
$stmt = $db->prepare("INSERT INTO scores (username, score) VALUES (:usrn, :scr)"); | |||
$stmt->bindValue(":usrn", $username, SQLITE3_TEXT); | |||
$stmt->bindValue(":scr", $email, SQLITE3_TEXT); | |||
$stmt->execute(); | |||
} | |||
if ($_SESSION['difficulty'] == 'Hard'){ | |||
$db = new SQLite3 ("scores.db"); | |||
$username = $_POST['username']; | |||
$score = ($_POST['ammo'] / 16) * 100; | |||
$stmt = $db->prepare("INSERT INTO scores (username, score) VALUES (:usrn, :scr)"); | |||
$stmt->bindValue(":usrn", $username, SQLITE3_TEXT); | |||
$stmt->bindValue(":scr", $email, SQLITE3_TEXT); | |||
$stmt->execute(); | |||
} | |||
?> |
@@ -1,7 +1,25 @@ | |||
<?php | |||
// Scoreboard | |||
class ScoreDB extends SQLite3{ | |||
function __construct() | |||
{ | |||
$this->open('scores.db'); | |||
} | |||
function save_scores($score){ | |||
$this->exec("INSERT INTO scores (score) VALUES (" . $score . ")"); | |||
} | |||
function get_scores() | |||
{ | |||
$scores = $this->query('SELECT * FROM scores'); | |||
} | |||
} | |||
?> |