Source-Changes-HG archive

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

[src/trunk]: src/games/gomoku Some improvements to the new UI.



details:   https://anonhg.NetBSD.org/src/rev/e92a5e9b1849
branches:  trunk
changeset: 753450:e92a5e9b1849
user:      dholland <dholland%NetBSD.org@localhost>
date:      Mon Mar 29 04:28:47 2010 +0000

description:
Some improvements to the new UI.

diffstat:

 games/gomoku/bdisp.c  |  26 +++++++++++++++++++++++---
 games/gomoku/gomoku.h |   3 ++-
 games/gomoku/main.c   |  35 ++++++++++++++++++++---------------
 3 files changed, 45 insertions(+), 19 deletions(-)

diffs (180 lines):

diff -r 5ca7e69f12c3 -r e92a5e9b1849 games/gomoku/bdisp.c
--- a/games/gomoku/bdisp.c      Mon Mar 29 04:00:03 2010 +0000
+++ b/games/gomoku/bdisp.c      Mon Mar 29 04:28:47 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bdisp.c,v 1.14 2010/03/29 03:51:55 dholland Exp $      */
+/*     $NetBSD: bdisp.c,v 1.15 2010/03/29 04:28:47 dholland Exp $      */
 
 /*
  * Copyright (c) 1994
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)bdisp.c    8.2 (Berkeley) 5/3/95";
 #else
-__RCSID("$NetBSD: bdisp.c,v 1.14 2010/03/29 03:51:55 dholland Exp $");
+__RCSID("$NetBSD: bdisp.c,v 1.15 2010/03/29 04:28:47 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -261,6 +261,24 @@
 }
 
 int
+get_key(const char *allowed)
+{
+       int ch;
+
+       while (1) {
+               ch = getch();
+               if (allowed != NULL &&
+                   ch != '\0' && strchr(allowed, ch) == NULL) {
+                       beep();
+                       refresh();
+                       continue;
+               }
+               break;
+       }
+       return ch;
+}
+
+int
 get_line(char *buf, int size)
 {
        char *cp, *end;
@@ -321,7 +339,7 @@
        nx = curx;
        ny = cury;
        for (;;) {
-               mvprintw(BSZ3, (BSZ -6)/2, "(%c %d)", 
+               mvprintw(BSZ3, (BSZ -6)/2, "(%c %d) ", 
                                'A'+ ((curx > 7) ? (curx+1) : curx), cury + 1);
                BGOTO(cury, curx);
 
@@ -431,9 +449,11 @@
                break;
 #endif /* 0 */
                case 'Q':
+               case 'q':
                        return RESIGN;
                        break;
                case 'S':
+               case 's':
                        return SAVE;
                        break;
                case ' ':
diff -r 5ca7e69f12c3 -r e92a5e9b1849 games/gomoku/gomoku.h
--- a/games/gomoku/gomoku.h     Mon Mar 29 04:00:03 2010 +0000
+++ b/games/gomoku/gomoku.h     Mon Mar 29 04:28:47 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gomoku.h,v 1.18 2010/03/29 03:51:55 dholland Exp $     */
+/*     $NetBSD: gomoku.h,v 1.19 2010/03/29 04:28:47 dholland Exp $     */
 
 /*
  * Copyright (c) 1994
@@ -269,6 +269,7 @@
 
 void   bdinit(struct spotstr *);
 int    get_coord(void);
+int    get_key(const char *allowedkeys);
 int    get_line(char *, int);
 void   ask(const char *);
 void   dislog(const char *);
diff -r 5ca7e69f12c3 -r e92a5e9b1849 games/gomoku/main.c
--- a/games/gomoku/main.c       Mon Mar 29 04:00:03 2010 +0000
+++ b/games/gomoku/main.c       Mon Mar 29 04:28:47 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.23 2010/03/29 03:51:55 dholland Exp $       */
+/*     $NetBSD: main.c,v 1.24 2010/03/29 04:28:47 dholland Exp $       */
 
 /*
  * Copyright (c) 1994
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.4 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: main.c,v 1.23 2010/03/29 03:51:55 dholland Exp $");
+__RCSID("$NetBSD: main.c,v 1.24 2010/03/29 04:28:47 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -165,9 +165,11 @@
 #endif
 
                if (inputfp == NULL && test == 0) {
-                       ask("black or white? ");
+                       move(BSZ3, 0);
+                       printw("Black moves first. ");
+                       ask("(B)lack or (W)hite? ");
                        for (;;) {
-                               ch = getchar();
+                               ch = get_key(NULL);
                                if (ch == 'b' || ch == 'B') {
                                        color = BLACK;
                                        break;
@@ -176,8 +178,11 @@
                                        color = WHITE;
                                        break;
                                }
-                               move(BSZ3, 0);
-                               printw("Black moves first. Please enter `black' or `white'\n");
+                               if (ch == 'q' || ch == 'Q') {
+                                       quit();
+                               }
+                               beep();
+                               ask("Please choose (B)lack or (W)hite: ");
                        }
                        move(BSZ3, 0);
                        clrtoeol();
@@ -253,12 +258,12 @@
                case USER: /* input comes from standard input */
                getinput:
                        if (interactive) {
-                               ask("move? ");
+                               ask("Select move, (S)ave or (Q)uit.");
                                curmove = get_coord();
                                if (curmove == SAVE) {
                                        FILE *fp;
 
-                                       ask("save file name? ");
+                                       ask("Save file name? ");
                                        (void)get_line(fname, sizeof(fname));
                                        if ((fp = fopen(fname, "w")) == NULL) {
                                                misclog("cannot create save file");
@@ -313,7 +318,7 @@
                                addstr("Rats! you won");
                        break;
                case TIE:
-                       addstr("Wow! its a tie");
+                       addstr("Wow! It's a tie");
                        break;
                case ILLEGAL:
                        addstr("Illegal move");
@@ -323,14 +328,14 @@
                bdisp();
                if (i != RESIGN) {
                replay:
-                       ask("replay? ");
-                       if (get_line(buf, sizeof(buf)) &&
-                           (buf[0] == 'y' || buf[0] == 'Y'))
+                       ask("Play again? ");
+                       ch = get_key("YyNnQqSs"); 
+                       if (ch == 'Y' || ch == 'y')
                                goto again;
-                       if (strcmp(buf, "save") == 0) {
+                       if (ch == 'S') {
                                FILE *fp;
 
-                               ask("save file name? ");
+                               ask("Save file name? ");
                                (void)get_line(fname, sizeof(fname));
                                if ((fp = fopen(fname, "w")) == NULL) {
                                        misclog("cannot create save file");
@@ -382,7 +387,7 @@
        if (!interactive)
                quit();
 top:
-       ask("cmd? ");
+       ask("debug command: ");
        if (!get_line(input, sizeof(input)))
                quit();
        switch (*input) {



Home | Main Index | Thread Index | Old Index