X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/ea061499cfca6ed03384392d6972b6527402a242..f5228c7e8453860f0a16bfd7969a0a79a4e3e203:/tetris/tetris.c diff --git a/tetris/tetris.c b/tetris/tetris.c index 7202cb31..5a41c158 100644 --- a/tetris/tetris.c +++ b/tetris/tetris.c @@ -1,4 +1,4 @@ -/* $NetBSD: tetris.c,v 1.23 2010/12/05 04:34:23 pgoyette Exp $ */ +/* $NetBSD: tetris.c,v 1.32 2016/03/03 21:38:55 nat Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -62,6 +62,7 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 1993\ cell board[B_SIZE]; /* 1 => occupied, 0 => empty */ int Rows, Cols; /* current screen size */ +int Offset; /* used to center board & shapes */ static const struct shape *curshape; const struct shape *nextshape; @@ -73,6 +74,7 @@ gid_t gid, egid; char key_msg[100]; int showpreview; +int nocolor; static void elide(void); static void setup_board(void); @@ -92,7 +94,7 @@ setup_board(void) p = board; for (i = B_SIZE; i; i--) - *p++ = i <= (2 * B_COLS) || (i % B_COLS) < 2; + *p++ = (i <= (2 * B_COLS) || (i % B_COLS) < 2) ? 7 : 0; } /* @@ -115,6 +117,8 @@ elide(void) tsleep(); while (--base != 0) board[base + B_COLS] = board[base]; + /* don't forget to clear 0th row */ + memset(&board[1], 0, B_COLS - 2); scr_update(); tsleep(); break; @@ -129,7 +133,8 @@ main(int argc, char *argv[]) int pos, c; const char *keys; int level = 2; - char key_write[6][10]; +#define NUMKEYS 7 + char key_write[NUMKEYS][10]; int ch, i, j; int fd; @@ -142,12 +147,15 @@ main(int argc, char *argv[]) exit(1); close(fd); - keys = "jkl pq"; + keys = "jkl pqn"; - while ((ch = getopt(argc, argv, "k:l:ps")) != -1) + while ((ch = getopt(argc, argv, "bk:l:ps")) != -1) switch(ch) { + case 'b': + nocolor = 1; + break; case 'k': - if (strlen(keys = optarg) != 6) + if (strlen(keys = optarg) != NUMKEYS) usage(); break; case 'l': @@ -176,8 +184,8 @@ main(int argc, char *argv[]) fallrate = 1000000 / level; - for (i = 0; i <= 5; i++) { - for (j = i+1; j <= 5; j++) { + for (i = 0; i <= (NUMKEYS-1); i++) { + for (j = i+1; j <= (NUMKEYS-1); j++) { if (keys[i] == keys[j]) { errx(1, "duplicate command keys specified."); } @@ -191,9 +199,9 @@ main(int argc, char *argv[]) } snprintf(key_msg, sizeof(key_msg), -"%s - left %s - rotate %s - right %s - drop %s - pause %s - quit", +"%s - left %s - rotate %s - right %s - drop %s - pause %s - quit %s - down", key_write[0], key_write[1], key_write[2], key_write[3], - key_write[4], key_write[5]); + key_write[4], key_write[5], key_write[6]); (void)signal(SIGINT, onintr); scr_init(); @@ -259,7 +267,7 @@ main(int argc, char *argv[]) scr_msg(key_msg, 0); scr_msg(msg, 1); (void) fflush(stdout); - } while (rwait((struct timeval *)NULL) == -1); + } while (rwait(NULL) == -1); scr_msg(msg, 0); scr_msg(key_msg, 1); place(curshape, pos, 0); @@ -293,6 +301,14 @@ main(int argc, char *argv[]) } continue; } + if (c == keys[6]) { + /* move down */ + if (fits_in(curshape, pos + B_COLS)) { + pos += B_COLS; + score++; + } + continue; + } if (c == '\f') { scr_clear(); scr_msg(key_msg, 1); @@ -328,7 +344,7 @@ onintr(int signo __unused) static void usage(void) { - (void)fprintf(stderr, "usage: %s [-ps] [-k keys] [-l level]\n", + (void)fprintf(stderr, "usage: %s [-bps] [-k keys] [-l level]\n", getprogname()); exit(1); }