Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Darts scorekeeper v1.0
- Tue Feb 7 2012, KnickLighter */
- // Configuration
- $ds_game = "501";
- session_start();
- if ($_GET['act'] == "start") {
- $_SESSION['active'] = "yes";
- $_SESSION['score'] = $ds_game;
- $_SESSION['avg'] = "0";
- $_SESSION['throws'] = "0";
- $_SESSION['scored'] = array();
- }
- function ds_restart () { header("Location: index.php?act=start"); }
- function ds_error ($ds_err) {
- echo "<h1>Error!</h1><p>".$ds_err."</p><p>Click <a href=\"index.php\">here</a> to go back!";
- die();
- }
- if ($_GET['act'] == "throw") {
- if (isset($_GET['score'])) {
- $ds_score = htmlspecialchars($_GET['score']);
- if (!is_numeric($ds_score)) { ds_error("Score not numeric!"); }
- if ($ds_score == $_SESSION['score'] - 1) { ds_error("Score too high!"); }
- if ($ds_score > "180") { ds_error("Did you really score 180+?"); }
- if ($ds_score == $_SESSION['score']) { ds_restart(); }
- $_SESSION['score'] = $_SESSION['score'] - $ds_score;
- array_push($_SESSION['scored'], $ds_score);
- $_SESSION['throws'] = $_SESSION['throws'] + 1;
- $_SESSION['avg'] = ($ds_game - $_SESSION['score']) / ($_SESSION['throws']);
- }
- }
- ?>
- <html>
- <head>
- <title>Darts</title>
- </head>
- <body onload="document.score.score.focus();">
- <table width="100%">
- <tr>
- <td align="left"><a href="index.php?act=start">Start</a> |</td>
- <td align="right">Darts thrown: <? echo $_SESSION['throws'] * 3 ." (".round($_SESSION['avg'], 2)." avg.)"; ?></td>
- <tr>
- </table>
- <hr>
- <h1><? echo $_SESSION['score']; ?></h1>
- <hr>
- <form name="score" method="GET">
- <input type="hidden" name="act" value="throw">
- <input type="text" name="score" autocomplete="off">
- <input type="submit" value="Throw!">
- </form>
- <hr>
- <?php
- $ds_amount = count($_SESSION['scored']);
- for ($i = $ds_amount; $i >= 0; $i--) {
- echo $_SESSION['scored'][$i] ."\n<br>";
- }
- ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment