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 'down' key to tetris, defaulting to 'n'. ...



details:   https://anonhg.NetBSD.org/src/rev/364a825cb432
branches:  trunk
changeset: 806362:364a825cb432
user:      mrg <mrg%NetBSD.org@localhost>
date:      Thu Feb 19 02:27:30 2015 +0000

description:
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.

diffstat:

 games/tetris/tetris.6 |  10 ++++++----
 games/tetris/tetris.c |  25 +++++++++++++++++--------
 2 files changed, 23 insertions(+), 12 deletions(-)

diffs (116 lines):

diff -r f7d000af8d87 -r 364a825cb432 games/tetris/tetris.6
--- a/games/tetris/tetris.6     Wed Feb 18 17:00:15 2015 +0000
+++ b/games/tetris/tetris.6     Thu Feb 19 02:27:30 2015 +0000
@@ -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 @@
 pause
 .It q
 quit
+.It n
+down
 .El
 .Pp
 The options are as follows:
@@ -84,11 +86,11 @@
 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.
diff -r f7d000af8d87 -r 364a825cb432 games/tetris/tetris.c
--- a/games/tetris/tetris.c     Wed Feb 18 17:00:15 2015 +0000
+++ b/games/tetris/tetris.c     Thu Feb 19 02:27:30 2015 +0000
@@ -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 @@
        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 @@
                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 @@
                        nocolor = 1;
                        break;
                case 'k':
-                       if (strlen(keys = optarg) != 6)
+                       if (strlen(keys = optarg) != NUMKEYS)
                                usage();
                        break;
                case 'l':
@@ -180,8 +181,8 @@
 
        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 @@
        }
 
        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 @@
                        }
                        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);



Home | Main Index | Thread Index | Old Index