Finish implementing score and subway.
catseye
10 years ago
15 | 15 | } |
16 | 16 | |
17 | 17 | function rjust(str, width) { |
18 | str = '' + str; | |
18 | 19 | if (str.length >= width) return str; |
19 | 20 | return rep(' ', width - str.length) + str; |
20 | 21 | } |
63 | 64 | this.grip = 0; |
64 | 65 | this.ustink = 0; |
65 | 66 | |
66 | this.subway = false; | |
67 | this.subway = 0; | |
68 | this.subwayTurns = 0; | |
67 | 69 | |
68 | 70 | this.skip = false; |
69 | 71 | this.moved = false; |
161 | 163 | if (i === 6) |
162 | 164 | print("* S U P E R W U M P U S L A N D *\n"); |
163 | 165 | else if (i === 7) |
164 | print("* --------- ----------- ------- *\n"); | |
166 | print("* --------- ----------- ------- *\n"); | |
165 | 167 | else if (i === 9) |
166 | print("* v1.1 (Javascript) *\n"); | |
168 | print("* v1.1 (Javascript) *\n"); | |
167 | 169 | else if (i === 14) |
168 | print("* by Chris Pressey, Cat's Eye Technologies *\n"); | |
170 | print("* by Chris Pressey, Cat's Eye Technologies *\n"); | |
169 | 171 | else if (i === 16) |
170 | print("* Based on an original game by Gregory Yob *\n"); | |
172 | print("* Based on an original game by Gregory Yob *\n"); | |
171 | 173 | else |
172 | print("*" + rep(' ', 70) + "*\n"); | |
174 | print("*" + rep(' ', 70) + "*\n"); | |
173 | 175 | } |
174 | 176 | print(rep('*', 72) + "\n"); |
175 | 177 | }; |
183 | 185 | print("Scorecard for " + this.name + "\n"); |
184 | 186 | print(rep('=', 14 + this.name.length) + "\n\n"); |
185 | 187 | |
186 | var h1 = rjust('' + this.hides, 3); | |
187 | var s1 = rjust('' + (this.hides * 25), 9); | |
188 | print("Wumpus Hides " + h1 + " x 25 = " + s1 + "\n"); | |
189 | ||
190 | var h2 = rjust('' + this.arrows, 3); | |
191 | var s2 = rjust('' + (this.arrows * 2), 9); | |
192 | print("Arrows Remaining " + h2 + " x 2 = " + s2 + "\n"); | |
193 | ||
194 | var h4 = rjust('' + this.cans, 3); | |
195 | var s4 = rjust('' + (this.cans * 3), 9); | |
196 | print("Aerosol Cans " + h4 + " x 3 = " + s4 + "\n"); | |
197 | ||
198 | var h5 = rjust('' + this.tokens, 3); | |
199 | var s5 = rjust('' + (this.tokens * 5), 9); | |
200 | print("Subway Tokens " + h5 + " x 5 = " + s5 + "\n"); | |
201 | ||
202 | /* | |
203 | my $h3 = 0; | |
204 | for (my $i = 1; $i <= 100; $i++) | |
205 | { | |
206 | $h3++ if $visited[$i]; | |
207 | } | |
208 | $h3 = sprintf("%3d", $h3); | |
209 | my $s3 = sprintf("%9d", $h3); | |
210 | print "Locations Visited $h3 x 1 = $s3\n"; | |
211 | ||
212 | my $tot = sprintf("%9d", $s1 + $s2 + $s3 + $s4 + $s5); | |
213 | print " ---------\n"; | |
214 | print "Total $tot\n\n"; | |
215 | */ | |
216 | }; | |
217 | ||
188 | var scoreHides = this.hides * 25; | |
189 | print("Wumpus Hides " + | |
190 | rjust(this.hides, 3) + | |
191 | " x 25 = " + | |
192 | rjust(scoreHides, 9) + | |
193 | "\n"); | |
194 | ||
195 | var scoreArrows = this.arrows * 2; | |
196 | print("Arrows Remaining " + | |
197 | rjust(this.arrows, 3) + | |
198 | " x 2 = " + | |
199 | rjust(scoreArrows, 9) + | |
200 | "\n"); | |
201 | ||
202 | var scoreCans = this.cans * 3; | |
203 | print("Aerosol Cans " + | |
204 | rjust(this.cans, 3) + | |
205 | " x 3 = " + | |
206 | rjust(scoreCans, 9) + | |
207 | "\n"); | |
208 | ||
209 | var scoreTokens = this.tokens * 5; | |
210 | print("Subway Tokens " + | |
211 | rjust(this.tokens, 3) + | |
212 | " x 5 = " + | |
213 | rjust(scoreTokens, 9) + | |
214 | "\n"); | |
215 | ||
216 | var scoreLocations = 0; | |
217 | for (var i = 1; i <= 100; i++) { | |
218 | if (this.visited[i]) scoreLocations++; | |
219 | } | |
220 | print("Locations Visited " + | |
221 | rjust(scoreLocations, 3) + | |
222 | " x 1 = " + | |
223 | rjust(scoreLocations, 9) + | |
224 | "\n"); | |
225 | ||
226 | var scoreTotal = scoreHides + scoreArrows + scoreCans + scoreTokens + scoreLocations; | |
227 | print(" ---------\n"); | |
228 | print("Total " + rjust(scoreTotal, 9) + "\n\n"); | |
229 | }; | |
218 | 230 | |
219 | 231 | this.pause = function(nextState) { |
220 | 232 | this.tty.write("\n[Press ENTER to continue.] "); |
277 | 289 | for (var i = 0; i < this.wumpi.length; i++) { |
278 | 290 | if (this.wumpi[i].room === this.roomNo) { |
279 | 291 | if (!this.wumpi[i].asleep) { |
280 | if (this.subway) { | |
292 | if (this.subway > 0) { | |
281 | 293 | print("* Right outside the train window is a Wumpus!\n"); |
282 | 294 | } else if (this.camo) { |
283 | 295 | print("* Good thing the Wumpus here can't see you.\n"); |
306 | 318 | } |
307 | 319 | |
308 | 320 | if (room.bats > 0) { |
309 | if (this.subway) { | |
321 | if (this.subway > 0) { | |
310 | 322 | print("* Super Bats flutter out of the path of the subway train.\n"); |
311 | 323 | } else if (this.batbgon > 0) { |
312 | 324 | print("* Super Bats in this location stay well away from your awful stench!\n"); |
329 | 341 | } |
330 | 342 | |
331 | 343 | if (room.pits > 0) { |
332 | if (this.subway) { | |
344 | if (this.subway > 0) { | |
333 | 345 | print("* The subway rails take a curving path around a bottomless pit here.\n"); |
334 | 346 | } else if (this.grip > 0) { |
335 | 347 | print("* You deftly stick to the edge of the bottomless pit!\n"); |
592 | 604 | this.pause('statePrompt'); |
593 | 605 | } else { |
594 | 606 | this.tokens--; |
607 | this.subway = dest; | |
608 | this.subwayTurns = 3; | |
595 | 609 | print("\n \"All aboard!\"\n\n"); |
610 | this.pause('stateRidingSubway'); | |
611 | } | |
612 | }; | |
613 | ||
614 | this.stateRidingSubway = function(input) { | |
615 | var self = this; | |
616 | var print = function(str) { | |
617 | self.tty.write(str); | |
618 | }; | |
619 | this.roomNo = d(1, 100); | |
620 | this.show(); | |
621 | this.subwayTurns--; | |
622 | if (this.subwayTurns === 0) { | |
623 | print("\n \"Next stop, " + this.subway + ", " + this.rooms[this.subway].desc + "...\"\n\n"); | |
624 | this.roomNo = this.subway; | |
596 | 625 | this.pause('statePrompt'); |
597 | /* | |
598 | sleep 2; | |
599 | for(my $q = 1; $q <= 3; $q++) { print ((' ' x $q) x $q . "...chug chug...\n"); sleep 1; } | |
600 | for(my $i = 1; $i <= 3; $i++) | |
601 | { | |
602 | $room = d(1,100); | |
603 | $subway = 1; | |
604 | show(); | |
605 | for(my $q = 1; $q <= 3; $q++) { print ((' ' x $i) x $q . "...chug chug...\n"); sleep 1; } | |
606 | $subway = 0; | |
607 | } | |
608 | print "\n \"Next stop, $r, $room[$r]->[0]...\""; | |
609 | sleep 3; | |
610 | $room = $r; | |
611 | */ | |
626 | } else { | |
627 | print("\n ...chug chug...\n\n"); | |
628 | this.pause('stateRidingSubway'); | |
612 | 629 | } |
613 | 630 | }; |
614 | 631 |