]> git.cameronkatri.com Git - bsdgames-darwin.git/commitdiff
Add previewing of next shape. Old (previous) behaviour can be
authorhubertf <hubertf@NetBSD.org>
Sun, 3 Jan 1999 02:00:17 +0000 (02:00 +0000)
committerhubertf <hubertf@NetBSD.org>
Sun, 3 Jan 1999 02:00:17 +0000 (02:00 +0000)
restored by compiling with NO_PREVIEW defined.

tetris/input.c
tetris/input.h
tetris/screen.c
tetris/tetris.6
tetris/tetris.c
tetris/tetris.h

index 26772cdad61cffe54f299f196afc0df174a055e7..b21ad834527241251b5fd040f17a684304d60114 100644 (file)
@@ -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
 
 /*-
  * Copyright (c) 1992, 1993
@@ -136,20 +136,6 @@ tsleep()
                        break;
 }
 
                        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.
  */
 /*
  * getchar with timeout.
  */
index d9616b1d99f58568dcf0c72eea5bb99e326c42f3..8bbd0d34970bb181f52d0d880472f0db7b704316 100644 (file)
@@ -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
 
 /*-
  * Copyright (c) 1992, 1993
@@ -38,7 +38,6 @@
  *     @(#)input.h     8.1 (Berkeley) 5/31/93
  */
 
  *     @(#)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));
 int    rwait __P((struct timeval *));
 int    tgetchar __P((void));
 void   tsleep __P((void));
index fe0e21ad95509ac3cfc06a0cf9f02eae33029220..c4a4ff87cd757599856a9781455c8c0710a798d2 100644 (file)
@@ -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
 
 /*-
  * Copyright (c) 1992, 1993
@@ -279,8 +279,8 @@ scr_set()
        Cols = COnum;
        if (Rows < MINROWS || Cols < MINCOLS) {
                (void) fprintf(stderr,
        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)
                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;
        register regcell so, cur_so = 0;
        register int i, ccol, j;
        sigset_t sigset, osigset;
+       static struct shape *lastshape;
 
        sigemptyset(&sigset);
        sigaddset(&sigset, SIGTSTP);
 
        sigemptyset(&sigset);
        sigaddset(&sigset, SIGTSTP);
@@ -389,10 +390,47 @@ scr_update()
                        putpad(HOstr);
                else
                        moveto(0, 0);
                        putpad(HOstr);
                else
                        moveto(0, 0);
-               (void) printf("%d", score);
+               (void) printf("Score: %d", score);
                curscore = 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++) {
        bp = &board[D_FIRST * B_COLS];
        sp = &curscreen[D_FIRST * B_COLS];
        for (j = D_FIRST; j < D_LAST; j++) {
index bb4084bae6657de8e6817128a54556eb76f856d6..49fc76e3fef324f0822f282aa56ce6dd17f4a458 100644 (file)
@@ -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.
 .\"
 .\" 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
 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.
index b2f0006c6fad25d248e8b23a5f94a989c2252636..c5569c9b8192157be5d095871210f88fca344f61 100644 (file)
@@ -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
 
 /*-
  * 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__));
 
        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
 /*
  * 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;
        char *argv[];
 {
        register int pos, c;
-       register struct shape *curshape;
        register char *keys;
        register int level = 2;
        char key_write[6][10];
        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;
        scr_set();
 
        pos = A_FIRST*B_COLS + (B_COLS/2)-1;
+       nextshape = randshape();
        curshape = randshape();
 
        scr_msg(key_msg, 1);
        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.
                         */
                         * 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;
                        pos = A_FIRST*B_COLS + (B_COLS/2)-1;
                        if (!fits_in(curshape, pos))
                                break;
@@ -278,8 +283,10 @@ main(argc, argv)
                        }
                        continue;
                }
                        }
                        continue;
                }
-               if (c == '\f')
+               if (c == '\f') {
                        scr_clear();
                        scr_clear();
+                       scr_msg(key_msg, 1);
+               }
        }
 
        scr_clear();
        }
 
        scr_clear();
index 0aa410566c1ce20fe086e2a527ffe3d792d3b6e9..13d4b40bdfc33d2bcf7825951a2277b56ee1b02b 100644 (file)
@@ -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
 
 /*-
  * Copyright (c) 1992, 1993
@@ -132,6 +132,9 @@ struct shape {
 extern struct shape shapes[];
 #define        randshape() (&shapes[random() % 7])
 
 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.
  *
 /*
  * Shapes fall at a rate faster than once per second.
  *