Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/games/tetris Add a little color. In order to minimize logic ...



details:   https://anonhg.NetBSD.org/src/rev/7346f9f82465
branches:  trunk
changeset: 329836:7346f9f82465
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Jun 11 16:47:39 2014 +0000

description:
Add a little color. In order to minimize logic differences, keep 0 as the
empty board value, and since 7 is white, turn white into black (0) when
painting.

diffstat:

 games/tetris/screen.c |  22 +++++++++++++++++++++-
 games/tetris/shapes.c |  41 +++++++++++++++++++++--------------------
 games/tetris/tetris.c |   4 ++--
 games/tetris/tetris.h |   3 ++-
 4 files changed, 46 insertions(+), 24 deletions(-)

diffs (148 lines):

diff -r f210ec8b6177 -r 7346f9f82465 games/tetris/screen.c
--- a/games/tetris/screen.c     Wed Jun 11 16:45:06 2014 +0000
+++ b/games/tetris/screen.c     Wed Jun 11 16:47:39 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: screen.c,v 1.27 2011/10/03 12:32:28 roy Exp $  */
+/*     $NetBSD: screen.c,v 1.28 2014/06/11 16:47:39 christos Exp $     */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -94,6 +94,18 @@
                putpad(buf);
 }
 
+static void
+setcolor(int c)
+{
+       char *buf;
+       if (set_a_foreground == NULL)
+               return;
+
+       buf = tiparm(set_a_foreground, c == 7 ? 0 : c);
+       if (buf != NULL)
+               putpad(buf);
+}
+
 /*
  * Set up from termcap.
  */
@@ -312,6 +324,7 @@
                                                
                /* draw */
                putpad(enter_standout_mode);
+               setcolor(nextshape->color);
                moveto(r, 2*c);
                putstr("  ");
                for(i=0; i<3; i++) {
@@ -349,7 +362,14 @@
                                            exit_standout_mode);
                                        cur_so = so;
                                }
+                               setcolor(so);
+#ifdef DEBUG
+                               char buf[3];
+                               snprintf(buf, sizeof(buf), "%d%d", so, so);
+                               putstr(buf);
+#else
                                putstr("  ");
+#endif
                        } else
                                putstr(so ? "XX" : "  ");
                        ccol = i + 1;
diff -r f210ec8b6177 -r 7346f9f82465 games/tetris/shapes.c
--- a/games/tetris/shapes.c     Wed Jun 11 16:45:06 2014 +0000
+++ b/games/tetris/shapes.c     Wed Jun 11 16:47:39 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: shapes.c,v 1.8 2009/05/25 04:33:53 dholland Exp $      */
+/*     $NetBSD: shapes.c,v 1.9 2014/06/11 16:47:39 christos Exp $      */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -53,25 +53,25 @@
 #define        BR      B_COLS+1        /* bottom right */
 
 const struct shape shapes[] = {
-       /* 0*/  { 7,    { TL, TC, MR, } },
-       /* 1*/  { 8,    { TC, TR, ML, } },
-       /* 2*/  { 9,    { ML, MR, BC, } },
-       /* 3*/  { 3,    { TL, TC, ML, } },
-       /* 4*/  { 12,   { ML, BL, MR, } },
-       /* 5*/  { 15,   { ML, BR, MR, } },
-       /* 6*/  { 18,   { ML, MR, 2   } },      /* sticks out */
-       /* 7*/  { 0,    { TC, ML, BL, } },
-       /* 8*/  { 1,    { TC, MR, BR, } },
-       /* 9*/  { 10,   { TC, MR, BC, } },
-       /*10*/  { 11,   { TC, ML, MR, } },
-       /*11*/  { 2,    { TC, ML, BC, } },
-       /*12*/  { 13,   { TC, BC, BR, } },
-       /*13*/  { 14,   { TR, ML, MR, } },
-       /*14*/  { 4,    { TL, TC, BC, } },
-       /*15*/  { 16,   { TR, TC, BC, } },
-       /*16*/  { 17,   { TL, MR, ML, } },
-       /*17*/  { 5,    { TC, BC, BL, } },
-       /*18*/  { 6,    { TC, BC, 2*B_COLS } }  /* sticks out */
+       /* 0*/  { 7,  7,        { TL, TC, MR, } },
+       /* 1*/  { 1,  8,        { TC, TR, ML, } },
+       /* 2*/  { 2,  9,        { ML, MR, BC, } },
+       /* 3*/  { 3,  3,        { TL, TC, ML, } },
+       /* 4*/  { 4, 12,        { ML, BL, MR, } },
+       /* 5*/  { 5, 15,        { ML, BR, MR, } },
+       /* 6*/  { 6, 18,        { ML, MR, 2   } },      /* sticks out */
+       /* 7*/  { 7,  0,        { TC, ML, BL, } },
+       /* 8*/  { 1,  1,        { TC, MR, BR, } },
+       /* 9*/  { 2, 10,        { TC, MR, BC, } },
+       /*10*/  { 2, 11,        { TC, ML, MR, } },
+       /*11*/  { 2,  2,        { TC, ML, BC, } },
+       /*12*/  { 4, 13,        { TC, BC, BR, } },
+       /*13*/  { 4, 14,        { TR, ML, MR, } },
+       /*14*/  { 4,  4,        { TL, TC, BC, } },
+       /*15*/  { 5, 16,        { TR, TC, BC, } },
+       /*16*/  { 5, 17,        { TL, MR, ML, } },
+       /*17*/  { 5,  5,        { TC, BC, BL, } },
+       /*18*/  { 6,  6,        { TC, BC, 2*B_COLS } }  /* sticks out */
 };
 
 /*
@@ -97,6 +97,7 @@
 place(const struct shape *shape, int pos, int onoff)
 {
        const int *o = shape->off;
+       onoff = onoff ? shape->color : 0;
 
        board[pos] = onoff;
        board[pos + *o++] = onoff;
diff -r f210ec8b6177 -r 7346f9f82465 games/tetris/tetris.c
--- a/games/tetris/tetris.c     Wed Jun 11 16:45:06 2014 +0000
+++ b/games/tetris/tetris.c     Wed Jun 11 16:47:39 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tetris.c,v 1.24 2011/08/31 16:24:56 plunky Exp $       */
+/*     $NetBSD: tetris.c,v 1.25 2014/06/11 16:47:39 christos Exp $     */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -92,7 +92,7 @@
 
        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;
 }
 
 /*
diff -r f210ec8b6177 -r 7346f9f82465 games/tetris/tetris.h
--- a/games/tetris/tetris.h     Wed Jun 11 16:45:06 2014 +0000
+++ b/games/tetris/tetris.h     Wed Jun 11 16:47:39 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tetris.h,v 1.12 2009/08/12 08:51:21 dholland Exp $     */
+/*     $NetBSD: tetris.h,v 1.13 2014/06/11 16:47:39 christos Exp $     */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -123,6 +123,7 @@
  * rotated forms.
  */
 struct shape {
+       int     color;
        int     rot;    /* index of rotated version of this shape */
        int     off[3]; /* offsets to other blots if center is at (0,0) */
 };



Home | Main Index | Thread Index | Old Index