add a scrolling region
authorKen Arnold <arnold@ucbvax.Berkeley.EDU>
Sun, 8 May 1983 05:07:02 +0000 (21:07 -0800)
committerKen Arnold <arnold@ucbvax.Berkeley.EDU>
Sun, 8 May 1983 05:07:02 +0000 (21:07 -0800)
SCCS-vsn: games/cribbage/crib.c 1.15
SCCS-vsn: games/cribbage/io.c 1.9
SCCS-vsn: games/cribbage/support.c 1.11
SCCS-vsn: games/cribbage/cribcur.h 1.4

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

index 4a6834f..4383b3a 100644 (file)
@@ -53,10 +53,10 @@ char        *argv[];
        signal(SIGINT, bye);
        crmode();
        noecho();
        signal(SIGINT, bye);
        crmode();
        noecho();
-       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);
+       Playwin = subwin(stdscr, PLAY_Y, PLAY_X, 0, 0);
+       Tablewin = subwin(stdscr, TABLE_Y, TABLE_X, 0, PLAY_X);
+       Compwin = subwin(stdscr, COMP_Y, COMP_X, 0, TABLE_X + PLAY_X);
+       Msgwin = subwin(stdscr, MSG_Y, MSG_X, Y_MSG_START, SCORE_X + 1);
        leaveok(Playwin, TRUE);
        leaveok(Tablewin, TRUE);
        leaveok(Compwin, TRUE);
        leaveok(Playwin, TRUE);
        leaveok(Tablewin, TRUE);
        leaveok(Compwin, TRUE);
@@ -77,6 +77,7 @@ char  *argv[];
        }
        playing = TRUE;
        do {
        }
        playing = TRUE;
        do {
+           wclrtobot(Msgwin);
            msg(quiet ? "L or S? " : "Long (to 121) or Short (to 61)? ");
            if (glimit == SGAME)
                glimit = (getuchar() == 'L' ? LGAME : SGAME);
            msg(quiet ? "L or S? " : "Long (to 121) or Short (to 61)? ");
            if (glimit == SGAME)
                glimit = (getuchar() == 'L' ? LGAME : SGAME);
@@ -192,7 +193,7 @@ game()
            wrefresh(Tablewin);
            werase(Compwin);
            wrefresh(Compwin);
            wrefresh(Tablewin);
            werase(Compwin);
            wrefresh(Compwin);
-           msg("Loser (%s) gets first crib.",  (iwon ? "you" : "me"));
+           msg("Loser (%s) gets first crib",  (iwon ? "you" : "me"));
            compcrib = !iwon;
        }
 
            compcrib = !iwon;
        }
 
@@ -343,7 +344,7 @@ int         pos;
            msgcard(turnover, FALSE);
            endmsg();
            if (turnover.rank == JACK) {
            msgcard(turnover, FALSE);
            endmsg();
            if (turnover.rank == JACK) {
-               msg("I get two for his heels.");
+               msg("I get two for his heels");
                win = chkscr(&cscore,2 );
            }
        }
                win = chkscr(&cscore,2 );
            }
        }
@@ -354,7 +355,7 @@ int         pos;
            msgcard(turnover, FALSE);
            endmsg();
            if (turnover.rank == JACK) {
            msgcard(turnover, FALSE);
            endmsg();
            if (turnover.rank == JACK) {
-               msg("You get two for his heels.");
+               msg("You get two for his heels");
                win = chkscr(&pscore, 2);
            }
        }
                win = chkscr(&pscore, 2);
            }
        }
@@ -375,13 +376,13 @@ BOOLEAN           mycrib, blank;
        if (mycrib)
            cardx = CRIB_X;
        else
        if (mycrib)
            cardx = CRIB_X;
        else
-           cardx = X_SCORE_SZ;
+           cardx = 0;
 
        mvaddstr(CRIB_Y, cardx + 1, "CRIB");
        prcard(stdscr, CRIB_Y + 1, cardx, turnover, blank);
 
        if (mycrib)
 
        mvaddstr(CRIB_Y, cardx + 1, "CRIB");
        prcard(stdscr, CRIB_Y + 1, cardx, turnover, blank);
 
        if (mycrib)
-           cardx = X_SCORE_SZ;
+           cardx = 0;
        else
            cardx = CRIB_X;
 
        else
            cardx = CRIB_X;
 
@@ -425,13 +426,13 @@ BOOLEAN           mycrib;
            if (myturn) {                               /* my tyrn to play */
                if (!anymove(ch, cnum, sum)) {          /* if no card to play */
                    if (!mego && cnum) {                /* go for comp? */
            if (myturn) {                               /* my tyrn to play */
                if (!anymove(ch, cnum, sum)) {          /* if no card to play */
                    if (!mego && cnum) {                /* go for comp? */
-                       msg("GO.");
+                       msg("GO");
                        mego = TRUE;
                    }
                    if (anymove(ph, pnum, sum))         /* can player move? */
                        myturn = !myturn;
                    else {                              /* give him his point */
                        mego = TRUE;
                    }
                    if (anymove(ph, pnum, sum))         /* can player move? */
                        myturn = !myturn;
                    else {                              /* give him his point */
-                       msg(quiet ? "You get one." : "You get one point.");
+                       msg(quiet ? "You get one" : "You get one point");
                        if (chkscr(&pscore, 1))
                            return TRUE;
                        sum = 0;
                        if (chkscr(&pscore, 1))
                            return TRUE;
                        sum = 0;
@@ -470,13 +471,14 @@ BOOLEAN           mycrib;
            else {
                if (!anymove(ph, pnum, sum)) {          /* can player move? */
                    if (!ugo && pnum) {                 /* go for player */
            else {
                if (!anymove(ph, pnum, sum)) {          /* can player move? */
                    if (!ugo && pnum) {                 /* go for player */
-                       msg("You have a GO.");
+                       msg("You have a GO");
                        ugo = TRUE;
                    }
                    if (anymove(ch, cnum, sum))         /* can computer play? */
                        myturn = !myturn;
                    else {
                        ugo = TRUE;
                    }
                    if (anymove(ch, cnum, sum))         /* can computer play? */
                        myturn = !myturn;
                    else {
-                       msg(quiet ? "I get one." : "I get one point.");
+                       msg(quiet ? "I get one" : "I get one point");
+                       do_wait();
                        if (chkscr(&cscore, 1))
                            return TRUE;
                        sum = 0;
                        if (chkscr(&cscore, 1))
                            return TRUE;
                        sum = 0;
@@ -497,7 +499,7 @@ BOOLEAN             mycrib;
                            if (sum + VAL(crd.rank) <= 31)
                                break;
                            else
                            if (sum + VAL(crd.rank) <= 31)
                                break;
                            else
-                               msg("Total > 31 -- try again.");
+                               msg("Total > 31 -- try again");
                        }
                    makeknown(&crd, 1);
                    remove(crd, ph, pnum--);
                        }
                    makeknown(&crd, 1);
                    remove(crd, ph, pnum--);
@@ -513,6 +515,8 @@ BOOLEAN             mycrib;
                }
            }
            if (sum >= 31) {
                }
            }
            if (sum >= 31) {
+               if (!myturn)
+                   do_wait();
                sum = 0;
                mego = ugo = FALSE;
                Tcnt = 0;
                sum = 0;
                mego = ugo = FALSE;
                Tcnt = 0;
@@ -527,6 +531,7 @@ BOOLEAN             mycrib;
        if (last)
            if (played) {
                msg(quiet ? "I get one for last" : "I get one point for last");
        if (last)
            if (played) {
                msg(quiet ? "I get one for last" : "I get one point for last");
+               do_wait();
                if (chkscr(&cscore, 1))
                    return TRUE;
            }
                if (chkscr(&cscore, 1))
                    return TRUE;
            }
@@ -564,6 +569,7 @@ BOOLEAN             mycrib;
                return TRUE;
            if (comphand(chand, "hand"))
                return TRUE;
                return TRUE;
            if (comphand(chand, "hand"))
                return TRUE;
+           do_wait();
            if (comphand(crib, "crib"))
                return TRUE;
        }
            if (comphand(crib, "crib"))
                return TRUE;
        }
index ae58ee3..f9d3574 100644 (file)
@@ -4,14 +4,15 @@
 # define       TABLE_X         14
 # define       COMP_Y          15      /* size of computer's hand window */
 # define       COMP_X          12
 # define       TABLE_X         14
 # define       COMP_Y          15      /* size of computer's hand window */
 # define       COMP_X          12
-# define       SCORE_Y         0       /* starting position of scoring board */
-# define       SCORE_X         0
-# define       Y_SCORE_SZ      11      /* X size of score board */
+# define       Y_SCORE_SZ      9       /* Y size of score board */
 # define       X_SCORE_SZ      41      /* X size of score board */
 # define       X_SCORE_SZ      41      /* X size of score board */
+# define       SCORE_Y         0       /* starting position of scoring board */
+# define       SCORE_X         (PLAY_X + TABLE_X + COMP_X)
 # 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 + X_SCORE_SZ)
+# define       CRIB_X          (PLAY_X + TABLE_X)
 # define       MSG_Y           (LINES - (Y_SCORE_SZ + 1))
 # define       MSG_Y           (LINES - (Y_SCORE_SZ + 1))
-# define       MSG_X           X_SCORE_SZ
+# define       MSG_X           (COLS - SCORE_X - 1)
+# define       Y_MSG_START     (Y_SCORE_SZ + 1)
 
 # define       PEG     '*'     /* what a peg looks like on the board */
 
 
 # define       PEG     '*'     /* what a peg looks like on the board */
 
index 4096ae3..6fd82cc 100644 (file)
@@ -360,24 +360,29 @@ int       args;
  * endmsg:
  *     Display a new msg.
  */
  * endmsg:
  *     Display a new msg.
  */
+
+int    Lineno = 0;
+
 endmsg()
 {
     register int       len;
     register char      *mp, *omp;
 endmsg()
 {
     register int       len;
     register char      *mp, *omp;
-    static int         lineno = 0;
+    static int         lastline = 0;
 
     /*
 
     /*
-     * All messages should start with uppercase, except ones that
-     * start with a pack addressing character
+     * All messages should start with uppercase
      */
      */
+    mvaddch(lastline + Y_MSG_START, SCORE_X, ' ');
     if (islower(Msgbuf[0]) && Msgbuf[1] != ')')
        Msgbuf[0] = toupper(Msgbuf[0]);
     mp = Msgbuf;
     len = strlen(mp);
     if (islower(Msgbuf[0]) && Msgbuf[1] != ')')
        Msgbuf[0] = toupper(Msgbuf[0]);
     mp = Msgbuf;
     len = strlen(mp);
-    if (len / MSG_X + lineno > MSG_Y)
-       lineno = 0;
+    if (len / MSG_X + Lineno >= MSG_Y)
+       Lineno = 0;
+    mvaddch(Lineno + Y_MSG_START, SCORE_X, '*');
+    lastline = Lineno;
     do {
     do {
-       mvwaddstr(Msgwin, lineno, 0, mp);
+       mvwaddstr(Msgwin, Lineno, 0, mp);
        if ((len = strlen(mp)) > MSG_X) {
            omp = mp;
            for (mp = &mp[MSG_X-1]; *mp != ' '; mp--)
        if ((len = strlen(mp)) > MSG_X) {
            omp = mp;
            for (mp = &mp[MSG_X-1]; *mp != ' '; mp--)
@@ -385,14 +390,14 @@ endmsg()
            while (*mp == ' ')
                mp--;
            mp++;
            while (*mp == ' ')
                mp--;
            mp++;
-           wmove(Msgwin, lineno, mp - omp);
+           wmove(Msgwin, Lineno, mp - omp);
            wclrtoeol(Msgwin);
        }
            wclrtoeol(Msgwin);
        }
-       if (++lineno >= MSG_Y)
-           lineno = 0;
+       if (++Lineno >= MSG_Y)
+           Lineno = 0;
     } while (len > MSG_X);
     wclrtoeol(Msgwin);
     } while (len > MSG_X);
     wclrtoeol(Msgwin);
-    Mpos = Newpos;
+    Mpos = Newpos % MSG_X;
     Newpos = 0;
     wrefresh(Msgwin);
     refresh();
     Newpos = 0;
     wrefresh(Msgwin);
     refresh();
@@ -420,6 +425,28 @@ int        *args;
     Newpos = strlen(Msgbuf);
 }
 
     Newpos = strlen(Msgbuf);
 }
 
+/*
+ * do_wait:
+ *     Wait for the user to type ' ' before doing anything else
+ */
+do_wait()
+{
+    register int line;
+    static char prompt[] = { '-', '-', 'M', 'o', 'r', 'e', '-', '-', '\0' };
+
+    if (Mpos + sizeof prompt < MSG_X)
+       wmove(Msgwin, Lineno > 0 ? Lineno - 1 : MSG_Y - 1, Mpos);
+    else {
+       mvwaddch(Msgwin, Lineno, 0, ' ');
+       wclrtoeol(Msgwin);
+       if (++Lineno >= MSG_Y)
+           Lineno = 0;
+    }
+    waddstr(Msgwin, prompt);
+    wrefresh(Msgwin);
+    wait_for(' ');
+}
+
 /*
  * wait_for
  *     Sit around until the guy types the right key
 /*
  * wait_for
  *     Sit around until the guy types the right key
index aecb00b..2d22205 100644 (file)
@@ -91,7 +91,7 @@ char          *s;
        if (i != j) {
            if (i < j) {
                win = chkscr(&pscore, i);
        if (i != j) {
            if (i < j) {
                win = chkscr(&pscore, i);
-               msg("It's really only %d points, I get %d.", i, 2);
+               msg("It's really only %d points; I get %d", i, 2);
                if (!win)
                    win = chkscr(&cscore, 2);
            }
                if (!win)
                    win = chkscr(&cscore, 2);
            }
@@ -101,6 +101,7 @@ char                *s;
            }
            if (explain)
                msg("Explanation: %s", expl);
            }
            if (explain)
                msg("Explanation: %s", expl);
+           do_wait();
        }
        else
            win = chkscr(&pscore, i);
        }
        else
            win = chkscr(&pscore, i);