Initial commit

This commit is contained in:
Stefan Ritter 2012-03-13 11:36:26 +01:00
commit 600316a94a
86 changed files with 10167 additions and 0 deletions

2
.htaccess Normal file
View file

@ -0,0 +1,2 @@
DirectoryIndex index.php
Options +FollowSymLinks

133
controllers/content.php Normal file
View file

@ -0,0 +1,133 @@
<?php include(SITE_ROOT . "/include/" . "config.inc.php"); ?>
<div id="wrapper">
<?php
/*
* Let's check our database connection
*/
require_once(SITE_ROOT . "/models/" . "database.php");
$database = new Database();
$db = $database->connect();
if (!$db == 0) {
echo "BJack is not fully installed, please run install.php!";
} else {
$page = $_SERVER["QUERY_STRING"];
if (!$page || $page == "menu") {
/*
* Here comes the front page
*/
include(SITE_ROOT . "/templates/" . "menu.tpl.php");
} else if ($page == "login") {
/*
* User, password, ...
*/
session_start();
if(isset($_SESSION["user"])) {
include(SITE_ROOT . "/templates/" . "game.tpl.php");
} else {
include(SITE_ROOT . "/templates/" . "login.tpl.php");
}
} else if ($page == "logout") {
/*
* Destroy session
*/
require_once(SITE_ROOT . "/models/" . "bjack.php");
$bjack = new BJack();
$bjack->destroySession();
include(SITE_ROOT . "/templates/" . "logout.tpl.php");
} else if ($page == "game") {
/*
* Game
*/
/* Validate data */
$user = $_POST["user"];
$pass = $_POST["pass"];
if ($user == "name" || $user == "" || $pass == "password" || $pass == "") {
include(SITE_ROOT . "/templates/" . "invalid.tpl.php");
} else {
/*
* Data is valid
* - check database for existing user
* - create new user
*/
require_once(SITE_ROOT . "/models/" . "database.php");
$database = new Database();
$checkuser = $database->checkUser($user, $pass);
if ($checkuser == 2 || $checkuser == 0) {
/* Create shuffled deck and store everything into session */
session_start();
if (!isset($_SESSION["num"])) {
require_once(SITE_ROOT . "/models/" . "bjack.php");
$bjack = new BJack();
$deck = $bjack->generateShuffledDeck();
$_SESSION["deck"] = $deck;
$_SESSION["num"] = 0;
$_SESSION["score"] = 0;
}
$_SESSION["user"] = $user;
include(SITE_ROOT . "/templates/" . "game.tpl.php");
} else {
include(SITE_ROOT . "/templates/" . "invalid.tpl.php");
}
}
} else if ($page == "impressum") {
/*
* Impressum
*/
include(SITE_ROOT . "/templates/" . "impressum.tpl.php");
} else if ($page == "highscores") {
/*
* Highscores
*/
include(SITE_ROOT . "/templates/" . "highscores.tpl.php");
} else {
/*
* 404
*/
include(SITE_ROOT . "/templates/" . "404.tpl.php");
}
}
?>
</div>

64
css/default.css Normal file
View file

@ -0,0 +1,64 @@
* {
margin: 0px;
padding: 0px;
}
body {
background: url(../images/background.jpg);
font-family: "Open Sans";
font-size: 10pt;
}
ok {
font-weight: bold;
color: #0f0;
}
fail {
font-weight: bold;
color: #f00;
}
img {
border: 0px;
}
#wrapper {
width: 960px;
height: 600px;
position: absolute;
top: 50%;
left: 50%;
margin-top: -300px;
margin-left: -480px;
background: #fff;
border-radius: 10px;
box-shadow: 5px 5px 10px #000;
text-align: center;
}
#menu {
/* Cards are 72x96 pixels */
width: 276px;
height: 120px;
position: absolute;
top: 50%;
left: 50%;
margin-top: -60px;
margin-left: -138px;
text-align: center;
}
#menu img {
margin: 0px 10px 0px 10px;
}
#menu img:hover {
box-shadow: 3px 3px 0px #000;
}
#menu p {
width: 92px;
float: left;
text-align: center;
}

BIN
images/background.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

BIN
images/cards/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 440 B

BIN
images/cards/10.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

BIN
images/cards/11.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

BIN
images/cards/12.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB

BIN
images/cards/13.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

BIN
images/cards/14.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB

BIN
images/cards/15.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB

BIN
images/cards/16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB

BIN
images/cards/17.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 623 B

BIN
images/cards/18.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 596 B

BIN
images/cards/19.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

BIN
images/cards/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 583 B

BIN
images/cards/20.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 554 B

BIN
images/cards/21.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 679 B

BIN
images/cards/22.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 608 B

BIN
images/cards/23.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 634 B

BIN
images/cards/24.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 533 B

BIN
images/cards/25.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 612 B

BIN
images/cards/26.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 618 B

BIN
images/cards/27.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 625 B

BIN
images/cards/28.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 525 B

BIN
images/cards/29.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 B

BIN
images/cards/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 453 B

BIN
images/cards/30.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 609 B

BIN
images/cards/31.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 606 B

BIN
images/cards/32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 513 B

BIN
images/cards/33.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 510 B

BIN
images/cards/34.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 520 B

BIN
images/cards/35.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 531 B

BIN
images/cards/36.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 463 B

BIN
images/cards/37.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 553 B

BIN
images/cards/38.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 558 B

BIN
images/cards/39.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 578 B

BIN
images/cards/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 388 B

BIN
images/cards/40.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 478 B

BIN
images/cards/41.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 474 B

BIN
images/cards/42.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 486 B

BIN
images/cards/43.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 494 B

BIN
images/cards/44.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 435 B

BIN
images/cards/45.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 505 B

BIN
images/cards/46.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 511 B

BIN
images/cards/47.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 508 B

BIN
images/cards/48.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 440 B

BIN
images/cards/49.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 457 B

BIN
images/cards/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB

BIN
images/cards/50.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 463 B

BIN
images/cards/51.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 474 B

BIN
images/cards/52.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 411 B

BIN
images/cards/53.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
images/cards/54.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
images/cards/6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB

BIN
images/cards/7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

BIN
images/cards/8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB

BIN
images/cards/9.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB

BIN
images/cards/b1fh.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B

BIN
images/cards/b1fv.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B

BIN
images/cards/b1pb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 196 B

BIN
images/cards/b1pl.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 B

BIN
images/cards/b1pr.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 197 B

BIN
images/cards/b1pt.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 B

BIN
images/cards/b2fh.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

BIN
images/cards/b2fv.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

BIN
images/cards/b2pb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 196 B

BIN
images/cards/b2pl.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 B

BIN
images/cards/b2pr.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 197 B

BIN
images/cards/b2pt.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 B

20
include/config.inc.php Normal file
View file

@ -0,0 +1,20 @@
<?php
/*
* General configuration
*/
$site_title = "BJack for #rautemusik (POC)";
$db_host = "localhost";
$db_name = "bjack";
$db_user = "bjack";
$db_pass = "bjack2";
/*
* Don't touch this
*/
$site_path = dirname(__FILE__);
$model_path = $site_path . "/models/";
?>

13
index.php Normal file
View file

@ -0,0 +1,13 @@
<?php define("SITE_ROOT", dirname(__FILE__)); ?>
<!DOCTYPE html>
<html lang="en">
<?php include(SITE_ROOT . "/templates/" . "head.tpl.php"); ?>
<body>
<?php include(SITE_ROOT . "/controllers/" . "content.php"); ?>
</body>
</html>

42
install.php Normal file
View file

@ -0,0 +1,42 @@
<?php define("SITE_ROOT", dirname(__FILE__)); ?>
<!DOCTYPE html>
<html>
<?php include(SITE_ROOT . "/templates/" . "head.tpl.php"); ?>
<body>
<div id="wrapper">
<h1>Database Setup</h1>
<?php
$host = $_POST["host"];
$rpassword = $_POST["rpassword"];
$name = $_POST["name"];
$user = $_POST["user"];
$password = $_POST["password"];
require_once(SITE_ROOT . "/models/" . "database.php");
$database = new Database();
$db = $database->connect();
if ($db == 0) {
echo "Installation already done!";
} else {
echo "<form action='install.php' method='post'>";
echo "Database host:<br /><input type='text' name='host' value='$host' /><br /><br />";
echo "Database root password:<br /><input type='text' name='rpassword' value='$rpassword' /><br /><br />";
echo "Database name:<br /><input type='text' name='name' value='$name' /><br /><br />";
echo "Database user:<br /><input type='text' name='user' value='$user' /><br /><br />";
echo "Database password:<br /><input type='text' name='password' value='$password' /><br /><br />";
echo "<input type='submit' value='Install' />";
echo "</form>";
}
?>
</div>
</body>
</html>

24
jquery/bjack.js vendored Normal file
View file

@ -0,0 +1,24 @@
$(document).ready(function() {
/*
* Clear values of name and password on click
*/
$("#name").click(function() {
if ($(this).val() == "name") {
$(this).removeAttr("value");
};
});
$("#pass").click(function() {
if ($(this).val() == "password") {
$(this).removeAttr("value");
$(this).prop({"type": "password"});
};
});
$("select").change(function() {
continue;
});
});

9266
jquery/jquery-1.7.1.js vendored Normal file

File diff suppressed because it is too large Load diff

258
models/bjack.php Normal file
View file

@ -0,0 +1,258 @@
<?php
class BJack {
function destroySession() {
/*
* Destroy the running session (logout)
*/
session_unset();
session_destroy();
session_write_close();
setcookie(session_name(), "", 0, '/');
session_regenerate_id(true);
}
function generateShuffledDeck() {
/*
* shuffle() uses rand() and should satifsy our needs
*/
$deck = range(1, 312);
shuffle($deck);
return $deck;
}
function calculateChance($deck, $num, $score) {
/*
* First let's see how many points are left to 21
*/
$pointsLeft = 21 - $score;
/*
* Now we have to find out how many cards in our rest deck can break our neck
*/
$cardsToLose = 0;
for ($i = $num; $i <= 312; $i++) {
$card = $this->getCardInfo($deck[$i]);
$cardValue = $card[0];
if ($cardValue > $pointsLeft) {
$cardsToLose++;
}
}
/*
* Now we now how many cards are left and how many of them can make us feel like a looser
*/
$cardsLeft = 312 - $num;
$chanceToLose = ($cardsToLose * 100) / $cardsLeft;
return $chanceToLose;
}
function sixDecksWorkaround($card) {
if ($card >= 53 && $card <= 104) {
$card = $card - 52;
} else if ($card >= 105 && $card <= 156) {
$card = $card - 104;
} else if ($card >= 157 && $card <= 208) {
$card = $card - 156;
} else if ($card >= 209 && $card <= 260) {
$card = $card - 208;
} else if ($card >= 261 && $card <= 312) {
$card = $card - 260;
}
return $card;
}
function getCardInfo($card) {
/*
* Information about our card
*
* Array [0] = Card points
* Array [1] = Card name
*/
$card = $this->sixDecksWorkaround($card);
$data = array();
if ($card == "1") {
$data[] = 1;
$data[] = "Ace of Clubs";
} else if ($card == "2") {
$data[] = 1;
$data[] = "Ace of Spades";
} else if ($card == "3") {
$data[] = 1;
$data[] = "Ace of Hearts";
} else if ($card == "4") {
$data[] = 1;
$data[] = "Ace of Diamonds";
} else if ($card == "5") {
$data[] = 10;
$data[] = "King of Clubs";
} else if ($card == "6") {
$data[] = 10;
$data[] = "King of Spades";
} else if ($card == "7") {
$data[] = 10;
$data[] = "King of Hearts";
} else if ($card == "8") {
$data[] = 10;
$data[] = "King of Diamonds";
} else if ($card == "9") {
$data[] = 10;
$data[] = "Queen of Clubs";
} else if ($card == "10") {
$data[] = 10;
$data[] = "Queen of Spades";
} else if ($card == "11") {
$data[] = 10;
$data[] = "Queen of Hearts";
} else if ($card == "12") {
$data[] = 10;
$data[] = "Queen of Diamonds";
} else if ($card == "13") {
$data[] = 10;
$data[] = "Jack of Clubs";
} else if ($card == "14") {
$data[] = 10;
$data[] = "Jack of Spades";
} else if ($card == "15") {
$data[] = 10;
$data[] = "Jack of Hearts";
} else if ($card == "16") {
$data[] = 10;
$data[] = "Jack of Diamonds";
} else if ($card == "17") {
$data[] = 10;
$data[] = "Ten of Clubs";
} else if ($card == "18") {
$data[] = 10;
$data[] = "Ten of Spades";
} else if ($card == "19") {
$data[] = 10;
$data[] = "Ten of Hearts";
} else if ($card == "20") {
$data[] = 10;
$data[] = "Ten of Diamonds";
} else if ($card == "21") {
$data[] = 9;
$data[] = "Nine of Clubs";
} else if ($card == "22") {
$data[] = 9;
$data[] = "Nine of Spades";
} else if ($card == "23") {
$data[] = 9;
$data[] = "Nine of Hearts";
} else if ($card == "24") {
$data[] = 9;
$data[] = "Nine of Diamonds";
} else if ($card == "25") {
$data[] = 8;
$data[] = "Eight of Clubs";
} else if ($card == "26") {
$data[] = 8;
$data[] = "Eight of Spades";
} else if ($card == "27") {
$data[] = 8;
$data[] = "Eight of Hearts";
} else if ($card == "28") {
$data[] = 8;
$data[] = "Eight of Diamonds";
} else if ($card == "29") {
$data[] = 7;
$data[] = "Seven of Clubs";
} else if ($card == "30") {
$data[] = 7;
$data[] = "Seven of Spades";
} else if ($card == "31") {
$data[] = 7;
$data[] = "Seven of Hearts";
} else if ($card == "32") {
$data[] = 7;
$data[] = "Seven of Diamonds";
} else if ($card == "33") {
$data[] = 6;
$data[] = "Six of Clubs";
} else if ($card == "34") {
$data[] = 6;
$data[] = "Six of Spades";
} else if ($card == "35") {
$data[] = 6;
$data[] = "Six of Hearts";
} else if ($card == "36") {
$data[] = 6;
$data[] = "Six of Diamonds";
} else if ($card == "37") {
$data[] = 5;
$data[] = "Five of Clubs";
} else if ($card == "38") {
$data[] = 5;
$data[] = "Five of Spades";
} else if ($card == "39") {
$data[] = 5;
$data[] = "Five of Hearts";
} else if ($card == "40") {
$data[] = 5;
$data[] = "Five of Diamonds";
} else if ($card == "41") {
$data[] = 4;
$data[] = "Four of Clubs";
} else if ($card == "42") {
$data[] = 4;
$data[] = "Four of Spades";
} else if ($card == "43") {
$data[] = 4;
$data[] = "Four of Hearts";
} else if ($card == "44") {
$data[] = 4;
$data[] = "Four of Diamonds";
} else if ($card == "45") {
$data[] = 3;
$data[] = "Three of Clubs";
} else if ($card == "46") {
$data[] = 4;
$data[] = "Three of Spades";
} else if ($card == "47") {
$data[] = 4;
$data[] = "Three of Hearts";
} else if ($card == "48") {
$data[] = 4;
$data[] = "Three of Diamonds";
} else if ($card == "49") {
$data[] = 2;
$data[] = "Two of Clubs";
} else if ($card == "50") {
$data[] = 2;
$data[] = "Two of Spades";
} else if ($card == "51") {
$data[] = 2;
$data[] = "Two of Hearts";
} else if ($card == "52") {
$data[] = 2;
$data[] = "Two of Diamonds";
} else {
$data[] = 0;
$data[] = "Unknown card";
}
return $data;
}
}

94
models/database.php Normal file
View file

@ -0,0 +1,94 @@
<?php
class Database {
function connect() {
include(SITE_ROOT . "/include/" . "config.inc.php");
$handler = mysql_connect($db_host, $db_user, $db_pass);
$db = mysql_select_db($db_name);
if ($db) {
return 0;
} else {
return 1;
}
}
function checkUser($user, $pass) {
$this->connect();
$query = "SELECT pass FROM users WHERE user='" . $user . "'";
$result = mysql_query($query);
$row = mysql_fetch_row($result);
/*
* User does not exists, create new one
*/
if (!$row) {
/*
* Create user
*/
$query = "INSERT INTO users(user, pass) VALUES ('" . $user . "', '" . md5($pass) . "')";
$result = mysql_query($query);
/*
* Create empty highscore row
*/
$query = "INSERT INTO highscores (user, score, gamesplayed) VALUES ('$user', 0, 0)";
$result = mysql_query($query);
/*
* New user created
*/
return 2;
} else {
/*
* If user exists check his password
* 0 = match, 1 = no match
*/
return strcmp($row[0], md5($pass));
}
}
function getHighscores() {
$data = array();
$handle = $this->connect();
$query = "SELECT * FROM highscores";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result)) {
$user = $row[1];
$score = $row[2];
$gamesplayed = $row[3];
$data[] = array($user, $score / $gamesplayed, $gamesplayed);
}
return $data;
}
function saveScore($user, $score) {
$this->connect();
if ($score > 21) $score = 0;
/*
* Save highscore to database
*/
$query = "UPDATE highscores SET score = score + $score, gamesplayed = gamesplayed + 1 WHERE user = '$user'";
$result = mysql_query($query);
}
}

2
templates/404.tpl.php Normal file
View file

@ -0,0 +1,2 @@
<h1>404</h1>
<p>Site not found...</p>

167
templates/game.tpl.php Normal file
View file

@ -0,0 +1,167 @@
<h1>New Game</h1>
<?php
session_start();
if ($checkuser == 0) {
echo "Hello " . $_SESSION['user'] . "!";
} else if ($checkuser == 1) {
echo "Wrong Password!";
return 0;
} else if ($checkuser == 2) {
echo "New user created! Hello " . $_SESSION['user'] . "!";
}
?>
<br /><br />
<?php
require_once(SITE_ROOT . "/models/" . "bjack.php");
$bjack = new BJack();
if ($_REQUEST["finish"]) {
/*
* Finish button pressed
*/
$num = $_SESSION["num"]; /* Which card */
$card = $_SESSION["deck"][$num]; /* ID of card */
$info = $bjack->getCardInfo($card);
$cardPicture = $bjack->sixDecksWorkaround($card); /* Filename of card picture */
echo "<img src='images/cards/$cardPicture.png' alt='card' title='$info[1]' /><br />";
$score = $_SESSION["score"]; /* Get score from session */
echo "You finished the game with score <b>$score</b>.<br /><br />";
echo "<a href='?login'>New game</a>";
/*
* Reset game data
*/
unset($_SESSION["num"]);
unset($_SESSION["score"]);
/*
* Save score to database
*/
require_once(SITE_ROOT . "/models/" . "database.php");
$database = new Database();
$database->saveScore($_SESSION["user"], $score);
/*
* Generate new deck and store it to session
*/
$deck = $bjack->generateShuffledDeck();
$_SESSION["deck"] = $deck;
} else {
$_SESSION["num"]++; /* Increase card counter */
$num = $_SESSION["num"];
$score = $_SESSION["score"];
$card = $_SESSION["deck"][$num];
$info = $bjack->getCardInfo($card);
$cardPicture = $bjack->sixDecksWorkaround($card);
/*
* Calculate new score
*/
$score += $info[0];
/*
* Save score back to session
*/
$_SESSION["score"] = $score;
/*
* Display articles for Aces and Eights
*/
if ($card == "1" || $card == "2" || $card == "3" || $card == "4" || $card == "25" || $card == "26" || $card == "27" || $card == "28") {
$n = "n";
} else {
$n = "";
}
/*
* Display points for Aces
*/
if ($card == "1" || $card == "2" || $card == "3" || $card == "4") {
$ace = " or 10";
} else {
$ace = "";
}
echo "<img src='images/cards/$cardPicture.png' alt='card' title='$info[1]' /><br />";
echo "Your <b>$num.</b> card is a$n <b>$info[1]</b> and it gives you <b>$info[0]$ace points</b>.<br />Your score is now <b>$score.</b>";
/*
* Display chance to go over 21
* The complete deck has a value of 2040 points
*/
if ($score <= 21) {
$chance = $bjack->calculateChance($_SESSION["deck"], $num, $score);
$chance = round($chance, 0); /* We won't see a float number */
echo "<br />Chance to lose: <b>$chance%</b><br /><br />";
echo "<form action='?login' method='post'>\n";
echo "<input type='submit' value='New Card' name='newcard' />\n";
echo "<input type='submit' value='Finish game' name='finish' />\n";
echo "<select class='cardsSelector'>\n";
echo "<option>1 card</option>\n";
echo "<option>2 cards</option>\n";
echo "<option>3 cards</option>\n";
echo "</select>\n";
echo "</form>";
} else {
/*
* Lost game
*/
echo "You loose!<br /><br />";
echo "<a href='?login'>New game</a>";
/*
* Reset session data
*/
unset($_SESSION["num"]);
unset($_SESSION["score"]);
/*
* Save score to database
*/
require_once(SITE_ROOT . "/models/" . "database.php");
$database = new Database();
$database->saveScore($_SESSION["user"], $score);
/*
* Generate new deck
*/
$deck = $bjack->generateShuffledDeck();
$_SESSION["deck"] = $deck;
}
}
?>
<br /><br />
<a href="?menu">Back to menu</a>

8
templates/head.tpl.php Normal file
View file

@ -0,0 +1,8 @@
<?php include(SITE_ROOT . "/include/" . "config.inc.php"); ?>
<head>
<title><?php echo $site_title; ?></title>
<link rel="stylesheet" type="text/css" href="<?php echo "css/default.css"; ?>" />
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<script type="text/javascript" src="jquery/jquery-1.7.1.js"></script>
<script type="text/javascript" src="jquery/bjack.js"></script>
</head>

View file

@ -0,0 +1,35 @@
<h1>Highscores</h1>
<?php
require_once(SITE_ROOT . "/models/" . "database.php");
$database = new Database();
$highscores = $database->getHighscores();
/*
* Sort multidimensional array according to $array[][1]
*/
$sortArray = array();
foreach ($highscores as $key => $value) {
$sortArray[$key] = $value[1];
}
array_multisort($sortArray, SORT_DESC, SORT_NUMERIC, $highscores);
$place = 0;
foreach ($highscores as $highscore) {
if ($highscore[1] <= 21) {
$place++;
}
if ($place != 0) {
echo "Place $place: ";
}
$score = round($highscore[1], 2);
echo" <b>$highscore[0]</b> with <b>$score</b> Points in <b>$highscore[2]</b> games<br />\n";
}
?>
<br /><br />
<a href="?menu">Back to menu</a>

View file

@ -0,0 +1,9 @@
<h1>Impressum</h1>
<p>
Stefan 'xeno' Ritter<br />
E-Mail: xeno (at) thehappy.de
</p>
<br />
<br />
<a href="?menu">Back to menu</a>

11
templates/invalid.tpl.php Normal file
View file

@ -0,0 +1,11 @@
<h1>Error</h1>
Something went terribly wrong!<br /><br />
Wrong password?<br />
Username cannot be <b>name</b><br />
Password cannot be <b>password</b><br />
The developer is a dumbass<br /><br />
<a href="?login">Try again</a><br /><br/>
<a href="?menu">Back to menu</a>

6
templates/login.tpl.php Normal file
View file

@ -0,0 +1,6 @@
<h1>Login</h1>
<form action="?game" method="post">
<input name="user" id="name" type="text" value="name" /><br />
<input name="pass" id="pass" type="text" value="password" /><br />
<input type="submit" value="Start" />
</form>

2
templates/logout.tpl.php Normal file
View file

@ -0,0 +1,2 @@
<h1>User logged out</h1>
<a href="?menu">Back to menu</a>

11
templates/menu.tpl.php Normal file
View file

@ -0,0 +1,11 @@
<?php
session_start();
if (isset($_SESSION["user"])) {
echo "Logged in as user <b>" . $_SESSION["user"] . "</b> (<a href='?logout'>logout</a>)";
}
?>
<div id="menu">
<a href="?login"><img src="images/cards/1.png" alt="card" /></a><a href="?highscores"><img src="images/cards/2.png" alt="card" /></a><a href="?impressum"><img src="images/cards/3.png" alt="card" /></a>
<p>New Game</p><p>Highscores</p><p>Impressum</p>
</div>