da60626431e94a11d582e3d42654ac5f74c77b31
* Copyright (c) 1992 The Regents of the University of California.
* %sccs.include.redist.c%
* @(#)tetris.c 5.1 (Berkeley) %G%
"@(#) Copyright (c) 1992 The Regents of the University of California.\n\
* Tetris (or however it is spelled).
* Set up the initial board.
* The bottom display row is completely set,
* along with another (hidden) row underneath that.
* Also, the left and right edges are set.
*p
++ = i
<= (2 * B_COLS
) || (i
% B_COLS
) < 2;
#else /* work around compiler bug */
*p
++ = i
<= (2 * B_COLS
) || (i
% B_COLS
) < 2 ? 1 : 0;
* Elide any full active rows.
for (i
= A_FIRST
; i
< A_LAST
; i
++) {
for (j
= B_COLS
- 2; *p
++ != 0;) {
/* this row is to be elided */
bzero(&board
[base
], B_COLS
- 2);
board
[base
+ B_COLS
] = board
[base
];
register struct shape
*curshape
;
"usage: %s [level] [-keys]\n",
level
= atoi(argv
[argc
]);
fallrate
= 1000000 / level
;
for (i
= 0; i
<= 5; i
++) {
for (j
= i
+1; j
<= 5; j
++) {
if (keys
[i
] == keys
[j
]) {
"%s: Duplicate command keys specified.\n",
strcpy(key_write
[i
], "<space>");
key_write
[i
][0] = keys
[i
];
"%s - left %s - rotate %s - right %s - drop %s - pause %s - quit",
key_write
[0], key_write
[1], key_write
[2], key_write
[3],
key_write
[4], key_write
[5]);
pos
= A_FIRST
*B_COLS
+ (B_COLS
/2)-1;
* Timeout. Move down if possible.
if (fits_in(curshape
, pos
+ B_COLS
)) {
* Put up the current shape `permanently',
* bump score, and elide any full rows.
* Choose a new shape. If it does not fit,
pos
= A_FIRST
*B_COLS
+ (B_COLS
/2)-1;
if (!fits_in(curshape
, pos
))
"paused - press RETURN to continue";
} while (rwait((struct timeval
*)NULL
) == -1);
if (fits_in(curshape
, pos
- 1))
struct shape
*new = &shapes
[curshape
->rot
];
if (fits_in(curshape
, pos
+ 1))
while (fits_in(curshape
, pos
+ B_COLS
)) {
(void)printf("Your score: %d point%s x level %d = %d\n",
score
, score
== 1 ? "" : "s", level
, score
* level
);
printf("\nHit RETURN to see high scores, ^C to skip.\n");
while ((i
= getchar()) != '\n')