Kaynağa Gözat

Score_display

master
rvaken 3 yıl önce
ebeveyn
işleme
79f209d3f5
5 değiştirilmiş dosya ile 83 ekleme ve 1 silme
  1. 18
    1
      game.php
  2. BIN
      registration.db
  3. 47
    0
      savescores.php
  4. 0
    0
      scores.db
  5. 18
    0
      scores.php

+ 18
- 1
game.php Dosyayı Görüntüle

@@ -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']);

BIN
registration.db Dosyayı Görüntüle


+ 47
- 0
savescores.php Dosyayı Görüntüle

@@ -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();
}



?>

+ 0
- 0
scores.db Dosyayı Görüntüle


+ 18
- 0
scores.php Dosyayı Görüntüle

@@ -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');

}


}

?>

Loading…
İptal
Kaydet