make a scrolling region for cribbage
authorKen Arnold <arnold@ucbvax.Berkeley.EDU>
Mon, 2 May 1983 06:31:16 +0000 (22:31 -0800)
committerKen Arnold <arnold@ucbvax.Berkeley.EDU>
Mon, 2 May 1983 06:31:16 +0000 (22:31 -0800)
SCCS-vsn: games/cribbage/crib.c 1.14
SCCS-vsn: games/cribbage/io.c 1.8
SCCS-vsn: games/cribbage/support.c 1.10
SCCS-vsn: games/cribbage/cribbage.h 1.3
SCCS-vsn: games/cribbage/cribcur.h 1.3
SCCS-vsn: games/cribbage/extern.c 1.2

usr/src/games/cribbage/crib.c
usr/src/games/cribbage/cribbage.h
usr/src/games/cribbage/cribcur.h
usr/src/games/cribbage/extern.c
usr/src/games/cribbage/io.c
usr/src/games/cribbage/support.c

index e6d9f28..4a6834f 100644 (file)
@@ -53,12 +53,14 @@ char        *argv[];
        signal(SIGINT, bye);
        crmode();
        noecho();
        signal(SIGINT, bye);
        crmode();
        noecho();
-       Playwin = subwin(stdscr, PLAY_Y, PLAY_X, 0, SCORE_SZ);
-       Tablewin = subwin(stdscr, TABLE_Y, TABLE_X, 0, PLAY_X + SCORE_SZ);
-       Compwin = subwin(stdscr, COMP_Y, COMP_X, 0, TABLE_X + PLAY_X + SCORE_SZ);
+       Playwin = subwin(stdscr, PLAY_Y, PLAY_X, 0, X_SCORE_SZ);
+       Tablewin = subwin(stdscr, TABLE_Y, TABLE_X, 0, PLAY_X + X_SCORE_SZ);
+       Compwin = subwin(stdscr, COMP_Y, COMP_X, 0, TABLE_X + PLAY_X + X_SCORE_SZ);
+       Msgwin = subwin(stdscr, MSG_Y, MSG_X, Y_SCORE_SZ + 1, 0);
        leaveok(Playwin, TRUE);
        leaveok(Tablewin, TRUE);
        leaveok(Compwin, TRUE);
        leaveok(Playwin, TRUE);
        leaveok(Tablewin, TRUE);
        leaveok(Compwin, TRUE);
+       clearok(stdscr, FALSE);
 
        if (!quiet) {
            msg("Do you need instructions for cribbage? ");
 
        if (!quiet) {
            msg("Do you need instructions for cribbage? ");
@@ -153,6 +155,7 @@ game()
        BOOLEAN                 compcrib;
 
        makeboard();
        BOOLEAN                 compcrib;
 
        makeboard();
+       refresh();
        makedeck(deck);
        shuffle(deck);
        if (gamecount == 0) {
        makedeck(deck);
        shuffle(deck);
        if (gamecount == 0) {
@@ -245,10 +248,6 @@ BOOLEAN            mycrib;
        extern char             Msgbuf[];
 
        werase(Compwin);
        extern char             Msgbuf[];
 
        werase(Compwin);
-       wrefresh(Compwin);
-       move(CRIB_Y, SCORE_SZ);
-       clrtobot();
-       mvaddstr(LINES - 1, 0, Msgbuf);
 
        knownum = 0;
        deckpos = deal(mycrib);
 
        knownum = 0;
        deckpos = deal(mycrib);
@@ -371,15 +370,23 @@ int               pos;
 prcrib(mycrib, blank)
 BOOLEAN                mycrib, blank;
 {
 prcrib(mycrib, blank)
 BOOLEAN                mycrib, blank;
 {
-       register int    cardx;
+       register int    y, cardx;
 
        if (mycrib)
            cardx = CRIB_X;
        else
 
        if (mycrib)
            cardx = CRIB_X;
        else
-           cardx = SCORE_SZ;
+           cardx = X_SCORE_SZ;
 
        mvaddstr(CRIB_Y, cardx + 1, "CRIB");
        prcard(stdscr, CRIB_Y + 1, cardx, turnover, blank);
 
        mvaddstr(CRIB_Y, cardx + 1, "CRIB");
        prcard(stdscr, CRIB_Y + 1, cardx, turnover, blank);
+
+       if (mycrib)
+           cardx = X_SCORE_SZ;
+       else
+           cardx = CRIB_X;
+
+       for (y = CRIB_Y; y <= CRIB_Y + 5; y++)
+           mvaddstr(y, cardx, "       ");
 }
 
 /*
 }
 
 /*
@@ -430,7 +437,6 @@ BOOLEAN             mycrib;
                        sum = 0;
                        mego = ugo = FALSE;
                        Tcnt = 0;
                        sum = 0;
                        mego = ugo = FALSE;
                        Tcnt = 0;
-                       Hasread = FALSE;
                    }
                }
                else {
                    }
                }
                else {
@@ -476,7 +482,6 @@ BOOLEAN             mycrib;
                        sum = 0;
                        mego = ugo = FALSE;
                        Tcnt = 0;
                        sum = 0;
                        mego = ugo = FALSE;
                        Tcnt = 0;
-                       Hasread = FALSE;
                    }
                }
                else {                                  /* player plays */
                    }
                }
                else {                                  /* player plays */
@@ -512,7 +517,6 @@ BOOLEAN             mycrib;
                mego = ugo = FALSE;
                Tcnt = 0;
                last = FALSE;                           /* disable last flag */
                mego = ugo = FALSE;
                Tcnt = 0;
                last = FALSE;                           /* disable last flag */
-               Hasread = FALSE;
            }
            if (!pnum && !cnum)
                break;                                  /* both done */
            }
            if (!pnum && !cnum)
                break;                                  /* both done */
index e443101..b2f14c4 100644 (file)
@@ -20,7 +20,6 @@ extern  BOOLEAN               iwon;                   /* if comp won last */
 extern  BOOLEAN                explain;                /* player mistakes explained */
 extern  BOOLEAN                rflag;                  /* if all cuts random */
 extern  BOOLEAN                quiet;                  /* if suppress random mess */
 extern  BOOLEAN                explain;                /* player mistakes explained */
 extern  BOOLEAN                rflag;                  /* if all cuts random */
 extern  BOOLEAN                quiet;                  /* if suppress random mess */
-extern  BOOLEAN                Hasread;                /* has had chance to read msg */
 extern BOOLEAN         playing;                /* currently playing game */
 
 extern  char           expl[];                 /* string for explanation */
 extern BOOLEAN         playing;                /* currently playing game */
 
 extern  char           expl[];                 /* string for explanation */
index 8b8b6bb..ae58ee3 100644 (file)
@@ -6,12 +6,16 @@
 # define       COMP_X          12
 # define       SCORE_Y         0       /* starting position of scoring board */
 # define       SCORE_X         0
 # define       COMP_X          12
 # define       SCORE_Y         0       /* starting position of scoring board */
 # define       SCORE_X         0
-# define       SCORE_SZ        41      /* X size of score board */
+# define       Y_SCORE_SZ      11      /* X size of score board */
+# define       X_SCORE_SZ      41      /* X size of score board */
 # define       CRIB_Y          17      /* position of crib (cut card) */
 # define       CRIB_Y          17      /* position of crib (cut card) */
-# define       CRIB_X          (PLAY_X + TABLE_X + SCORE_SZ)
+# define       CRIB_X          (PLAY_X + TABLE_X + X_SCORE_SZ)
+# define       MSG_Y           (LINES - (Y_SCORE_SZ + 1))
+# define       MSG_X           X_SCORE_SZ
 
 # define       PEG     '*'     /* what a peg looks like on the board */
 
 
 # define       PEG     '*'     /* what a peg looks like on the board */
 
+extern WINDOW          *Compwin;               /* computer's hand window */
+extern WINDOW          *Msgwin;                /* message window */
 extern WINDOW          *Playwin;               /* player's hand window */
 extern WINDOW          *Tablewin;              /* table window */
 extern WINDOW          *Playwin;               /* player's hand window */
 extern WINDOW          *Tablewin;              /* table window */
-extern WINDOW          *Compwin;               /* computer's hand window */
index 4d2858e..73cd409 100644 (file)
@@ -2,29 +2,29 @@
 # include      "deck.h"
 # include      "cribbage.h"
 
 # include      "deck.h"
 # include      "cribbage.h"
 
-bool           iwon            = FALSE;        /* if comp won last game */
-bool           explain         = FALSE;        /* player mistakes explained */
-bool           rflag           = FALSE;        /* if all cuts random */
-bool           quiet           = FALSE;        /* if suppress random mess */
-bool           Hasread         = TRUE;         /* if has read msg */
+bool   explain         = FALSE;        /* player mistakes explained */
+bool   iwon            = FALSE;        /* if comp won last game */
+bool   quiet           = FALSE;        /* if suppress random mess */
+bool   rflag           = FALSE;        /* if all cuts random */
 
 
-char           expl[128];                      /* explanation */
+char   expl[128];                      /* explanation */
 
 
-int            knownum         = 0;            /* number of cards we know */
-int            pscore          = 0;            /* player score in this game */
-int            cscore          = 0;            /* comp score in this game */
-int            pgames          = 0;            /* number games player won */
-int            cgames          = 0;            /* number games comp won */
-int            gamecount       = 0;            /* number games played */
-int            glimit          = LGAME;        /* game playe to glimit */
+int    cgames          = 0;            /* number games comp won */
+int    cscore          = 0;            /* comp score in this game */
+int    gamecount       = 0;            /* number games played */
+int    glimit          = LGAME;        /* game playe to glimit */
+int    knownum         = 0;            /* number of cards we know */
+int    pgames          = 0;            /* number games player won */
+int    pscore          = 0;            /* player score in this game */
 
 
-CARD           deck[CARDS];                    /* a deck */
-CARD           phand[FULLHAND];                /* player's hand */
-CARD           chand[FULLHAND];                /* computer's hand */
-CARD           crib[CINHAND];                  /* the crib */
-CARD           turnover;                       /* the starter */
-CARD           known[CARDS];                   /* cards we have seen */
+CARD   chand[FULLHAND];                /* computer's hand */
+CARD   crib[CINHAND];                  /* the crib */
+CARD   deck[CARDS];                    /* a deck */
+CARD   known[CARDS];                   /* cards we have seen */
+CARD   phand[FULLHAND];                /* player's hand */
+CARD   turnover;                       /* the starter */
 
 
-WINDOW         *Playwin;                       /* player's hand window */
-WINDOW         *Tablewin;                      /* table window */
-WINDOW         *Compwin;                       /* computer's hand window */
+WINDOW *Compwin;                       /* computer's hand window */
+WINDOW *Msgwin;                        /* messages for the player */
+WINDOW *Playwin;                       /* player's hand window */
+WINDOW *Tablewin;                      /* table window */
index 0c564cc..4096ae3 100644 (file)
@@ -3,9 +3,13 @@
 # include      <unctrl.h>
 # include      "deck.h"
 # include      "cribbage.h"
 # include      <unctrl.h>
 # include      "deck.h"
 # include      "cribbage.h"
+# include      "cribcur.h"
 
 # define       LINESIZE                128
 
 
 # define       LINESIZE                128
 
+# ifdef CTRL
+# undef CTRL
+# endif
 # define       CTRL(X)                 ('X' - 'A' + 1)
 
 # ifndef       attron
 # define       CTRL(X)                 ('X' - 'A' + 1)
 
 # ifndef       attron
@@ -275,7 +279,7 @@ getuchar()
        c = readchar();
        if (islower(c))
            c = toupper(c);
        c = readchar();
        if (islower(c))
            c = toupper(c);
-       addch(c);
+       waddch(Msgwin, c);
        return c;
 }
 
        return c;
 }
 
@@ -336,19 +340,6 @@ msg(fmt, args)
 char   *fmt;
 int    args;
 {
 char   *fmt;
 int    args;
 {
-    /*
-     * if the string is "", just clear the line
-     */
-    if (*fmt == '\0') {
-       move(LINES - 1, 0);
-       clrtoeol();
-       Mpos = 0;
-       Hasread = TRUE;
-       return;
-    }
-    /*
-     * otherwise add to the message and flush it out
-     */
     doadd(fmt, &args);
     endmsg();
 }
     doadd(fmt, &args);
     endmsg();
 }
@@ -367,29 +358,45 @@ int       args;
 
 /*
  * endmsg:
 
 /*
  * endmsg:
- *     Display a new msg (giving him a chance to see the previous one
- *     if it is up there with the --More--)
+ *     Display a new msg.
  */
 endmsg()
 {
  */
 endmsg()
 {
-    if (!Hasread) {
-       move(LINES - 1, Mpos);
-       addstr("--More--");
-       refresh();
-       wait_for(' ');
-    }
+    register int       len;
+    register char      *mp, *omp;
+    static int         lineno = 0;
+
     /*
      * All messages should start with uppercase, except ones that
      * start with a pack addressing character
      */
     if (islower(Msgbuf[0]) && Msgbuf[1] != ')')
        Msgbuf[0] = toupper(Msgbuf[0]);
     /*
      * All messages should start with uppercase, except ones that
      * start with a pack addressing character
      */
     if (islower(Msgbuf[0]) && Msgbuf[1] != ')')
        Msgbuf[0] = toupper(Msgbuf[0]);
-    mvaddstr(LINES - 1, 0, Msgbuf);
-    clrtoeol();
+    mp = Msgbuf;
+    len = strlen(mp);
+    if (len / MSG_X + lineno > MSG_Y)
+       lineno = 0;
+    do {
+       mvwaddstr(Msgwin, lineno, 0, mp);
+       if ((len = strlen(mp)) > MSG_X) {
+           omp = mp;
+           for (mp = &mp[MSG_X-1]; *mp != ' '; mp--)
+               continue;
+           while (*mp == ' ')
+               mp--;
+           mp++;
+           wmove(Msgwin, lineno, mp - omp);
+           wclrtoeol(Msgwin);
+       }
+       if (++lineno >= MSG_Y)
+           lineno = 0;
+    } while (len > MSG_X);
+    wclrtoeol(Msgwin);
     Mpos = Newpos;
     Newpos = 0;
     Mpos = Newpos;
     Newpos = 0;
+    wrefresh(Msgwin);
     refresh();
     refresh();
-    Hasread = FALSE;
+    wrefresh(Msgwin);
 }
 
 /*
 }
 
 /*
@@ -448,7 +455,6 @@ over:
        wrefresh(curscr);
        goto over;
     }
        wrefresh(curscr);
        goto over;
     }
-    Hasread = TRUE;
     if (c == '\r')
        return '\n';
     else
     if (c == '\r')
        return '\n';
     else
@@ -465,7 +471,10 @@ getline()
 {
     register char      *sp;
     register int       c, oy, ox;
 {
     register char      *sp;
     register int       c, oy, ox;
+    register WINDOW    *oscr;
 
 
+    oscr = stdscr;
+    stdscr = Msgwin;
     getyx(stdscr, oy, ox);
     refresh();
     /*
     getyx(stdscr, oy, ox);
     refresh();
     /*
@@ -498,10 +507,10 @@ getline()
                c = toupper(c);
            *sp++ = c;
            addstr(unctrl(c));
                c = toupper(c);
            *sp++ = c;
            addstr(unctrl(c));
-/*###366 [cc] Mpos undefined %%%*/
            Mpos++;
        }
     }
     *sp = '\0';
            Mpos++;
        }
     }
     *sp = '\0';
+    stdscr = oscr;
     return linebuf;
 }
     return linebuf;
 }
index 16e7d30..aecb00b 100644 (file)
@@ -119,7 +119,6 @@ char                *s;
 
        j = scorehand(h, turnover, CINHAND, FALSE, FALSE);
        prhand(h, CINHAND, Compwin, FALSE);
 
        j = scorehand(h, turnover, CINHAND, FALSE, FALSE);
        prhand(h, CINHAND, Compwin, FALSE);
-       Hasread = FALSE;
        msg("My %s scores %d", s, (j == 0 ? 19 : j));
        return chkscr(&cscore, j);
 }
        msg("My %s scores %d", s, (j == 0 ? 19 : j));
        return chkscr(&cscore, j);
 }