git @ Cat's Eye Technologies Super-Wumpus-Land / 874bf96
Splash screen and partial scorecard. catseye 10 years ago
1 changed file(s) with 82 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
44 n--;
55 }
66 return c;
7 }
8
9 function rep(ch, num) {
10 s = "";
11 for (var i = 0; i < num; i ++) {
12 s += ch;
13 }
14 return s;
15 }
16
17 function rjust(str, width) {
18 if (str.length >= width) return str;
19 return rep(' ', width - str.length) + str;
720 }
821
922 Room = function() {
133146 this.roomNo = d(1,100);
134147 this.arrows = 1;
135148
136 tty.write("SUPER WUMPUS LAND\n\n");
149 this.splash();
137150 this.pause('statePrompt');
138151 };
152
153 this.splash = function() {
154 this.tty.reset();
155 var self = this;
156 var print = function(str) {
157 self.tty.write(str);
158 };
159 print(rep('*', 72) + "\n");
160 for (var i = 1; i <= 20; i++) {
161 if (i === 6)
162 print("* S U P E R W U M P U S L A N D *\n");
163 else if (i === 7)
164 print("* --------- ----------- ------- *\n");
165 else if (i === 9)
166 print("* v1.1 (Javascript) *\n");
167 else if (i === 14)
168 print("* by Chris Pressey, Cat's Eye Technologies *\n");
169 else if (i === 16)
170 print("* Based on an original game by Gregory Yob *\n");
171 else
172 print("*" + rep(' ', 70) + "*\n");
173 }
174 print(rep('*', 72) + "\n");
175 };
176
177 this.score = function() {
178 this.tty.reset();
179 var self = this;
180 var print = function(str) {
181 self.tty.write(str);
182 };
183 print("Scorecard for " + this.name + "\n");
184 print(rep('=', 14 + this.name.length) + "\n\n");
185
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
139218
140219 this.pause = function(nextState) {
141220 this.tty.write("\n[Press ENTER to continue.] ");
155234
156235 this.visited[this.roomNo] = 1;
157236 print(desc + "\n");
158 for (var i = 0; i < desc.length; i++) {
159 print('-');
160 }
237 print(rep('-', desc.length));
161238 print("\n\n");
162239
163240 if (room.arrows === 1) {
551628 this.pause('stateGameOver');
552629 return;
553630 } else if (input === 'I') {
554 //alert('ya');
555 print("Your score is 7.");
631 this.score();
556632 this.pause('statePrompt');
557633 return;
558634 } else if (input === 'A' && this.cans > 0) {