git @ Cat's Eye Technologies Super-Wumpus-Land / 2e8866e
Implement game states. catseye 12 years ago
1 changed file(s) with 94 addition(s) and 83 deletion(s). Raw diff Collapse all Expand all
5151
5252 this.subway = false;
5353
54 this.done = false;
5554 this.skip = false;
5655 this.moved = false;
56
57 this.gameState = 'stateTitleScreen';
5758
5859 var loc_adj = [
5960 'Rocky',
132133 this.arrows = 1;
133134
134135 tty.write("SUPER WUMPUS LAND\n\n");
135 this.show();
136 this.ask();
136 this.pause('statePrompt');
137 };
138
139 this.pause = function(nextState) {
140 this.tty.write("\n[Press ENTER to continue.] ");
141 this.gameState = nextState;
137142 };
138143
139144 this.show = function() {
178183 print("" + room.tokens + " subway tokens lie on the ground here.\n");
179184 }
180185
181 if (room.guano > 0)
182 {
183 print("\nThere is a ");
184 if (room.guano === 1) { print("small"); }
185 else if (room.guano === 2) { print("sizable"); }
186 else if (room.guano === 3) { print("large"); }
187 else if (room.guano === 4) { print("huge"); }
188 else { print("gigantic"); }
189 print(" pile of Wumpus dung here.\n");
186 if (room.guano > 0) {
187 print("\nThere is a ");
188 if (room.guano === 1) { print("small"); }
189 else if (room.guano === 2) { print("sizable"); }
190 else if (room.guano === 3) { print("large"); }
191 else if (room.guano === 4) { print("huge"); }
192 else { print("gigantic"); }
193 print(" pile of Wumpus dung here.\n");
190194 }
191195
192196 print("\n");
204208 if (this.codliver > 0) {
205209 print(" ...and immediately BARFED YOU BACK OUT!!!!\n");
206210 } else {
207 this.pause();
208 this.done = true;
209 return;
211 this.pause('stateGameOver');
212 return false;
210213 }
211214 }
212215 } else {
231234 print("* Super Bats in this location stay well away from your awful stench!\n");
232235 } else {
233236 print("* Zap! Super Bat Snatch! Elsewheresville for you!\n");
234 this.pause();
235237 this.roomNo = d(1,100);
236238 this.skip = 1;
237 return;
239 this.pause('statePrompt');
240 return false;
238241 }
239242 }
240243 var batsNearby = false;
254257 print("* You deftly stick to the edge of the bottomless pit!\n");
255258 } else {
256259 print("* Yiiiieeee!!! Fell in a pit!\n");
257 this.pause();
258 this.done = true;
259 return;
260 this.pause('stateGameOver');
261 return false;
260262 }
261263 }
262264 var aDraft = false;
284286 }
285287 }
286288 print("\n");
289 return true;
287290 };
288291
289292 this.ask = function() {
341344 print(" [I]nventory and Score\n\n");
342345 print(" [Q]uit\n\n");
343346 print("What would you like to do next, " + this.name + "? ");
344 };
345
346 this.pause = function() {
347 this.tty.write("\n[Press ENTER to continue.] ");
348 this.paused = true;
349 };
350
351 this.handleInput = function(input) {
352 if (this.paused) {
353 this.paused = false;
354 this.show();
347
348 this.gameState = 'stateProcessCommand';
349 };
350
351 this.moveWumpi = function() {
352 var self = this;
353 var print = function(str) {
354 self.tty.write(str);
355 };
356
357 for (var i = 0; i < this.wumpi.length; i++) {
358 var wumpus = this.wumpi[i];
359 if (wumpus.room === 0) {
360 if (d(1, 5) === 1) {
361 // restart wumpus
362 wumpus.room = d(1, 100);
363 while (wumpus.room === this.roomNo) {
364 wumpus.room = d(1, 100);
365 }
366 wumpus.asleep = false;
367 }
368 continue;
369 }
370 if (wumpus.asleep) {
371 if (d(1, 4) === 1) {
372 wumpus.asleep = false;
373 if (d(1, 5) !== 1) {
374 this.rooms[wumpus.room].guano++;
375 }
376 }
377 } else {
378 if (d(1, 3) === 1) {
379 var dest = this.rooms[wumpus.room].exits[d(1,3)-1];
380 if (dest !== this.roomNo || !this.moved) {
381 wumpus.room = dest;
382 if (dest === this.roomNo) {
383 print("From around a corner, a hungry-looking Wumpus appears!!\n");
384 this.pause();
385 }
386 }
387 }
388 if (d(1,8) === 1) { wumpus.asleep = true; }
389 if (d(1,8) === 1) { this.rooms[wumpus.room].guano++; }
390 }
391 }
392 };
393
394 /* -*-*-*- GAME STATES -*-*-*- */
395
396 this.statePrompt = function(input) {
397 if (this.show()) {
355398 this.ask();
356 return;
357 }
358
399 }
400 };
401
402 this.stateGameOver = function(input) {
403 this.tty.write("Game over, " + this.name + ".\n");
404 };
405
406 this.stateProcessCommand = function(input) {
359407 var self = this;
360408 var print = function(str) {
361409 self.tty.write(str);
364412
365413 input = input.toUpperCase();
366414 if (input === 'Q') {
367 this.done = true;
415 this.pause('stateGameOver');
368416 return;
369417 } else if (input === 'I') {
370418 //alert('ya');
371419 print("Your score is 7.");
372 this.pause();
420 this.pause('statePrompt');
373421 return;
374422 } else if (input === 'A' && this.cans > 0) {
375423 this.cans--;
410458 if (this.codliver > 0) this.codliver = 1;
411459 if (this.batbgon > 0) this.batbgon = 1;
412460 }
413 this.pause();
461 this.pause('statePrompt');
462 return;
414463 } else if (input === 'D' && room.guano > 0) {
415464 this.ustink += d(3,3);
416465 room.guano--;
418467 if (d(1,6) == 1) { room.cans++; }
419468 if (d(1,12) == 1) { room.tokens++; }
420469 print("\nEw. You now stink so bad that you can't smell anything but yourself.\n");
421 this.pause();
470 this.pause('statePrompt');
422471 return;
423472 } else if (input === 'P') {
424473 this.arrows += room.arrows; room.arrows = 0;
438487
439488 this.moveWumpi();
440489
441 this.show();
442 this.ask();
443 };
444
445 this.moveWumpi = function() {
446 var self = this;
447 var print = function(str) {
448 self.tty.write(str);
449 };
450
451 for (var i = 0; i < this.wumpi.length; i++) {
452 var wumpus = this.wumpi[i];
453 if (wumpus.room === 0) {
454 if (d(1, 5) === 1) {
455 // restart wumpus
456 wumpus.room = d(1, 100);
457 while (wumpus.room === this.roomNo) {
458 wumpus.room = d(1, 100);
459 }
460 wumpus.asleep = false;
461 }
462 continue;
463 }
464 if (wumpus.asleep) {
465 if (d(1, 4) === 1) {
466 wumpus.asleep = false;
467 if (d(1, 5) !== 1) {
468 this.rooms[wumpus.room].guano++;
469 }
470 }
471 } else {
472 if (d(1, 3) === 1) {
473 var dest = this.rooms[wumpus.room].exits[d(1,3)-1];
474 if (dest !== this.roomNo || !this.moved) {
475 wumpus.room = dest;
476 if (dest === this.roomNo) {
477 print("From around a corner, a hungry-looking Wumpus appears!!\n");
478 this.pause();
479 }
480 }
481 }
482 if (d(1,8) === 1) { wumpus.asleep = true; }
483 if (d(1,8) === 1) { this.rooms[wumpus.room].guano++; }
484 }
485 }
490 if (this.show()) {
491 this.ask();
492 }
493 };
494
495 this.handleInput = function(input) {
496 this[this.gameState](input);
486497 };
487498 };