Home > Sorry, the page you were looking for in this blog does not exist.
1
2
3 hangman
4
5
6
25
81 #include
82 #include
83 #include
84 #include
85
86 struct Word
87 {
88 const char* clue;
89 const char* answer;
90 };
91
92 const Word wordDB[] = {
93 {"action", "drool"},
94 {"action", "forecast"},
95 {"action", "forget"},
96 {"action", "jump"},
97 {"action", "panic"},
98 {"action", "quash"},
99 {"action", "snore"},
100 {"action", "talk"},
101 {"action", "walk"},
102 {"activity", "boating"},
103 {"activity", "repair"},
104 {"activity", "ruffle"},
105 {"activity", "sleep"},
106 {"activity", "surfing"},
107 {"animal", "aardvark"},
108 {"animal", "adder"},
109 {"animal", "beaver"},
110 {"animal", "bison"},
111 {"animal", "cardinal"},
112 {"animal", "cariboo"},
113 {"animal", "cat"},
114 {"animal", "donkey"},
115 {"animal", "elephant"},
116 {"animal", "koala"},
117 {"animal", "otter"},
118 {"animal", "rabbit"},
119 {"animal", "raccoon"},
120 {"animal", "rodent"},
121 {"animal", "shark"},
122 {"animal", "sheep"},
123 {"animal", "squirrel"},
124 {"animal", "tiger"},
125 {"antique", "china"},
126 {"band", "nirvana"},
127 {"band", "rush"},
128 {"band", "ventures"},
129 {"creature", "elf"},
130 {"creature", "hobbit"},
131 {"creature", "mummy"},
132 {"creature", "troll"},
133 {"creature", "unicorn"},
134 {"creature", "vampire"},
135 {"creature", "warewolf"},
136 {"drink", "cola"},
137 {"drink", "juice"},
138 {"event", "drama"},
139 {"event", "mirage"},
140 {"event", "siesta"},
141 {"event", "stampede"},
142 {"food", "apple"},
143 {"food", "butter"},
144 {"food", "caesar salad"},
145 {"food", "cashew"},
146 {"food", "celery"},
147 {"food", "cheese"},
148 {"food", "chestnut"},
149 {"food", "cream"},
150 {"food", "donut"},
151 {"food", "grape"},
152 {"food", "honey"},
153 {"food", "icecream"},
154 {"food", "limburger"},
155 {"food", "milk"},
156 {"food", "noodle"},
157 {"food", "orange"},
158 {"food", "pasta"},
159 {"food", "pizza"},
160 {"food", "potato"},
161 {"food", "spice"},
162 {"food", "sugar"},
163 {"food", "tomatoes"},
164 {"food", "turnip"},
165 {"game", "cards"},
166 {"game", "golf"},
167 {"game", "pacman"},
168 {"icon", "barbie"},
169 {"icon", "frosty"},
170 {"icon", "grinch"},
171 {"icon", "gumby"},
172 {"icon", "lucy"},
173 {"icon", "popeye"},
174 {"icon", "snoopy"},
175 {"icon", "waldo"},
176 {"invention", "velcro"},
177 {"person", "enemy"},
178 {"person", "giant"},
179 {"person", "hero"},
180 {"person", "husband"},
181 {"person", "kennedy"},
182 {"person", "nixon"},
183 {"person", "youngster"},
184 {"place", "amsterdam"},
185 {"place", "athens"},
186 {"place", "beach"},
187 {"place", "bob"},
188 {"place", "buffalo"},
189 {"place", "calgary"},
190 {"place", "canada"},
191 {"place", "detroit"},
192 {"place", "downtown"},
193 {"place", "england"},
194 {"place", "gorge"},
195 {"place", "graceland"},
196 {"place", "hotel"},
197 {"place", "hotel"},
198 {"place", "india"},
199 {"place", "japan"},
200 {"place", "land"},
201 {"place", "library"},
202 {"place", "london"},
203 {"place", "norway"},
204 {"place", "oslo"},
205 {"place", "ottawa"},
206 {"place", "quadrant"},
207 {"place", "restaurant"},
208 {"place", "rink"},
209 {"place", "toronto"},
210 {"place", "victoria"},
211 {"place", "village"},
212 {"place", "zoo"},
213 {"plant", "daffodil"},
214 {"plant", "eggplant"},
215 {"plant", "ivy"},
216 {"plant", "spinach"},
217 {"plant", "tulip"},
218 {"profession", "astronaut"},
219 {"profession", "bard"},
220 {"profession", "hermit"},
221 {"profession", "lawyer"},
222 {"profession", "sorcerer"},
223 {"state", "alaska"},
224 {"subject", "geography"},
225 {"taste", "bitter"},
226 {"taste", "salty"},
227 {"taste", "sour"},
228 {"taste", "sweet"},
229 {"tool", "anvil"},
230 {"tool", "buffer"},
231 {"tool", "hook"},
232 {"tool", "knife"},
233 {"tool", "lasso"},
234 {"tool", "pickaxe"},
235 {"tool", "pliers"},
236 {"tool", "plow"},
237 {"tool", "screwdriver"},
238 {"tool", "wrench"},
239 {"toy", "kite"},
240 {"toy", "slinky"},
241 {"trouble", "tribble"}
242 };
243
244 %>
245 <%!!
246 /* Seed the random-number generator with current time so that
247 * the numbers will be different every time we run.
248 */
249 srand((unsigned)time(0));
250 %>
251 <%p
252 unsigned int i;
253 const char* ch=0;
254 const Word* word=0;
255 int wordDbIndex;
256 const char* guess=0;
257 char* newGuess=0;
258 int noOfUsedGues = 0;
259 HttpParameterIterator fIter(request);
260 /* Extract data from form in the above html */
261 for( ; fIter.hasMoreElements() ; fIter.nextElement())
262 {
263 if( ! strcmp(fIter.getName(), "guess") )
264 guess = fIter.getValue();
265 else if( ! strcmp(fIter.getName(), "ch") )
266 ch = fIter.getValue();
267 else if( ! strcmp(fIter.getName(), "wordDbIndex") )
268 {
269 wordDbIndex = atoi(fIter.getValue());
270 word = &wordDB[wordDbIndex];
271 }
272 else if( ! strcmp(fIter.getName(), "noOfUsedGues") )
273 noOfUsedGues = atoi(fIter.getValue());
274 }
275 if(word) /* Should be true unless first time or a new game.
276 * This works since the form in the html above is only
277 * emitted if we are playing a game
278 */
279 {
280 bool chCorrect=false;
281 assert(guess);
282 newGuess = httpStrdup(guess);
283 assert(ch);
284 for(i = 0 ; i < strlen(word->answer) ; i++)
285 {
286 if(tolower(word->answer[i]) == tolower(*ch))
287 {
288 newGuess[i] = *ch;
289 chCorrect = true;
290 }
291 }
292 if( ! httpStrCaseCmp(newGuess, word->answer) )
293 noOfUsedGues = 7; /* 7 signals "You Won!!!" */
294 else if(chCorrect == false)
295 noOfUsedGues++;
296 }
297 else /* First time or new game */
298 {
299 wordDbIndex = rand() % (sizeof(wordDB) / sizeof(wordDB[0]));
300 word = &wordDB[wordDbIndex];
301 newGuess = (char*)httpMalloc(strlen(word->answer)+1);
302 memset(newGuess, '_', strlen(word->answer));
303 newGuess[strlen(word->answer)] = 0;
304 }
305 %>
306 <%e
307 httpFree(newGuess);
308 %> !doctype>
7 H
8 a
9 n
10 g
11 m
12 a
13 n
14
15
16
17
18 <%
19 for(i = 0; i < strlen(newGuess) ; i++)
20 response->printf("%c ", newGuess[i]);
21 %>
22
23
24 25
26
27 <%
28 if(noOfUsedGues == 6 || noOfUsedGues == 7)
29 {
30 %>
31
76
77
78
79 <%g
80 #include 32 33 <%= noOfUsedGues == 6 ? "Game over." : "You Won!!!"%> 34 35
3637 38 The correct answer is <%=word->answer%>. 39 40
41 Play another game of Hangman 42 <% 43 } 44 else 45 { 46 if(noOfUsedGues == 0) 47 { 48 %> 49Guess your first letter of the above unknown word.
50 <% 51 } 52 else 53 { 54 %> 55You have <%="%d " 6-noOfUsedGues%> guesses left!
56 <% 57 } 58 %> 59 hint : <%=word->clue%> 60 61 69 <% 70 } 71 %> 7273 view html source code 74
75About The LOT 30
LOT30 is a non-profit organization formed by Andy Denko. Its purpose is to bring together Politician, fans of all Pakatan, and grassroots political organizations to fight for social enhancement.