index.lsp



   1   
<?lsp 2 3 -- 4 -- Converted from the CSP, which was converted from a CGI 5 -- 6 7 local 8 wordDB = page.hangmanworddb 9 or 10 { 11 {"script", "lsp"}, 12 {"action", "drool"}, 13 {"action", "forecast"}, 14 {"action", "forget"}, 15 {"action", "jump"}, 16 {"action", "panic"}, 17 {"action", "quash"}, 18 {"action", "snore"}, 19 {"action", "talk"}, 20 {"action", "walk"}, 21 {"activity", "boating"}, 22 {"activity", "repair"}, 23 {"activity", "ruffle"}, 24 {"activity", "sleep"}, 25 {"activity", "surfing"}, 26 {"animal", "aardvark"}, 27 {"animal", "adder"}, 28 {"animal", "beaver"}, 29 {"animal", "bison"}, 30 {"animal", "cardinal"}, 31 {"animal", "cariboo"}, 32 {"animal", "cat"}, 33 {"animal", "donkey"}, 34 {"animal", "elephant"}, 35 {"animal", "koala"}, 36 {"animal", "otter"}, 37 {"animal", "rabbit"}, 38 {"animal", "raccoon"}, 39 {"animal", "rodent"}, 40 {"animal", "shark"}, 41 {"animal", "sheep"}, 42 {"animal", "squirrel"}, 43 {"animal", "tiger"}, 44 {"antique", "china"}, 45 {"band", "nirvana"}, 46 {"band", "rush"}, 47 {"band", "ventures"}, 48 {"creature", "elf"}, 49 {"creature", "hobbit"}, 50 {"creature", "mummy"}, 51 {"creature", "troll"}, 52 {"creature", "unicorn"}, 53 {"creature", "vampire"}, 54 {"creature", "warewolf"}, 55 {"drink", "cola"}, 56 {"drink", "juice"}, 57 {"event", "drama"}, 58 {"event", "mirage"}, 59 {"event", "siesta"}, 60 {"event", "stampede"}, 61 {"food", "apple"}, 62 {"food", "butter"}, 63 {"food", "caesar salad"}, 64 {"food", "cashew"}, 65 {"food", "celery"}, 66 {"food", "cheese"}, 67 {"food", "chestnut"}, 68 {"food", "cream"}, 69 {"food", "donut"}, 70 {"food", "grape"}, 71 {"food", "honey"}, 72 {"food", "icecream"}, 73 {"food", "limburger"}, 74 {"food", "milk"}, 75 {"food", "noodle"}, 76 {"food", "orange"}, 77 {"food", "pasta"}, 78 {"food", "pizza"}, 79 {"food", "potato"}, 80 {"food", "spice"}, 81 {"food", "sugar"}, 82 {"food", "tomatoes"}, 83 {"food", "turnip"}, 84 {"game", "cards"}, 85 {"game", "golf"}, 86 {"game", "pacman"}, 87 {"icon", "barbie"}, 88 {"icon", "frosty"}, 89 {"icon", "grinch"}, 90 {"icon", "gumby"}, 91 {"icon", "lucy"}, 92 {"icon", "popeye"}, 93 {"icon", "snoopy"}, 94 {"icon", "waldo"}, 95 {"invention", "velcro"}, 96 {"person", "enemy"}, 97 {"person", "giant"}, 98 {"person", "hero"}, 99 {"person", "husband"}, 100 {"person", "kennedy"}, 101 {"person", "nixon"}, 102 {"person", "youngster"}, 103 {"place", "amsterdam"}, 104 {"place", "athens"}, 105 {"place", "beach"}, 106 {"place", "bob"}, 107 {"place", "buffalo"}, 108 {"place", "calgary"}, 109 {"place", "canada"}, 110 {"place", "detroit"}, 111 {"place", "downtown"}, 112 {"place", "england"}, 113 {"place", "gorge"}, 114 {"place", "graceland"}, 115 {"place", "hotel"}, 116 {"place", "hotel"}, 117 {"place", "india"}, 118 {"place", "japan"}, 119 {"place", "land"}, 120 {"place", "library"}, 121 {"place", "london"}, 122 {"place", "norway"}, 123 {"place", "oslo"}, 124 {"place", "ottawa"}, 125 {"place", "quadrant"}, 126 {"place", "restaurant"}, 127 {"place", "rink"}, 128 {"place", "toronto"}, 129 {"place", "victoria"}, 130 {"place", "village"}, 131 {"place", "zoo"}, 132 {"plant", "daffodil"}, 133 {"plant", "eggplant"}, 134 {"plant", "ivy"}, 135 {"plant", "spinach"}, 136 {"plant", "tulip"}, 137 {"profession", "astronaut"}, 138 {"profession", "bard"}, 139 {"profession", "hermit"}, 140 {"profession", "lawyer"}, 141 {"profession", "sorcerer"}, 142 {"state", "alaska"}, 143 {"subject", "geography"}, 144 {"taste", "bitter"}, 145 {"taste", "salty"}, 146 {"taste", "sour"}, 147 {"taste", "sweet"}, 148 {"tool", "anvil"}, 149 {"tool", "buffer"}, 150 {"tool", "hook"}, 151 {"tool", "knife"}, 152 {"tool", "lasso"}, 153 {"tool", "pickaxe"}, 154 {"tool", "pliers"}, 155 {"tool", "plow"}, 156 {"tool", "screwdriver"}, 157 {"tool", "wrench"}, 158 {"toy", "kite"}, 159 {"toy", "slinky"}, 160 {"trouble", "tribble"} 161 } 162 163 page.hangmanworddb = wordDB 164 165 local data = request:data() 166 167 local guess = data.guess 168 local wordDbIndex=tonumber(data.wordDbIndex) 169 local noOfUsedGues = tonumber(data.noOfUsedGues) 170 local ch = data.ch and string.sub(data.ch,1,1) 171 172 local fmt = string.format 173 local function prt(...) response:write(...) end 174 local function prtf(...) prt(fmt(...)) end 175 176 local answer, clue, word 177 178 if not wordDbIndex then -- /* Should be true unless first time or a new game. 179 -- * This works since the form in the html above is only 180 -- * emitted if we are playing a game 181 -- */ 182 -- /* First time or new game */ 183 repeat 184 wordDbIndex = ba.rnd(1,#wordDB); 185 until wordDbIndex ~= page.wordDbIndex 186 187 page.wordDbIndex = wordDbIndex 188 189 word = wordDB[wordDbIndex]; 190 clue=word[1] 191 answer=word[2] 192 newGuess = string.rep('_', #answer); 193 noOfUsedGues=0 194 else 195 local chCorrect = false; 196 assert(guess); 197 newGuess = guess; 198 assert(ch); 199 assert(wordDB) 200 assert(wordDbIndex > 0, wordDbIndex); 201 word = wordDB[wordDbIndex]; 202 assert(word) 203 clue=word[1] 204 answer=word[2] 205 ch = ch:lower() 206 newGuess="" 207 string.gsub(answer, "()(.)", function(pos,c) 208 if string.sub(answer, pos,pos) == ch then 209 newGuess = newGuess .. ch 210 chCorrect = true; 211 else 212 newGuess = newGuess .. string.sub(guess, pos,pos) 213 end 214 end) 215 if newGuess == answer then 216 noOfUsedGues = 7; -- 7 signals "You Won!!!" 217 elseif not chCorrect then 218 noOfUsedGues = noOfUsedGues + 1; 219 end 220 end 221 222 title="hangman" 223 response:include"/rtl/.header.lsp" 224 ?>
225 <div align=center> 226 227 <a href="http://barracudaserver.com/doc/Lua/frame.html" target="_blank"> 228 <img border="0" src="bl2.gif" style="float:left;margin: 10px 10px" 229 alt="The Hangman game is powered by the Lua Server Pages Barracuda plugin"></img></a> 230 231 <div style="float:right;width:250px;border-style: dotted; border-color:gray;border-width:1px;padding:5px;margin: 10px 10px 20px 20px"> 232 233 <p style="font-size: 12pt;text-align:left;color:gray"> 234 The hangman game was initially a CGI script. The CGI script was 235 converted to C/C++ server Pages (CSP). This version of the game is 236 in Lua Server Pages (LSP). Maybe you are interested in reading the 237 <a href="http://barracudaserver.com/WP/CSP/" target="blank">Hangman 238 CSP whitepaper</a>. You can compare the <a 239 href="http://barracudaserver.com/WP/CSP/hangmanHtmlCode.html" 240 target="_blank">CSP code</a> to the <a 241 href="showsource/showsource.lsp?path=
<?lsp=pathname?>
" 242 target=_blank>LSP code</a>. 243 </p> 244 </div> 245 246 <font color='#ff3333' size=+5>H</font> 247 <font color='#cc6633' size=+5>a</font> 248 <font color='#999900' size=+5>n</font> 249 <font color='#33cc33' size=+5>g</font> 250 <font color='#339999' size=+5>m</font> 251 <font color='#3366cc' size=+5>a</font> 252 <font color='#0033ff' size=+5>n</font> 253 </div> 254 255 <div align=center> 256 <font size=+3 color='#336699'> 257
<?lsp 258 for i=1, #newGuess do 259 prtf("%s&nbsp;",string.sub(newGuess,i,i)); 260 end 261 ?>
262 </font> 263 </div> 264 <br/> 265 <div align=center> 266 <img src='
<?lsp=fmt("hang%d", noOfUsedGues)?>
.gif' height=150 width=150 alt=''/> 267
<?lsp 268 if noOfUsedGues >= 6 then 269 ?>
270 <p> 271 <font size=+3 color="#ff3333"> 272
<?lsp= noOfUsedGues == 6 and "Game over." or "You Won!!!"?>
273 </font> 274 </p> 275 <p> 276 <font size=+2 color="#3333cc"> 277 The correct answer is <B>
<?lsp=answer?>
</B>. 278 </font> 279 </p> 280 Play another game of <a href='./'>Hangman</a> 281
<?lsp 282 else 283 if noOfUsedGues == 0 then 284 ?>
285 <p>Guess your first letter of the above unknown word.</p> 286
<?lsp 287 else 288 ?>
289 <p> You have
<?lsp= 6-noOfUsedGues ?>
guesses left! </p> 290
<?lsp 291 end 292 ?>
293 <font color='#0033ff'>hint : <b>
<?lsp=clue?>
</b></font> 294 295 <form method='post'> 296 <input type='hidden' name='wordDbIndex' value='
<?lsp=wordDbIndex?>
'/> 297 <input type='hidden' name='guess' value='
<?lsp=newGuess?>
'/> 298 <input type='hidden' name='noOfUsedGues' value='
<?lsp=noOfUsedGues?>
'/> 299
<?lsp 300 for i = string.byte('A'), string.byte('Z'), 1 do 301 prtf("\t\t<input type='submit' name='ch' value='%c'/>\n",i); 302 end 303 ?>
304 </form> 305
<?lsp 306 end 307 ?>
308 </div> 309
<?lsp response:include"/rtl/.footer.lsp" ?>
310