Rev 4268 | Rev 4565 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4268 | Rev 4515 | ||
|---|---|---|---|
| Line 34... | Line 34... | ||
| 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 | /** @addtogroup tetris Tetris |
38 | /** @addtogroup tetris Tetris |
| 39 | * @brief Tetris ported from OpenBSD |
39 | * @brief Tetris ported from OpenBSD |
| 40 | * @{ |
40 | * @{ |
| 41 | */ |
41 | */ |
| 42 | /** @file |
42 | /** @file |
| 43 | */ |
43 | */ |
| 44 | 44 | ||
| 45 | #ifndef lint |
- | |
| 46 | static const char copyright[] = |
45 | static const char copyright[] = |
| 47 | "@(#) Copyright (c) 1992, 1993\n\ |
46 | "@(#) Copyright (c) 1992, 1993\n" |
| 48 | The Regents of the University of California. All rights reserved.\n"; |
47 | "\tThe Regents of the University of California. All rights reserved.\n"; |
| 49 | #endif /* not lint */ |
- | |
| 50 | - | ||
| 51 | /* |
- | |
| 52 | * Tetris (or however it is spelled). |
- | |
| 53 | */ |
- | |
| 54 | 48 | ||
| 55 | #include <sys/time.h> |
49 | #include <sys/time.h> |
| 56 | #include <sys/types.h> |
50 | #include <sys/types.h> |
| 57 | - | ||
| 58 | #include <err.h> |
51 | #include <err.h> |
| 59 | #include <stdio.h> |
52 | #include <stdio.h> |
| 60 | #include <stdlib.h> |
53 | #include <stdlib.h> |
| 61 | #include <string.h> |
54 | #include <string.h> |
| 62 | #include <unistd.h> |
55 | #include <unistd.h> |
| - | 56 | #include <getopt.h> |
|
| 63 | 57 | ||
| 64 | #include "input.h" |
58 | #include "input.h" |
| 65 | #include "scores.h" |
59 | #include "scores.h" |
| 66 | #include "screen.h" |
60 | #include "screen.h" |
| 67 | #include "tetris.h" |
61 | #include "tetris.h" |
| 68 | 62 | ||
| 69 | cell board[B_SIZE]; |
63 | cell board[B_SIZE]; |
| - | 64 | ||
| - | 65 | int Rows; |
|
| 70 | int Rows, Cols; |
66 | int Cols; |
| - | 67 | ||
| 71 | const struct shape *curshape; |
68 | const struct shape *curshape; |
| 72 | const struct shape *nextshape; |
69 | const struct shape *nextshape; |
| - | 70 | ||
| 73 | long fallrate; |
71 | long fallrate; |
| 74 | int score; |
72 | int score; |
| 75 | //gid_t gid, egid; |
- | |
| 76 | char key_msg[100]; |
73 | char key_msg[100]; |
| 77 | int showpreview, classic; |
74 | int showpreview; |
| - | 75 | int classic; |
|
| 78 | 76 | ||
| 79 | static void elide(void); |
77 | static void elide(void); |
| 80 | static void setup_board(void); |
78 | static void setup_board(void); |
| 81 | const struct shape *randshape(void); |
79 | static const struct shape *randshape(void); |
| - | 80 | ||
| 82 | void onintr(int); |
81 | static void usage(void); |
| - | 82 | ||
| 83 | void usage(void); |
83 | static int firstgame = 1; |
| 84 | 84 | ||
| 85 | /* |
85 | /* |
| 86 | * Set up the initial board. The bottom display row is completely set, |
86 | * Set up the initial board. The bottom display row is completely set, |
| 87 | * along with another (hidden) row underneath that. Also, the left and |
87 | * along with another (hidden) row underneath that. Also, the left and |
| 88 | * right edges are set. |
88 | * right edges are set. |
| 89 | */ |
89 | */ |
| 90 | static void |
- | |
| 91 | setup_board(void) |
90 | static void setup_board(void) |
| 92 | { |
91 | { |
| 93 | int i; |
92 | int i; |
| 94 | cell *p; |
93 | cell *p = board; |
| 95 | 94 | ||
| 96 | p = board; |
- | |
| 97 | for (i = B_SIZE; i; i--) |
95 | for (i = B_SIZE; i; i--) |
| 98 | *p++ = i <= (2 * B_COLS) || (i % B_COLS) < 2; |
96 | *p++ = (i <= (2 * B_COLS) || (i % B_COLS) < 2) ? 0x0000ff : 0x000000; |
| 99 | } |
97 | } |
| 100 | 98 | ||
| 101 | /* |
99 | /* |
| 102 | * Elide any full active rows. |
100 | * Elide any full active rows. |
| 103 | */ |
101 | */ |
| 104 | static void |
- | |
| 105 | elide(void) |
102 | static void elide(void) |
| 106 | { |
103 | { |
| 107 | int rows = 0; |
104 | int rows = 0; |
| - | 105 | int i; |
|
| - | 106 | int j; |
|
| 108 | int i, j, base; |
107 | int base; |
| 109 | cell *p; |
108 | cell *p; |
| 110 | 109 | ||
| 111 | for (i = A_FIRST; i < A_LAST; i++) { |
110 | for (i = A_FIRST; i < A_LAST; i++) { |
| 112 | base = i * B_COLS + 1; |
111 | base = i * B_COLS + 1; |
| 113 | p = &board[base]; |
112 | p = &board[base]; |
| 114 | for (j = B_COLS - 2; *p++ != 0;) { |
113 | for (j = B_COLS - 2; *p++ != 0;) { |
| 115 | if (--j <= 0) { |
114 | if (--j <= 0) { |
| 116 | /* this row is to be elided */ |
115 | /* This row is to be elided */ |
| 117 | rows++; |
116 | rows++; |
| 118 | memset(&board[base], 0, B_COLS - 2); |
117 | memset(&board[base], 0, sizeof(cell) * (B_COLS - 2)); |
| - | 118 | ||
| 119 | scr_update(); |
119 | scr_update(); |
| 120 | tsleep(); |
120 | tsleep(); |
| - | 121 | ||
| 121 | while (--base != 0) |
122 | while (--base != 0) |
| 122 | board[base + B_COLS] = board[base]; |
123 | board[base + B_COLS] = board[base]; |
| - | 124 | ||
| 123 | scr_update(); |
125 | scr_update(); |
| 124 | tsleep(); |
126 | tsleep(); |
| - | 127 | ||
| 125 | break; |
128 | break; |
| 126 | } |
129 | } |
| 127 | } |
130 | } |
| 128 | } |
131 | } |
| - | 132 | ||
| 129 | switch (rows) { |
133 | switch (rows) { |
| 130 | case 1: |
134 | case 1: |
| 131 | score += 10; |
135 | score += 10; |
| 132 | break; |
136 | break; |
| 133 | case 2: |
137 | case 2: |
| Line 142... | Line 146... | ||
| 142 | default: |
146 | default: |
| 143 | break; |
147 | break; |
| 144 | } |
148 | } |
| 145 | } |
149 | } |
| 146 | 150 | ||
| 147 | const struct shape * |
151 | const struct shape *randshape(void) |
| 148 | randshape(void) |
- | |
| 149 | { |
152 | { |
| 150 | const struct shape *tmp; |
153 | const struct shape *tmp = &shapes[random() % 7]; |
| 151 | int i, j; |
154 | int i; |
| 152 | - | ||
| 153 | tmp = &shapes[random() % 7]; |
- | |
| 154 | j = random() % 4; |
155 | int j = random() % 4; |
| - | 156 | ||
| 155 | for (i = 0; i < j; i++) |
157 | for (i = 0; i < j; i++) |
| 156 | tmp = &shapes[classic? tmp->rotc : tmp->rot]; |
158 | tmp = &shapes[classic ? tmp->rotc : tmp->rot]; |
| - | 159 | ||
| 157 | return (tmp); |
160 | return (tmp); |
| 158 | } |
161 | } |
| 159 | 162 | ||
| 160 | static void srandomdev(void) |
163 | static void srandomdev(void) |
| 161 | { |
164 | { |
| 162 | struct timeval tv; |
165 | struct timeval tv; |
| 163 | 166 | ||
| 164 | gettimeofday(&tv, NULL); |
167 | gettimeofday(&tv, NULL); |
| 165 | srandom(tv.tv_sec + tv.tv_usec / 100000); |
168 | srandom(tv.tv_sec + tv.tv_usec / 100000); |
| 166 | } |
169 | } |
| 167 | 170 | ||
| 168 | static void tetris_menu_draw(int level) |
171 | static void tetris_menu_draw(int level) |
| 169 | { |
172 | { |
| 170 | clear_screen(); |
173 | clear_screen(); |
| 171 | moveto(5,10); |
174 | moveto(5, 10); |
| 172 | puts("Tetris\n\n"); |
175 | puts("Tetris\n\n"); |
| 173 | 176 | ||
| 174 | moveto(8,10); |
177 | moveto(8, 10); |
| 175 | printf("Level = %d (press keys 1 - 9 to change)",level); |
178 | printf("Level = %d (press keys 1 - 9 to change)", level); |
| 176 | moveto(9,10); |
179 | moveto(9, 10); |
| 177 | printf("Preview is %s (press 'p' to change)", (showpreview?"on ":"off")); |
180 | printf("Preview is %s (press 'p' to change)", (showpreview ? "on ": "off")); |
| 178 | moveto(12,10); |
181 | moveto(12, 10); |
| 179 | printf("Press 'h' to show hiscore table."); |
182 | printf("Press 'h' to show hiscore table."); |
| 180 | moveto(13,10); |
183 | moveto(13, 10); |
| 181 | printf("Press 's' to start game."); |
184 | printf("Press 's' to start game."); |
| 182 | moveto(14,10); |
185 | moveto(14, 10); |
| 183 | printf("Press 'q' to quit game."); |
186 | printf("Press 'q' to quit game."); |
| 184 | moveto(20,10); |
187 | moveto(20, 10); |
| 185 | printf("In game controls:"); |
188 | printf("In game controls:"); |
| 186 | moveto(21,0); |
189 | moveto(21, 0); |
| 187 | puts(key_msg); |
190 | puts(key_msg); |
| 188 | } |
191 | } |
| 189 | 192 | ||
| 190 | static int tetris_menu(int *level) |
193 | static int tetris_menu(int *level) |
| 191 | { |
194 | { |
| 192 | static int firstgame = 1; |
- | |
| 193 | int i; |
- | |
| 194 | /* if (showpreview == 0) |
- | |
| 195 | (void)printf("Your score: %d point%s x level %d = %d\n", |
- | |
| 196 | score, score == 1 ? "" : "s", level, score * level); |
- | |
| 197 | else { |
- | |
| 198 | (void)printf("Your score: %d point%s x level %d x preview penalty %0.3f = %d\n", |
- | |
| 199 | score, score == 1 ? "" : "s", level, (double)PRE_PENALTY, |
- | |
| 200 | (int)(score * level * PRE_PENALTY)); |
- | |
| 201 | score = score * PRE_PENALTY; |
- | |
| 202 | } |
- | |
| 203 | savescore(level); |
- | |
| 204 | - | ||
| 205 | showscores(level); |
- | |
| 206 | |
- | |
| 207 | printf("\nHit 's' to new game, 'q' to quit.\n"); |
- | |
| 208 | */ |
- | |
| 209 | tetris_menu_draw(*level); |
195 | tetris_menu_draw(*level); |
| 210 | while (1) { |
196 | while (1) { |
| 211 | - | ||
| 212 | i = getchar(); |
197 | int i = getchar(); |
| 213 | 198 | ||
| 214 | switch(i) { |
199 | switch(i) { |
| 215 | case 'p': |
200 | case 'p': |
| 216 | showpreview = !showpreview; |
201 | showpreview = !showpreview; |
| 217 | moveto(9,21); |
202 | moveto(9, 21); |
| 218 | if (showpreview) |
203 | if (showpreview) |
| 219 | printf("on "); |
204 | printf("on "); |
| 220 | else |
205 | else |
| 221 | printf("off"); |
206 | printf("off"); |
| 222 | - | ||
| 223 | break; |
207 | break; |
| 224 | case 'h': |
208 | case 'h': |
| 225 | showscores(firstgame); |
209 | showscores(firstgame); |
| 226 | tetris_menu_draw(*level); |
210 | tetris_menu_draw(*level); |
| 227 | break; |
211 | break; |
| Line 233... | Line 217... | ||
| 233 | case '1': |
217 | case '1': |
| 234 | case '2': |
218 | case '2': |
| 235 | case '3': |
219 | case '3': |
| 236 | case '4': |
220 | case '4': |
| 237 | case '5': |
221 | case '5': |
| 238 | case '6': |
222 | case '6': |
| 239 | case '7': |
223 | case '7': |
| 240 | case '8': |
224 | case '8': |
| 241 | case '9': |
225 | case '9': |
| 242 | *level = i - '0'; |
226 | *level = i - '0'; |
| 243 | moveto(8,18); |
227 | moveto(8, 18); |
| 244 | printf("%d", *level); |
228 | printf("%d", *level); |
| 245 | break; |
229 | break; |
| 246 | } |
230 | } |
| 247 | } |
231 | } |
| 248 | - | ||
| 249 | } |
232 | } |
| 250 | 233 | ||
| 251 | int |
- | |
| 252 | main(int argc, char *argv[]) |
234 | int main(int argc, char *argv[]) |
| 253 | { |
235 | { |
| 254 | int pos, c; |
236 | int pos; |
| - | 237 | int c; |
|
| 255 | char *keys; |
238 | char *keys; |
| 256 | int level = 2; |
239 | int level = 2; |
| 257 | char key_write[6][10]; |
240 | char key_write[6][10]; |
| - | 241 | int i; |
|
| 258 | int i, j; |
242 | int j; |
| - | 243 | int ch; |
|
| 259 | 244 | ||
| 260 | keys = "jkl pq"; |
245 | keys = "jkl pq"; |
| 261 | - | ||
| 262 | // gid = getgid(); |
- | |
| 263 | // egid = getegid(); |
- | |
| 264 | // setegid(gid); |
- | |
| 265 | 246 | ||
| 266 | classic = 0; |
247 | classic = 0; |
| 267 | showpreview = 1; |
248 | showpreview = 1; |
| 268 | - | ||
| 269 | /* while ((ch = getopt(argc, argv, "ck:l:ps")) != -1) */ |
- | |
| 270 | /* switch(ch) { */ |
- | |
| 271 | /* case 'c': */ |
- | |
| 272 | /* /\* */ |
- | |
| 273 | /* * this means: */ |
- | |
| 274 | /* * - rotate the other way; */ |
- | |
| 275 | /* * - no reverse video. */ |
- | |
| 276 | /* *\/ */ |
- | |
| 277 | /* classic = 1; */ |
- | |
| 278 | /* break; */ |
- | |
| 279 | /* case 'k': */ |
- | |
| 280 | /* if (str_size(keys = optarg) != 6) */ |
- | |
| 281 | /* usage(); */ |
- | |
| 282 | /* break; */ |
- | |
| 283 | /* case 'l': */ |
- | |
| 284 | /* level = (int)strtonum(optarg, MINLEVEL, MAXLEVEL, */ |
- | |
| 285 | /* &errstr); */ |
- | |
| 286 | /* if (errstr) */ |
- | |
| 287 | /* errx(1, "level must be from %d to %d", */ |
- | |
| 288 | /* MINLEVEL, MAXLEVEL); */ |
- | |
| 289 | /* break; */ |
- | |
| 290 | /* case 'p': */ |
- | |
| 291 | /* showpreview = 1; */ |
- | |
| 292 | /* break; */ |
- | |
| 293 | /* case 's': */ |
- | |
| 294 | /* showscores(0); */ |
- | |
| 295 | /* exit(0); */ |
- | |
| 296 | /* default: */ |
- | |
| 297 | /* usage(); */ |
- | |
| 298 | /* } */ |
- | |
| 299 | - | ||
| 300 | /* argc -= optind; */ |
- | |
| 301 | /* argv += optind; */ |
- | |
| 302 | - | ||
| 303 | /* if (argc) */ |
- | |
| 304 | /* usage(); */ |
- | |
| 305 | - | ||
| 306 | 249 | ||
| - | 250 | while ((ch = getopt(argc, argv, "ck:ps")) != -1) |
|
| - | 251 | switch(ch) { |
|
| - | 252 | case 'c': |
|
| - | 253 | /* |
|
| - | 254 | * this means: |
|
| - | 255 | * - rotate the other way |
|
| - | 256 | * - no reverse video |
|
| - | 257 | */ |
|
| - | 258 | classic = 1; |
|
| - | 259 | break; |
|
| - | 260 | case 'k': |
|
| - | 261 | if (str_size(keys = optarg) != 6) |
|
| - | 262 | usage(); |
|
| - | 263 | break; |
|
| - | 264 | case 'p': |
|
| - | 265 | showpreview = 1; |
|
| - | 266 | break; |
|
| - | 267 | case 's': |
|
| - | 268 | showscores(0); |
|
| - | 269 | exit(0); |
|
| - | 270 | default: |
|
| - | 271 | usage(); |
|
| - | 272 | } |
|
| 307 | 273 | ||
| - | 274 | argc -= optind; |
|
| - | 275 | argv += optind; |
|
| - | 276 | ||
| - | 277 | if (argc) |
|
| - | 278 | usage(); |
|
| - | 279 | ||
| 308 | for (i = 0; i <= 5; i++) { |
280 | for (i = 0; i <= 5; i++) { |
| 309 | for (j = i+1; j <= 5; j++) { |
281 | for (j = i + 1; j <= 5; j++) { |
| 310 | if (keys[i] == keys[j]) |
282 | if (keys[i] == keys[j]) |
| 311 | errx(1, "duplicate command keys specified."); |
283 | errx(1, "duplicate command keys specified."); |
| 312 | } |
284 | } |
| - | 285 | ||
| 313 | if (keys[i] == ' ') |
286 | if (keys[i] == ' ') |
| 314 | str_cpy(key_write[i], sizeof key_write[i], "<space>"); |
287 | str_cpy(key_write[i], sizeof(key_write[i]), "<space>"); |
| 315 | else { |
288 | else { |
| 316 | key_write[i][0] = keys[i]; |
289 | key_write[i][0] = keys[i]; |
| 317 | key_write[i][1] = '\0'; |
290 | key_write[i][1] = '\0'; |
| 318 | } |
291 | } |
| 319 | } |
292 | } |
| 320 | 293 | ||
| 321 | snprintf(key_msg, sizeof key_msg, |
294 | snprintf(key_msg, sizeof(key_msg), |
| 322 | "%s - left %s - rotate %s - right %s - drop %s - pause %s - quit", |
295 | "%s - left %s - rotate %s - right %s - drop %s - pause %s - quit", |
| 323 | key_write[0], key_write[1], key_write[2], key_write[3], |
296 | key_write[0], key_write[1], key_write[2], key_write[3], |
| 324 | key_write[4], key_write[5]); |
297 | key_write[4], key_write[5]); |
| 325 | 298 | ||
| 326 | scr_init(); |
299 | scr_init(); |
| 327 | initscores(); |
300 | initscores(); |
| 328 | while (tetris_menu(&level)) { |
301 | while (tetris_menu(&level)) { |
| 329 | fallrate = 1000000 / level; |
302 | fallrate = 1000000 / level; |
| 330 | 303 | ||
| 331 | scr_clear(); |
304 | scr_clear(); |
| 332 | setup_board(); |
305 | setup_board(); |
| 333 | 306 | ||
| 334 | srandomdev(); |
307 | srandomdev(); |
| 335 | scr_set(); |
308 | scr_set(); |
| 336 | 309 | ||
| 337 | pos = A_FIRST*B_COLS + (B_COLS/2)-1; |
310 | pos = A_FIRST * B_COLS + (B_COLS / 2) - 1; |
| 338 | nextshape = randshape(); |
311 | nextshape = randshape(); |
| 339 | curshape = randshape(); |
312 | curshape = randshape(); |
| 340 | 313 | ||
| 341 | scr_msg(key_msg, 1); |
314 | scr_msg(key_msg, 1); |
| 342 | 315 | ||
| 343 | for (;;) { |
316 | while (1) { |
| 344 | place(curshape, pos, 1); |
317 | place(curshape, pos, 1); |
| 345 | scr_update(); |
318 | scr_update(); |
| 346 | place(curshape, pos, 0); |
319 | place(curshape, pos, 0); |
| 347 | c = tgetchar(); |
320 | c = tgetchar(); |
| 348 | if (c < 0) { |
321 | if (c < 0) { |
| Line 351... | Line 324... | ||
| 351 | */ |
324 | */ |
| 352 | if (fits_in(curshape, pos + B_COLS)) { |
325 | if (fits_in(curshape, pos + B_COLS)) { |
| 353 | pos += B_COLS; |
326 | pos += B_COLS; |
| 354 | continue; |
327 | continue; |
| 355 | } |
328 | } |
| 356 | 329 | ||
| 357 | /* |
330 | /* |
| 358 | * Put up the current shape `permanently', |
331 | * Put up the current shape `permanently', |
| 359 | * bump score, and elide any full rows. |
332 | * bump score, and elide any full rows. |
| 360 | */ |
333 | */ |
| 361 | place(curshape, pos, 1); |
334 | place(curshape, pos, 1); |
| 362 | score++; |
335 | score++; |
| 363 | elide(); |
336 | elide(); |
| 364 | 337 | ||
| 365 | /* |
338 | /* |
| 366 | * Choose a new shape. If it does not fit, |
339 | * Choose a new shape. If it does not fit, |
| 367 | * the game is over. |
340 | * the game is over. |
| 368 | */ |
341 | */ |
| 369 | curshape = nextshape; |
342 | curshape = nextshape; |
| 370 | nextshape = randshape(); |
343 | nextshape = randshape(); |
| 371 | pos = A_FIRST*B_COLS + (B_COLS/2)-1; |
344 | pos = A_FIRST * B_COLS + (B_COLS / 2) - 1; |
| - | 345 | ||
| 372 | if (!fits_in(curshape, pos)) |
346 | if (!fits_in(curshape, pos)) |
| 373 | break; |
347 | break; |
| - | 348 | ||
| 374 | continue; |
349 | continue; |
| 375 | } |
350 | } |
| 376 | 351 | ||
| 377 | /* |
352 | /* |
| 378 | * Handle command keys. |
353 | * Handle command keys. |
| 379 | */ |
354 | */ |
| 380 | if (c == keys[5]) { |
355 | if (c == keys[5]) { |
| 381 | /* quit */ |
356 | /* quit */ |
| 382 | break; |
357 | break; |
| 383 | } |
358 | } |
| - | 359 | ||
| 384 | if (c == keys[4]) { |
360 | if (c == keys[4]) { |
| 385 | static char msg[] = |
361 | static char msg[] = |
| 386 | "paused - press RETURN to continue"; |
362 | "paused - press RETURN to continue"; |
| 387 | 363 | ||
| 388 | place(curshape, pos, 1); |
364 | place(curshape, pos, 1); |
| 389 | do { |
365 | do { |
| 390 | scr_update(); |
366 | scr_update(); |
| 391 | scr_msg(key_msg, 0); |
367 | scr_msg(key_msg, 0); |
| 392 | scr_msg(msg, 1); |
368 | scr_msg(msg, 1); |
| 393 | (void) fflush(stdout); |
369 | (void) fflush(stdout); |
| 394 | } while (rwait((struct timeval *)NULL) == -1); |
370 | } while (rwait((struct timeval *) NULL) == -1); |
| - | 371 | ||
| 395 | scr_msg(msg, 0); |
372 | scr_msg(msg, 0); |
| 396 | scr_msg(key_msg, 1); |
373 | scr_msg(key_msg, 1); |
| 397 | place(curshape, pos, 0); |
374 | place(curshape, pos, 0); |
| 398 | continue; |
375 | continue; |
| 399 | } |
376 | } |
| - | 377 | ||
| 400 | if (c == keys[0]) { |
378 | if (c == keys[0]) { |
| 401 | /* move left */ |
379 | /* move left */ |
| 402 | if (fits_in(curshape, pos - 1)) |
380 | if (fits_in(curshape, pos - 1)) |
| 403 | pos--; |
381 | pos--; |
| 404 | continue; |
382 | continue; |
| 405 | } |
383 | } |
| - | 384 | ||
| 406 | if (c == keys[1]) { |
385 | if (c == keys[1]) { |
| 407 | /* turn */ |
386 | /* turn */ |
| 408 | const struct shape *new = &shapes[ |
387 | const struct shape *new = |
| 409 | classic? curshape->rotc : curshape->rot]; |
388 | &shapes[classic ? curshape->rotc : curshape->rot]; |
| 410 | 389 | ||
| 411 | if (fits_in(new, pos)) |
390 | if (fits_in(new, pos)) |
| 412 | curshape = new; |
391 | curshape = new; |
| 413 | continue; |
392 | continue; |
| 414 | } |
393 | } |
| - | 394 | ||
| 415 | if (c == keys[2]) { |
395 | if (c == keys[2]) { |
| 416 | /* move right */ |
396 | /* move right */ |
| 417 | if (fits_in(curshape, pos + 1)) |
397 | if (fits_in(curshape, pos + 1)) |
| 418 | pos++; |
398 | pos++; |
| 419 | continue; |
399 | continue; |
| 420 | } |
400 | } |
| - | 401 | ||
| 421 | if (c == keys[3]) { |
402 | if (c == keys[3]) { |
| 422 | /* move to bottom */ |
403 | /* move to bottom */ |
| 423 | while (fits_in(curshape, pos + B_COLS)) { |
404 | while (fits_in(curshape, pos + B_COLS)) { |
| 424 | pos += B_COLS; |
405 | pos += B_COLS; |
| 425 | score++; |
406 | score++; |
| 426 | } |
407 | } |
| 427 | continue; |
408 | continue; |
| 428 | } |
409 | } |
| - | 410 | ||
| 429 | if (c == '\f') { |
411 | if (c == '\f') { |
| 430 | scr_clear(); |
412 | scr_clear(); |
| 431 | scr_msg(key_msg, 1); |
413 | scr_msg(key_msg, 1); |
| 432 | } |
414 | } |
| 433 | } |
415 | } |
| 434 | 416 | ||
| 435 | scr_clear(); |
417 | scr_clear(); |
| 436 | insertscore(score, level); |
418 | insertscore(score, level); |
| 437 | score=0; |
419 | score = 0; |
| 438 | } |
420 | } |
| 439 | 421 | ||
| 440 | scr_clear(); |
422 | scr_clear(); |
| 441 | printf("\n\n\n\t\tGame over.\n"); |
423 | printf("\nGame over.\n"); |
| 442 | /* |
- | |
| 443 | while ((i = getchar()) != '\n') |
- | |
| 444 | if (i == EOF) |
- | |
| 445 | break |
- | |
| 446 | */ |
- | |
| 447 | scr_end(); |
424 | scr_end(); |
| 448 | 425 | ||
| 449 | return 0; |
426 | return 0; |
| 450 | } |
427 | } |
| 451 | 428 | ||
| 452 | /* void */ |
- | |
| 453 | /* onintr(int signo) */ |
- | |
| 454 | /* { */ |
- | |
| 455 | /* scr_clear(); /\* XXX signal race *\/ */ |
- | |
| 456 | /* scr_end(); /\* XXX signal race *\/ */ |
- | |
| 457 | /* _exit(0); */ |
- | |
| 458 | /* } */ |
- | |
| 459 | - | ||
| 460 | void |
- | |
| 461 | usage(void) |
429 | void usage(void) |
| 462 | { |
430 | { |
| 463 | (void)fprintf(stderr, "usage: tetris [-ps] [-k keys] [-l level]\n"); |
431 | fprintf(stderr, "usage: tetris [-ps] [-k keys]\n"); |
| 464 | exit(1); |
432 | exit(1); |
| 465 | } |
433 | } |
| 466 | 434 | ||
| 467 | /** @} |
435 | /** @} |
| 468 | */ |
436 | */ |
| 469 | - | ||