Rev 1538 | Rev 1590 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1538 | Rev 1584 | ||
---|---|---|---|
1 | /* $OpenBSD: tetris.c,v 1.21 2006/04/20 03:24:12 ray Exp $ */ |
1 | /* $OpenBSD: tetris.c,v 1.21 2006/04/20 03:24:12 ray Exp $ */ |
2 | /* $NetBSD: tetris.c,v 1.2 1995/04/22 07:42:47 cgd Exp $ */ |
2 | /* $NetBSD: tetris.c,v 1.2 1995/04/22 07:42:47 cgd Exp $ */ |
3 | 3 | ||
4 | /*- |
4 | /*- |
5 | * Copyright (c) 1992, 1993 |
5 | * Copyright (c) 1992, 1993 |
6 | * The Regents of the University of California. All rights reserved. |
6 | * The Regents of the University of California. All rights reserved. |
7 | * |
7 | * |
8 | * This code is derived from software contributed to Berkeley by |
8 | * This code is derived from software contributed to Berkeley by |
9 | * Chris Torek and Darren F. Provine. |
9 | * Chris Torek and Darren F. Provine. |
10 | * |
10 | * |
11 | * Redistribution and use in source and binary forms, with or without |
11 | * Redistribution and use in source and binary forms, with or without |
12 | * modification, are permitted provided that the following conditions |
12 | * modification, are permitted provided that the following conditions |
13 | * are met: |
13 | * are met: |
14 | * 1. Redistributions of source code must retain the above copyright |
14 | * 1. Redistributions of source code must retain the above copyright |
15 | * notice, this list of conditions and the following disclaimer. |
15 | * notice, this list of conditions and the following disclaimer. |
16 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * 2. Redistributions in binary form must reproduce the above copyright |
17 | * notice, this list of conditions and the following disclaimer in the |
17 | * notice, this list of conditions and the following disclaimer in the |
18 | * documentation and/or other materials provided with the distribution. |
18 | * documentation and/or other materials provided with the distribution. |
19 | * 3. Neither the name of the University nor the names of its contributors |
19 | * 3. Neither the name of the University nor the names of its contributors |
20 | * may be used to endorse or promote products derived from this software |
20 | * may be used to endorse or promote products derived from this software |
21 | * without specific prior written permission. |
21 | * without specific prior written permission. |
22 | * |
22 | * |
23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
33 | * SUCH DAMAGE. |
33 | * SUCH DAMAGE. |
34 | * |
34 | * |
35 | * @(#)tetris.c 8.1 (Berkeley) 5/31/93 |
35 | * @(#)tetris.c 8.1 (Berkeley) 5/31/93 |
36 | */ |
36 | */ |
37 | 37 | ||
38 | #ifndef lint |
38 | #ifndef lint |
39 | static const char copyright[] = |
39 | static const char copyright[] = |
40 | "@(#) Copyright (c) 1992, 1993\n\ |
40 | "@(#) Copyright (c) 1992, 1993\n\ |
41 | The Regents of the University of California. All rights reserved.\n"; |
41 | The Regents of the University of California. All rights reserved.\n"; |
42 | #endif /* not lint */ |
42 | #endif /* not lint */ |
43 | 43 | ||
44 | /* |
44 | /* |
45 | * Tetris (or however it is spelled). |
45 | * Tetris (or however it is spelled). |
46 | */ |
46 | */ |
47 | 47 | ||
48 | #include <sys/time.h> |
48 | #include <sys/time.h> |
49 | #include <sys/types.h> |
49 | #include <sys/types.h> |
50 | 50 | ||
51 | #include <err.h> |
51 | #include <err.h> |
52 | #include <stdio.h> |
52 | #include <stdio.h> |
53 | #include <stdlib.h> |
53 | #include <stdlib.h> |
54 | #include <string.h> |
54 | #include <string.h> |
55 | #include <unistd.h> |
55 | #include <unistd.h> |
56 | 56 | ||
57 | #include "input.h" |
57 | #include "input.h" |
58 | #include "scores.h" |
58 | #include "scores.h" |
59 | #include "screen.h" |
59 | #include "screen.h" |
60 | #include "tetris.h" |
60 | #include "tetris.h" |
61 | 61 | ||
62 | cell board[B_SIZE]; |
62 | cell board[B_SIZE]; |
63 | int Rows, Cols; |
63 | int Rows, Cols; |
64 | const struct shape *curshape; |
64 | const struct shape *curshape; |
65 | const struct shape *nextshape; |
65 | const struct shape *nextshape; |
66 | long fallrate; |
66 | long fallrate; |
67 | int score; |
67 | int score; |
68 | //gid_t gid, egid; |
68 | //gid_t gid, egid; |
69 | char key_msg[100]; |
69 | char key_msg[100]; |
70 | int showpreview, classic; |
70 | int showpreview, classic; |
71 | 71 | ||
72 | static void elide(void); |
72 | static void elide(void); |
73 | static void setup_board(void); |
73 | static void setup_board(void); |
74 | const struct shape *randshape(void); |
74 | const struct shape *randshape(void); |
75 | void onintr(int); |
75 | void onintr(int); |
76 | void usage(void); |
76 | void usage(void); |
77 | 77 | ||
78 | /* |
78 | /* |
79 | * Set up the initial board. The bottom display row is completely set, |
79 | * Set up the initial board. The bottom display row is completely set, |
80 | * along with another (hidden) row underneath that. Also, the left and |
80 | * along with another (hidden) row underneath that. Also, the left and |
81 | * right edges are set. |
81 | * right edges are set. |
82 | */ |
82 | */ |
83 | static void |
83 | static void |
84 | setup_board(void) |
84 | setup_board(void) |
85 | { |
85 | { |
86 | int i; |
86 | int i; |
87 | cell *p; |
87 | cell *p; |
88 | 88 | ||
89 | p = board; |
89 | p = board; |
90 | for (i = B_SIZE; i; i--) |
90 | for (i = B_SIZE; i; i--) |
91 | *p++ = i <= (2 * B_COLS) || (i % B_COLS) < 2; |
91 | *p++ = i <= (2 * B_COLS) || (i % B_COLS) < 2; |
92 | } |
92 | } |
93 | 93 | ||
94 | /* |
94 | /* |
95 | * Elide any full active rows. |
95 | * Elide any full active rows. |
96 | */ |
96 | */ |
97 | static void |
97 | static void |
98 | elide(void) |
98 | elide(void) |
99 | { |
99 | { |
100 | int rows = 0; |
100 | int rows = 0; |
101 | int i, j, base; |
101 | int i, j, base; |
102 | cell *p; |
102 | cell *p; |
103 | 103 | ||
104 | for (i = A_FIRST; i < A_LAST; i++) { |
104 | for (i = A_FIRST; i < A_LAST; i++) { |
105 | base = i * B_COLS + 1; |
105 | base = i * B_COLS + 1; |
106 | p = &board[base]; |
106 | p = &board[base]; |
107 | for (j = B_COLS - 2; *p++ != 0;) { |
107 | for (j = B_COLS - 2; *p++ != 0;) { |
108 | if (--j <= 0) { |
108 | if (--j <= 0) { |
109 | /* this row is to be elided */ |
109 | /* this row is to be elided */ |
110 | rows++; |
110 | rows++; |
111 | memset(&board[base], 0, B_COLS - 2); |
111 | memset(&board[base], 0, B_COLS - 2); |
112 | scr_update(); |
112 | scr_update(); |
113 | tsleep(); |
113 | tsleep(); |
114 | while (--base != 0) |
114 | while (--base != 0) |
115 | board[base + B_COLS] = board[base]; |
115 | board[base + B_COLS] = board[base]; |
116 | scr_update(); |
116 | scr_update(); |
117 | tsleep(); |
117 | tsleep(); |
118 | break; |
118 | break; |
119 | } |
119 | } |
120 | } |
120 | } |
121 | } |
121 | } |
122 | switch (rows) { |
122 | switch (rows) { |
123 | case 1: |
123 | case 1: |
124 | score += 10; |
124 | score += 10; |
125 | break; |
125 | break; |
126 | case 2: |
126 | case 2: |
127 | score += 30; |
127 | score += 30; |
128 | break; |
128 | break; |
129 | case 3: |
129 | case 3: |
130 | score += 70; |
130 | score += 70; |
131 | break; |
131 | break; |
132 | case 4: |
132 | case 4: |
133 | score += 150; |
133 | score += 150; |
134 | break; |
134 | break; |
135 | default: |
135 | default: |
136 | break; |
136 | break; |
137 | } |
137 | } |
138 | } |
138 | } |
139 | 139 | ||
140 | const struct shape * |
140 | const struct shape * |
141 | randshape(void) |
141 | randshape(void) |
142 | { |
142 | { |
143 | const struct shape *tmp; |
143 | const struct shape *tmp; |
144 | int i, j; |
144 | int i, j; |
145 | 145 | ||
146 | tmp = &shapes[random() % 7]; |
146 | tmp = &shapes[random() % 7]; |
147 | j = random() % 4; |
147 | j = random() % 4; |
148 | for (i = 0; i < j; i++) |
148 | for (i = 0; i < j; i++) |
149 | tmp = &shapes[classic? tmp->rotc : tmp->rot]; |
149 | tmp = &shapes[classic? tmp->rotc : tmp->rot]; |
150 | return (tmp); |
150 | return (tmp); |
151 | } |
151 | } |
152 | 152 | ||
153 | static void srandomdev(void) |
153 | static void srandomdev(void) |
154 | { |
154 | { |
155 | struct timeval tv; |
155 | struct timeval tv; |
156 | 156 | ||
157 | gettimeofday(&tv, NULL); |
157 | gettimeofday(&tv, NULL); |
158 | srandom(tv.tv_sec + tv.tv_usec / 100000); |
158 | srandom(tv.tv_sec + tv.tv_usec / 100000); |
159 | } |
159 | } |
160 | 160 | ||
161 | int |
161 | int |
162 | main(int argc, char *argv[]) |
162 | main(int argc, char *argv[]) |
163 | { |
163 | { |
164 | int pos, c; |
164 | int pos, c; |
165 | char *keys; |
165 | char *keys; |
166 | int level = 2; |
166 | int level = 2; |
167 | char key_write[6][10]; |
167 | char key_write[6][10]; |
168 | const char *errstr; |
168 | const char *errstr; |
169 | int ch, i, j; |
169 | int ch, i, j; |
170 | 170 | ||
171 | keys = "jkl pq"; |
171 | keys = "jkl pq"; |
172 | 172 | ||
173 | // gid = getgid(); |
173 | // gid = getgid(); |
174 | // egid = getegid(); |
174 | // egid = getegid(); |
175 | // setegid(gid); |
175 | // setegid(gid); |
176 | 176 | ||
177 | classic = showpreview = 0; |
177 | classic = showpreview = 0; |
178 | 178 | ||
179 | /* while ((ch = getopt(argc, argv, "ck:l:ps")) != -1) */ |
179 | /* while ((ch = getopt(argc, argv, "ck:l:ps")) != -1) */ |
180 | /* switch(ch) { */ |
180 | /* switch(ch) { */ |
181 | /* case 'c': */ |
181 | /* case 'c': */ |
182 | /* /\* */ |
182 | /* /\* */ |
183 | /* * this means: */ |
183 | /* * this means: */ |
184 | /* * - rotate the other way; */ |
184 | /* * - rotate the other way; */ |
185 | /* * - no reverse video. */ |
185 | /* * - no reverse video. */ |
186 | /* *\/ */ |
186 | /* *\/ */ |
187 | /* classic = 1; */ |
187 | /* classic = 1; */ |
188 | /* break; */ |
188 | /* break; */ |
189 | /* case 'k': */ |
189 | /* case 'k': */ |
190 | /* if (strlen(keys = optarg) != 6) */ |
190 | /* if (strlen(keys = optarg) != 6) */ |
191 | /* usage(); */ |
191 | /* usage(); */ |
192 | /* break; */ |
192 | /* break; */ |
193 | /* case 'l': */ |
193 | /* case 'l': */ |
194 | /* level = (int)strtonum(optarg, MINLEVEL, MAXLEVEL, */ |
194 | /* level = (int)strtonum(optarg, MINLEVEL, MAXLEVEL, */ |
195 | /* &errstr); */ |
195 | /* &errstr); */ |
196 | /* if (errstr) */ |
196 | /* if (errstr) */ |
197 | /* errx(1, "level must be from %d to %d", */ |
197 | /* errx(1, "level must be from %d to %d", */ |
198 | /* MINLEVEL, MAXLEVEL); */ |
198 | /* MINLEVEL, MAXLEVEL); */ |
199 | /* break; */ |
199 | /* break; */ |
200 | /* case 'p': */ |
200 | /* case 'p': */ |
201 | /* showpreview = 1; */ |
201 | /* showpreview = 1; */ |
202 | /* break; */ |
202 | /* break; */ |
203 | /* case 's': */ |
203 | /* case 's': */ |
204 | /* showscores(0); */ |
204 | /* showscores(0); */ |
205 | /* exit(0); */ |
205 | /* exit(0); */ |
206 | /* default: */ |
206 | /* default: */ |
207 | /* usage(); */ |
207 | /* usage(); */ |
208 | /* } */ |
208 | /* } */ |
209 | 209 | ||
210 | /* argc -= optind; */ |
210 | /* argc -= optind; */ |
211 | /* argv += optind; */ |
211 | /* argv += optind; */ |
212 | 212 | ||
213 | /* if (argc) */ |
213 | /* if (argc) */ |
214 | /* usage(); */ |
214 | /* usage(); */ |
215 | 215 | ||
216 | fallrate = 1000000 / level; |
216 | fallrate = 1000000 / level; |
217 | 217 | ||
218 | for (i = 0; i <= 5; i++) { |
218 | for (i = 0; i <= 5; i++) { |
219 | for (j = i+1; j <= 5; j++) { |
219 | for (j = i+1; j <= 5; j++) { |
220 | if (keys[i] == keys[j]) |
220 | if (keys[i] == keys[j]) |
221 | errx(1, "duplicate command keys specified."); |
221 | errx(1, "duplicate command keys specified."); |
222 | } |
222 | } |
223 | if (keys[i] == ' ') |
223 | if (keys[i] == ' ') |
224 | strncpy(key_write[i], "<space>", sizeof key_write[i]); |
224 | strncpy(key_write[i], "<space>", sizeof key_write[i]); |
225 | else { |
225 | else { |
226 | key_write[i][0] = keys[i]; |
226 | key_write[i][0] = keys[i]; |
227 | key_write[i][1] = '\0'; |
227 | key_write[i][1] = '\0'; |
228 | } |
228 | } |
229 | } |
229 | } |
230 | 230 | ||
231 | snprintf(key_msg, sizeof key_msg, |
231 | snprintf(key_msg, sizeof key_msg, |
232 | "%s - left %s - rotate %s - right %s - drop %s - pause %s - quit", |
232 | "%s - left %s - rotate %s - right %s - drop %s - pause %s - quit", |
233 | key_write[0], key_write[1], key_write[2], key_write[3], |
233 | key_write[0], key_write[1], key_write[2], key_write[3], |
234 | key_write[4], key_write[5]); |
234 | key_write[4], key_write[5]); |
235 | 235 | newgame: |
|
236 | scr_init(); |
236 | scr_init(); |
237 | setup_board(); |
237 | setup_board(); |
238 | 238 | ||
239 | srandomdev(); |
239 | srandomdev(); |
240 | scr_set(); |
240 | scr_set(); |
241 | 241 | ||
242 | pos = A_FIRST*B_COLS + (B_COLS/2)-1; |
242 | pos = A_FIRST*B_COLS + (B_COLS/2)-1; |
243 | nextshape = randshape(); |
243 | nextshape = randshape(); |
244 | curshape = randshape(); |
244 | curshape = randshape(); |
245 | 245 | ||
246 | scr_msg(key_msg, 1); |
246 | scr_msg(key_msg, 1); |
247 | 247 | ||
248 | for (;;) { |
248 | for (;;) { |
249 | place(curshape, pos, 1); |
249 | place(curshape, pos, 1); |
250 | scr_update(); |
250 | scr_update(); |
251 | place(curshape, pos, 0); |
251 | place(curshape, pos, 0); |
252 | c = tgetchar(); |
252 | c = tgetchar(); |
253 | if (c < 0) { |
253 | if (c < 0) { |
254 | /* |
254 | /* |
255 | * Timeout. Move down if possible. |
255 | * Timeout. Move down if possible. |
256 | */ |
256 | */ |
257 | if (fits_in(curshape, pos + B_COLS)) { |
257 | if (fits_in(curshape, pos + B_COLS)) { |
258 | pos += B_COLS; |
258 | pos += B_COLS; |
259 | continue; |
259 | continue; |
260 | } |
260 | } |
261 | 261 | ||
262 | /* |
262 | /* |
263 | * Put up the current shape `permanently', |
263 | * Put up the current shape `permanently', |
264 | * bump score, and elide any full rows. |
264 | * bump score, and elide any full rows. |
265 | */ |
265 | */ |
266 | place(curshape, pos, 1); |
266 | place(curshape, pos, 1); |
267 | score++; |
267 | score++; |
268 | elide(); |
268 | elide(); |
269 | 269 | ||
270 | /* |
270 | /* |
271 | * Choose a new shape. If it does not fit, |
271 | * Choose a new shape. If it does not fit, |
272 | * the game is over. |
272 | * the game is over. |
273 | */ |
273 | */ |
274 | curshape = nextshape; |
274 | curshape = nextshape; |
275 | nextshape = randshape(); |
275 | nextshape = randshape(); |
276 | pos = A_FIRST*B_COLS + (B_COLS/2)-1; |
276 | pos = A_FIRST*B_COLS + (B_COLS/2)-1; |
277 | if (!fits_in(curshape, pos)) |
277 | if (!fits_in(curshape, pos)) |
278 | break; |
278 | break; |
279 | continue; |
279 | continue; |
280 | } |
280 | } |
281 | 281 | ||
282 | /* |
282 | /* |
283 | * Handle command keys. |
283 | * Handle command keys. |
284 | */ |
284 | */ |
285 | if (c == keys[5]) { |
285 | if (c == keys[5]) { |
286 | /* quit */ |
286 | /* quit */ |
287 | break; |
287 | break; |
288 | } |
288 | } |
289 | if (c == keys[4]) { |
289 | if (c == keys[4]) { |
290 | static char msg[] = |
290 | static char msg[] = |
291 | "paused - press RETURN to continue"; |
291 | "paused - press RETURN to continue"; |
292 | 292 | ||
293 | place(curshape, pos, 1); |
293 | place(curshape, pos, 1); |
294 | do { |
294 | do { |
295 | scr_update(); |
295 | scr_update(); |
296 | scr_msg(key_msg, 0); |
296 | scr_msg(key_msg, 0); |
297 | scr_msg(msg, 1); |
297 | scr_msg(msg, 1); |
298 | // (void) fflush(stdout); |
298 | // (void) fflush(stdout); |
299 | } while (rwait((struct timeval *)NULL) == -1); |
299 | } while (rwait((struct timeval *)NULL) == -1); |
300 | scr_msg(msg, 0); |
300 | scr_msg(msg, 0); |
301 | scr_msg(key_msg, 1); |
301 | scr_msg(key_msg, 1); |
302 | place(curshape, pos, 0); |
302 | place(curshape, pos, 0); |
303 | continue; |
303 | continue; |
304 | } |
304 | } |
305 | if (c == keys[0]) { |
305 | if (c == keys[0]) { |
306 | /* move left */ |
306 | /* move left */ |
307 | if (fits_in(curshape, pos - 1)) |
307 | if (fits_in(curshape, pos - 1)) |
308 | pos--; |
308 | pos--; |
309 | continue; |
309 | continue; |
310 | } |
310 | } |
311 | if (c == keys[1]) { |
311 | if (c == keys[1]) { |
312 | /* turn */ |
312 | /* turn */ |
313 | const struct shape *new = &shapes[ |
313 | const struct shape *new = &shapes[ |
314 | classic? curshape->rotc : curshape->rot]; |
314 | classic? curshape->rotc : curshape->rot]; |
315 | 315 | ||
316 | if (fits_in(new, pos)) |
316 | if (fits_in(new, pos)) |
317 | curshape = new; |
317 | curshape = new; |
318 | continue; |
318 | continue; |
319 | } |
319 | } |
320 | if (c == keys[2]) { |
320 | if (c == keys[2]) { |
321 | /* move right */ |
321 | /* move right */ |
322 | if (fits_in(curshape, pos + 1)) |
322 | if (fits_in(curshape, pos + 1)) |
323 | pos++; |
323 | pos++; |
324 | continue; |
324 | continue; |
325 | } |
325 | } |
326 | if (c == keys[3]) { |
326 | if (c == keys[3]) { |
327 | /* move to bottom */ |
327 | /* move to bottom */ |
328 | while (fits_in(curshape, pos + B_COLS)) { |
328 | while (fits_in(curshape, pos + B_COLS)) { |
329 | pos += B_COLS; |
329 | pos += B_COLS; |
330 | score++; |
330 | score++; |
331 | } |
331 | } |
332 | continue; |
332 | continue; |
333 | } |
333 | } |
334 | if (c == '\f') { |
334 | if (c == '\f') { |
335 | scr_clear(); |
335 | scr_clear(); |
336 | scr_msg(key_msg, 1); |
336 | scr_msg(key_msg, 1); |
337 | } |
337 | } |
338 | } |
338 | } |
339 | 339 | ||
340 | scr_clear(); |
340 | scr_clear(); |
341 | scr_end(); |
341 | scr_end(); |
342 | 342 | ||
343 | if (showpreview == 0) |
343 | if (showpreview == 0) |
344 | (void)printf("Your score: %d point%s x level %d = %d\n", |
344 | (void)printf("Your score: %d point%s x level %d = %d\n", |
345 | score, score == 1 ? "" : "s", level, score * level); |
345 | score, score == 1 ? "" : "s", level, score * level); |
346 | else { |
346 | else { |
347 | /* (void)printf("Your score: %d point%s x level %d x preview penalty %0.3f = %d\n", */ |
347 | /* (void)printf("Your score: %d point%s x level %d x preview penalty %0.3f = %d\n", */ |
348 | /* score, score == 1 ? "" : "s", level, (double)PRE_PENALTY, */ |
348 | /* score, score == 1 ? "" : "s", level, (double)PRE_PENALTY, */ |
349 | /* (int)(score * level * PRE_PENALTY)); */ |
349 | /* (int)(score * level * PRE_PENALTY)); */ |
350 | /* score = score * PRE_PENALTY; */ |
350 | /* score = score * PRE_PENALTY; */ |
351 | } |
351 | } |
352 | savescore(level); |
352 | savescore(level); |
353 | 353 | ||
- | 354 | showscores(level); |
|
- | 355 | ||
354 | printf("\nHit RETURN to see high scores, ^C to skip.\n"); |
356 | printf("\nHit 's' to new game, 'q' to quit.\n"); |
355 | 357 | ||
- | 358 | ||
- | 359 | while (i = getchar()) { |
|
- | 360 | if (i == 's') |
|
- | 361 | goto newgame; |
|
- | 362 | if (i == 'q') |
|
- | 363 | break; |
|
- | 364 | } |
|
- | 365 | ||
- | 366 | scr_clear(); |
|
- | 367 | printf("\n\n\n\t\tGame over.\n"); |
|
- | 368 | /* |
|
356 | while ((i = getchar()) != '\n') |
369 | while ((i = getchar()) != '\n') |
357 | if (i == EOF) |
370 | if (i == EOF) |
358 | break; |
371 | break |
359 | - | ||
360 | showscores(level); |
- | |
361 | 372 | */ |
|
362 | exit(0); |
373 | exit(0); |
363 | } |
374 | } |
364 | 375 | ||
365 | /* void */ |
376 | /* void */ |
366 | /* onintr(int signo) */ |
377 | /* onintr(int signo) */ |
367 | /* { */ |
378 | /* { */ |
368 | /* scr_clear(); /\* XXX signal race *\/ */ |
379 | /* scr_clear(); /\* XXX signal race *\/ */ |
369 | /* scr_end(); /\* XXX signal race *\/ */ |
380 | /* scr_end(); /\* XXX signal race *\/ */ |
370 | /* _exit(0); */ |
381 | /* _exit(0); */ |
371 | /* } */ |
382 | /* } */ |
372 | 383 | ||
373 | void |
384 | void |
374 | usage(void) |
385 | usage(void) |
375 | { |
386 | { |
376 | (void)fprintf(stderr, "usage: tetris [-ps] [-k keys] [-l level]\n"); |
387 | (void)fprintf(stderr, "usage: tetris [-ps] [-k keys] [-l level]\n"); |
377 | exit(1); |
388 | exit(1); |
378 | } |
389 | } |
379 | 390 |