From: hubertf Date: Sun, 3 Jan 1999 02:00:17 +0000 (+0000) Subject: Add previewing of next shape. Old (previous) behaviour can be X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/commitdiff_plain/bb3d9b5a7d9f27925fc7284fcb2394b29406be8d Add previewing of next shape. Old (previous) behaviour can be restored by compiling with NO_PREVIEW defined. --- diff --git a/tetris/input.c b/tetris/input.c index 26772cda..b21ad834 100644 --- a/tetris/input.c +++ b/tetris/input.c @@ -1,4 +1,4 @@ -/* $NetBSD: input.c,v 1.3 1996/02/06 22:47:33 jtc Exp $ */ +/* $NetBSD: input.c,v 1.4 1999/01/03 02:00:17 hubertf Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -136,20 +136,6 @@ tsleep() break; } -/* - * Eat up any input (used at end of game). - */ -void -eat_input() -{ - struct timeval tv; - char c; - - do { - tv.tv_sec = tv.tv_usec = 0; - } while (rwait(&tv) && read(0, &c, 1) == 1); -} - /* * getchar with timeout. */ diff --git a/tetris/input.h b/tetris/input.h index d9616b1d..8bbd0d34 100644 --- a/tetris/input.h +++ b/tetris/input.h @@ -1,4 +1,4 @@ -/* $NetBSD: input.h,v 1.2 1995/04/22 07:42:36 cgd Exp $ */ +/* $NetBSD: input.h,v 1.3 1999/01/03 02:00:17 hubertf Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -38,7 +38,6 @@ * @(#)input.h 8.1 (Berkeley) 5/31/93 */ -void eat_input __P((void)); int rwait __P((struct timeval *)); int tgetchar __P((void)); void tsleep __P((void)); diff --git a/tetris/screen.c b/tetris/screen.c index fe0e21ad..c4a4ff87 100644 --- a/tetris/screen.c +++ b/tetris/screen.c @@ -1,4 +1,4 @@ -/* $NetBSD: screen.c,v 1.7 1998/08/10 02:25:45 perry Exp $ */ +/* $NetBSD: screen.c,v 1.8 1999/01/03 02:00:18 hubertf Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -279,8 +279,8 @@ scr_set() Cols = COnum; if (Rows < MINROWS || Cols < MINCOLS) { (void) fprintf(stderr, - "the screen is too small: must be at least %d x %d", - MINROWS, MINCOLS); + "the screen is too small: must be at least %dx%d, ", + MINCOLS, MINROWS); stop(""); /* stop() supplies \n */ } if (tcgetattr(0, &oldtt) < 0) @@ -376,6 +376,7 @@ scr_update() register regcell so, cur_so = 0; register int i, ccol, j; sigset_t sigset, osigset; + static struct shape *lastshape; sigemptyset(&sigset); sigaddset(&sigset, SIGTSTP); @@ -389,10 +390,47 @@ scr_update() putpad(HOstr); else moveto(0, 0); - (void) printf("%d", score); + (void) printf("Score: %d", score); curscore = score; } +#ifndef NO_PREVIEW + /* draw preview of nextpattern */ + if (nextshape != lastshape) { + int i; + static int r=5, c=2; + int tr, tc, t; + + lastshape = nextshape; + + /* clean */ + putpad(SEstr); + moveto(r-1, c-1); putstr(" "); + moveto(r, c-1); putstr(" "); + moveto(r+1, c-1); putstr(" "); + moveto(r+2, c-1); putstr(" "); + + moveto(r-3, c-2); + putstr("Next shape:"); + + /* draw */ + putpad(SOstr); + moveto(r, 2*c); + putstr(" "); + for(i=0; i<3; i++) { + t = c + r*B_COLS; + t += nextshape->off[i]; + + tr = t / B_COLS; + tc = t % B_COLS; + + moveto(tr, 2*tc); + putstr(" "); + } + putpad(SEstr); + } +#endif + bp = &board[D_FIRST * B_COLS]; sp = &curscreen[D_FIRST * B_COLS]; for (j = D_FIRST; j < D_LAST; j++) { diff --git a/tetris/tetris.6 b/tetris/tetris.6 index bb4084ba..49fc76e3 100644 --- a/tetris/tetris.6 +++ b/tetris/tetris.6 @@ -1,4 +1,4 @@ -.\" $NetBSD: tetris.6,v 1.4 1997/09/01 23:26:11 mikel Exp $ +.\" $NetBSD: tetris.6,v 1.5 1999/01/03 02:00:18 hubertf Exp $ .\" .\" Copyright (c) 1992, 1993 .\" The Regents of the University of California. All rights reserved. @@ -155,3 +155,5 @@ Chris Torek and Darren F. Provine. .Pp Manual adapted from the original entry written by Nancy L. Tinkham and Darren F. Provine. +.Pp +Code for previewing next shape added by Hubert Feyrer in 1999. diff --git a/tetris/tetris.c b/tetris/tetris.c index b2f0006c..c5569c9b 100644 --- a/tetris/tetris.c +++ b/tetris/tetris.c @@ -1,4 +1,4 @@ -/* $NetBSD: tetris.c,v 1.5 1998/09/13 15:27:30 hubertf Exp $ */ +/* $NetBSD: tetris.c,v 1.6 1999/01/03 02:00:18 hubertf Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -67,6 +67,10 @@ static void setup_board __P((void)); void onintr __P((int)) __attribute__((__noreturn__)); void usage __P((void)) __attribute__((__noreturn__)); +struct shape *curshape; +struct shape *nextshape; + + /* * Set up the initial board. The bottom display row is completely set, * along with another (hidden) row underneath that. Also, the left and @@ -121,7 +125,6 @@ main(argc, argv) char *argv[]; { register int pos, c; - register struct shape *curshape; register char *keys; register int level = 2; char key_write[6][10]; @@ -190,6 +193,7 @@ main(argc, argv) scr_set(); pos = A_FIRST*B_COLS + (B_COLS/2)-1; + nextshape = randshape(); curshape = randshape(); scr_msg(key_msg, 1); @@ -220,7 +224,8 @@ main(argc, argv) * Choose a new shape. If it does not fit, * the game is over. */ - curshape = randshape(); + curshape = nextshape; + nextshape = randshape(); pos = A_FIRST*B_COLS + (B_COLS/2)-1; if (!fits_in(curshape, pos)) break; @@ -278,8 +283,10 @@ main(argc, argv) } continue; } - if (c == '\f') + if (c == '\f') { scr_clear(); + scr_msg(key_msg, 1); + } } scr_clear(); diff --git a/tetris/tetris.h b/tetris/tetris.h index 0aa41056..13d4b40b 100644 --- a/tetris/tetris.h +++ b/tetris/tetris.h @@ -1,4 +1,4 @@ -/* $NetBSD: tetris.h,v 1.3 1998/09/13 15:27:30 hubertf Exp $ */ +/* $NetBSD: tetris.h,v 1.4 1999/01/03 02:00:18 hubertf Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -132,6 +132,9 @@ struct shape { extern struct shape shapes[]; #define randshape() (&shapes[random() % 7]) +extern struct shape *curshape; +extern struct shape *nextshape; + /* * Shapes fall at a rate faster than once per second. *