Module Name:    src
Committed By:   christos
Date:           Wed Jun 11 16:47:39 UTC 2014

Modified Files:
        src/games/tetris: screen.c shapes.c tetris.c tetris.h

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/games/tetris/screen.c
cvs rdiff -u -r1.8 -r1.9 src/games/tetris/shapes.c
cvs rdiff -u -r1.24 -r1.25 src/games/tetris/tetris.c
cvs rdiff -u -r1.12 -r1.13 src/games/tetris/tetris.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/tetris/screen.c
diff -u src/games/tetris/screen.c:1.27 src/games/tetris/screen.c:1.28
--- src/games/tetris/screen.c:1.27	Mon Oct  3 08:32:28 2011
+++ src/games/tetris/screen.c	Wed Jun 11 12:47:39 2014
@@ -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 @@ moveto(int r, int c)
 		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 @@ scr_update(void)
 						
 		/* draw */
 		putpad(enter_standout_mode);
+		setcolor(nextshape->color);
 		moveto(r, 2*c);
 		putstr("  ");
 		for(i=0; i<3; i++) {
@@ -349,7 +362,14 @@ scr_update(void)
 					    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;

Index: src/games/tetris/shapes.c
diff -u src/games/tetris/shapes.c:1.8 src/games/tetris/shapes.c:1.9
--- src/games/tetris/shapes.c:1.8	Mon May 25 00:33:53 2009
+++ src/games/tetris/shapes.c	Wed Jun 11 12:47:39 2014
@@ -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 @@ void
 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;

Index: src/games/tetris/tetris.c
diff -u src/games/tetris/tetris.c:1.24 src/games/tetris/tetris.c:1.25
--- src/games/tetris/tetris.c:1.24	Wed Aug 31 12:24:56 2011
+++ src/games/tetris/tetris.c	Wed Jun 11 12:47:39 2014
@@ -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 @@ 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;
 }
 
 /*

Index: src/games/tetris/tetris.h
diff -u src/games/tetris/tetris.h:1.12 src/games/tetris/tetris.h:1.13
--- src/games/tetris/tetris.h:1.12	Wed Aug 12 04:51:21 2009
+++ src/games/tetris/tetris.h	Wed Jun 11 12:47:39 2014
@@ -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 @@ extern int	Rows, Cols;	/* current screen
  * 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) */
 };

Reply via email to