Module Name: src
Committed By: mrg
Date: Thu Feb 19 02:27:30 UTC 2015
Modified Files:
src/games/tetris: tetris.6 tetris.c
Log Message:
add a 'down' key to tetris, defaulting to 'n'. it move the block down
a line, if it fits. like most other tetris games have.
minor clean up of magic number usage while here.
To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/games/tetris/tetris.6
cvs rdiff -u -r1.27 -r1.28 src/games/tetris/tetris.c
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/tetris.6
diff -u src/games/tetris/tetris.6:1.14 src/games/tetris/tetris.6:1.15
--- src/games/tetris/tetris.6:1.14 Tue Jul 15 16:17:15 2014
+++ src/games/tetris/tetris.6 Thu Feb 19 02:27:30 2015
@@ -1,4 +1,4 @@
-.\" $NetBSD: tetris.6,v 1.14 2014/07/15 16:17:15 wiz Exp $
+.\" $NetBSD: tetris.6,v 1.15 2015/02/19 02:27:30 mrg Exp $
.\"
.\" Copyright (c) 1992, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -32,7 +32,7 @@
.\"
.\" @(#)tetris.6 8.1 (Berkeley) 5/31/93
.\"
-.Dd July 13, 2014
+.Dd February 18, 2015
.Dt TETRIS 6
.Os
.Sh NAME
@@ -69,6 +69,8 @@ drop
pause
.It q
quit
+.It n
+down
.El
.Pp
The options are as follows:
@@ -84,11 +86,11 @@ The default control keys can be changed
option.
The
.Ar keys
-argument must have the six keys in order, and, remember to quote any
+argument must have the seven keys in order, and, remember to quote any
space or tab characters from the shell.
For example:
.sp
-.Dl "tetris -l 2 -k 'jkl pq'"
+.Dl "tetris -l 2 -k 'jkl pqn'"
.sp
will play the default games, i.e. level 2 and with the default
control keys.
Index: src/games/tetris/tetris.c
diff -u src/games/tetris/tetris.c:1.27 src/games/tetris/tetris.c:1.28
--- src/games/tetris/tetris.c:1.27 Sun Jul 13 17:38:38 2014
+++ src/games/tetris/tetris.c Thu Feb 19 02:27:30 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: tetris.c,v 1.27 2014/07/13 17:38:38 pgoyette Exp $ */
+/* $NetBSD: tetris.c,v 1.28 2015/02/19 02:27:30 mrg Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -130,7 +130,8 @@ main(int argc, char *argv[])
int pos, c;
const char *keys;
int level = 2;
- char key_write[6][10];
+#define NUMKEYS 7
+ char key_write[NUMKEYS][10];
int ch, i, j;
int fd;
@@ -143,7 +144,7 @@ main(int argc, char *argv[])
exit(1);
close(fd);
- keys = "jkl pq";
+ keys = "jkl pqn";
while ((ch = getopt(argc, argv, "bk:l:ps")) != -1)
switch(ch) {
@@ -151,7 +152,7 @@ main(int argc, char *argv[])
nocolor = 1;
break;
case 'k':
- if (strlen(keys = optarg) != 6)
+ if (strlen(keys = optarg) != NUMKEYS)
usage();
break;
case 'l':
@@ -180,8 +181,8 @@ main(int argc, char *argv[])
fallrate = 1000000 / level;
- for (i = 0; i <= 5; i++) {
- for (j = i+1; j <= 5; j++) {
+ for (i = 0; i <= (NUMKEYS-1); i++) {
+ for (j = i+1; j <= (NUMKEYS-1); j++) {
if (keys[i] == keys[j]) {
errx(1, "duplicate command keys specified.");
}
@@ -195,9 +196,9 @@ main(int argc, char *argv[])
}
snprintf(key_msg, sizeof(key_msg),
-"%s - left %s - rotate %s - right %s - drop %s - pause %s - quit",
+"%s - left %s - rotate %s - right %s - drop %s - pause %s - quit %s - down",
key_write[0], key_write[1], key_write[2], key_write[3],
- key_write[4], key_write[5]);
+ key_write[4], key_write[5], key_write[6]);
(void)signal(SIGINT, onintr);
scr_init();
@@ -297,6 +298,14 @@ main(int argc, char *argv[])
}
continue;
}
+ if (c == keys[6]) {
+ /* move down */
+ if (fits_in(curshape, pos + B_COLS)) {
+ pos += B_COLS;
+ score++;
+ }
+ continue;
+ }
if (c == '\f') {
scr_clear();
scr_msg(key_msg, 1);