diff options
author | Stefan Ritter <xeno@thehappy.de> | 2012-03-13 11:36:26 +0100 |
---|---|---|
committer | Stefan Ritter <xeno@thehappy.de> | 2012-03-13 11:36:26 +0100 |
commit | 600316a94a7e40c5fef364d6f98abc3e509131ad (patch) | |
tree | 4d35ea4627d32bf1c1d6acfdb4799eae174e54a2 /templates |
Initial commit
Diffstat (limited to 'templates')
-rw-r--r-- | templates/404.tpl.php | 2 | ||||
-rw-r--r-- | templates/game.tpl.php | 167 | ||||
-rw-r--r-- | templates/head.tpl.php | 8 | ||||
-rw-r--r-- | templates/highscores.tpl.php | 35 | ||||
-rw-r--r-- | templates/impressum.tpl.php | 9 | ||||
-rw-r--r-- | templates/invalid.tpl.php | 11 | ||||
-rw-r--r-- | templates/login.tpl.php | 6 | ||||
-rw-r--r-- | templates/logout.tpl.php | 2 | ||||
-rw-r--r-- | templates/menu.tpl.php | 11 |
9 files changed, 251 insertions, 0 deletions
diff --git a/templates/404.tpl.php b/templates/404.tpl.php new file mode 100644 index 0000000..91fc6fb --- /dev/null +++ b/templates/404.tpl.php @@ -0,0 +1,2 @@ +<h1>404</h1> +<p>Site not found...</p> diff --git a/templates/game.tpl.php b/templates/game.tpl.php new file mode 100644 index 0000000..f7f67b8 --- /dev/null +++ b/templates/game.tpl.php @@ -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> diff --git a/templates/head.tpl.php b/templates/head.tpl.php new file mode 100644 index 0000000..9410f54 --- /dev/null +++ b/templates/head.tpl.php @@ -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> diff --git a/templates/highscores.tpl.php b/templates/highscores.tpl.php new file mode 100644 index 0000000..9bc889f --- /dev/null +++ b/templates/highscores.tpl.php @@ -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> diff --git a/templates/impressum.tpl.php b/templates/impressum.tpl.php new file mode 100644 index 0000000..f6370a2 --- /dev/null +++ b/templates/impressum.tpl.php @@ -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> diff --git a/templates/invalid.tpl.php b/templates/invalid.tpl.php new file mode 100644 index 0000000..a05adf9 --- /dev/null +++ b/templates/invalid.tpl.php @@ -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> diff --git a/templates/login.tpl.php b/templates/login.tpl.php new file mode 100644 index 0000000..073cafc --- /dev/null +++ b/templates/login.tpl.php @@ -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> diff --git a/templates/logout.tpl.php b/templates/logout.tpl.php new file mode 100644 index 0000000..bb4a5f7 --- /dev/null +++ b/templates/logout.tpl.php @@ -0,0 +1,2 @@ +<h1>User logged out</h1> +<a href="?menu">Back to menu</a> diff --git a/templates/menu.tpl.php b/templates/menu.tpl.php new file mode 100644 index 0000000..4c3913a --- /dev/null +++ b/templates/menu.tpl.php @@ -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> |