Source-Changes-HG archive

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

[src/netbsd-7]: src/games/tetris Pull up following revision(s) (requested by ...



details:   https://anonhg.NetBSD.org/src/rev/bd87d8af0175
branches:  netbsd-7
changeset: 799108:bd87d8af0175
user:      snj <snj%NetBSD.org@localhost>
date:      Wed Mar 18 08:14:17 2015 +0000

description:
Pull up following revision(s) (requested by mrg in ticket #622):
        games/tetris/tetris.6: revision 1.15
        games/tetris/tetris.c: revision 1.28
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 1109d532f654 -r bd87d8af0175 games/tetris/tetris.6
--- a/games/tetris/tetris.6     Wed Mar 18 08:12:16 2015 +0000
+++ b/games/tetris/tetris.6     Wed Mar 18 08:14:17 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.14.2.1 2015/03/18 08:14:17 snj 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 1109d532f654 -r bd87d8af0175 games/tetris/tetris.c
--- a/games/tetris/tetris.c     Wed Mar 18 08:12:16 2015 +0000
+++ b/games/tetris/tetris.c     Wed Mar 18 08:14:17 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.27.2.1 2015/03/18 08:14:17 snj 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