Add previewing of next shape. Old (previous) behaviour can be
restored by compiling with NO_PREVIEW defined.
This commit is contained in:
parent
75ea7b3f7e
commit
f42c52bee6
@ -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.
|
||||
*/
|
||||
|
@ -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));
|
||||
|
@ -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++) {
|
||||
|
@ -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.
|
||||
|
@ -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();
|
||||
|
@ -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.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user