SHOW:
|
|
- or go back to the newest paste.
| 1 | <?php | |
| 2 | session_start(); | |
| 3 | ?> | |
| 4 | <head> | |
| 5 | - | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| 5 | + | <meta charset="UTF-8"> |
| 6 | <style> | |
| 7 | input[type=submit] {
| |
| 8 | width: 25px; | |
| 9 | height: 25px; | |
| 10 | margin: 1px; | |
| 11 | } | |
| 12 | ||
| 13 | #wordArea {
| |
| 14 | letter-spacing:5px; | |
| 15 | font-size: 23px; | |
| 16 | } | |
| 17 | </style> | |
| 18 | </head> | |
| 19 | ||
| 20 | <?php | |
| 21 | ||
| 22 | function file_get_contents_utf8($fn) {
| |
| 23 | $content = file_get_contents($fn); | |
| 24 | return mb_convert_encoding($content, 'UTF-8', | |
| 25 | mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true)); | |
| 26 | } | |
| 27 | ||
| 28 | /* | |
| 29 | * Origional script by Duane O'Brien - http://chaoticneutral.net written for IBM DeveloperWorks | |
| 30 | * Edited and custom modifyed by Jonas Laursen | |
| 31 | */ | |
| 32 | ||
| 33 | $letters = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','æ','ø','å');
| |
| 34 | ||
| 35 | if (empty($_POST)) {
| |
| 36 | $words = explode("\n", file_get_contents('words.list.txt'));
| |
| 37 | $right = array_fill_keys($letters, '_'); | |
| 38 | $wrong = array(); | |
| 39 | shuffle($words); | |
| 40 | $word = strtolower($words[0]); $_SESSION['word'] = $word; | |
| 41 | $_SESSION['rightstr'] = serialize($right); | |
| 42 | $_SESSION['wrongstr'] = serialize($wrong); | |
| 43 | $wordletters = str_split($word); | |
| 44 | print_r($wordletters); | |
| 45 | $show = ''; | |
| 46 | foreach ($wordletters as $letter) {
| |
| 47 | $show .= $right[$letter]; | |
| 48 | } | |
| 49 | } else {
| |
| 50 | $win = false; | |
| 51 | $word = $_SESSION['word']; | |
| 52 | $guess = strtolower($_POST['guess']); | |
| 53 | $right = unserialize($_SESSION['rightstr']); | |
| 54 | $wrong = unserialize($_SESSION['wrongstr']); | |
| 55 | $wordletters = str_split($word); | |
| 56 | if (stristr($word, $guess)) {
| |
| 57 | $show = ''; | |
| 58 | $right[$guess] = $guess; | |
| 59 | $wordletters = str_split($word); | |
| 60 | foreach ($wordletters as $letter) {
| |
| 61 | $show .= $right[$letter]; | |
| 62 | } | |
| 63 | if($show == $word) $win = 'win'; | |
| 64 | } else {
| |
| 65 | $show = ''; | |
| 66 | $wrong[$guess] = $guess; | |
| 67 | if (count($wrong) == 7) {
| |
| 68 | $show = $word; | |
| 69 | $win = 'loose'; | |
| 70 | } else {
| |
| 71 | foreach ($wordletters as $letter) {
| |
| 72 | $show .= $right[$letter]; | |
| 73 | } | |
| 74 | } | |
| 75 | } | |
| 76 | $used = array_merge($right, $wrong); | |
| 77 | $_SESSION['rightstr'] = serialize($right); | |
| 78 | $_SESSION['wrongstr'] = serialize($wrong); | |
| 79 | } | |
| 80 | ||
| 81 | if($win == 'loose' || $win == false) {
| |
| 82 | $count = count($wrong); | |
| 83 | echo "<img src='assets/stages/". $count .".png'>"; | |
| 84 | } elseif($win == 'win') {
| |
| 85 | echo "<img src='assets/stages/win.png'>"; | |
| 86 | } | |
| 87 | ||
| 88 | ?> | |
| 89 | Bad Guesses : <?php echo implode(', ', $wrong) ?><br />
| |
| 90 | <b>Notér:</b> æ = ae, ø = oe, å = aa<br/> | |
| 91 | <div id='wordArea'><?php echo $show ?></div><br /> | |
| 92 | <form method='post'> | |
| 93 | <input type='hidden' name='action' value='guess' /> | |
| 94 | ||
| 95 | <?php | |
| 96 | $x = 1; | |
| 97 | foreach($letters as $key => $letter) {
| |
| 98 | if(in_array($letter, $used)) $disabled = ' disabled'; else $disabled = ''; | |
| 99 | if($win != false) $disabled = ' disabled'; | |
| 100 | echo "<input type='submit' name='guess' value='". $letter ."'$disabled>"; | |
| 101 | if($x == 7) { echo "<br/>"; $x = 0; }
| |
| 102 | $x++; | |
| 103 | } | |
| 104 | ?> | |
| 105 | </form> | |
| 106 | <a href='index.php'>Start Over</a> |