Annotation of 42BSD/games/mille/misc.c, revision 1.1

1.1     ! root        1: #include       "mille.h"
        !             2: # ifdef        attron
        !             3: #      include <term.h>
        !             4: #      define  _tty    cur_term->Nttyb
        !             5: # endif        attron
        !             6: 
        !             7: /*
        !             8:  * @(#)misc.c  1.3 (Berkeley) 7/2/83
        !             9:  */
        !            10: 
        !            11: #define        NUMSAFE 4
        !            12: 
        !            13: /* VARARGS1 */
        !            14: error(str, arg)
        !            15: char   *str;
        !            16: {
        !            17:        stdscr = Score;
        !            18:        mvprintw(ERR_Y, ERR_X, str, arg);
        !            19:        clrtoeol();
        !            20:        putchar('');
        !            21:        refresh();
        !            22:        stdscr = Board;
        !            23:        return FALSE;
        !            24: }
        !            25: 
        !            26: CARD
        !            27: getcard()
        !            28: {
        !            29:        reg char        c, c1;
        !            30: 
        !            31:        for (;;) {
        !            32:                while ((c = readch()) == '\n' || c == '\r' || c == ' ')
        !            33:                        continue;
        !            34:                if (islower(c))
        !            35:                        c = toupper(c);
        !            36:                if (c == _tty.sg_kill || c == _tty.sg_erase)
        !            37:                        return -1;
        !            38:                addstr(unctrl(c));
        !            39:                clrtoeol();
        !            40:                switch (c) {
        !            41:                  case '1':     case '2':       case '3':
        !            42:                  case '4':     case '5':       case '6':
        !            43:                        c -= '0';
        !            44:                        break;
        !            45:                  case '0':     case 'P':       case 'p':
        !            46:                        c = 0;
        !            47:                        break;
        !            48:                  default:
        !            49:                        putchar('');
        !            50:                        addch('\b');
        !            51:                        if (!isprint(c))
        !            52:                                addch('\b');
        !            53:                        c = -1;
        !            54:                        break;
        !            55:                }
        !            56:                refresh();
        !            57:                if (c >= 0) {
        !            58:                        while ((c1=readch()) != '\r' && c1 != '\n' && c1 != ' ')
        !            59:                                if (c1 == _tty.sg_kill)
        !            60:                                        return -1;
        !            61:                                else if (c1 == _tty.sg_erase) {
        !            62:                                        addch('\b');
        !            63:                                        clrtoeol();
        !            64:                                        refresh();
        !            65:                                        goto cont;
        !            66:                                }
        !            67:                                else
        !            68:                                        write(0, "", 1);
        !            69:                        return c;
        !            70:                }
        !            71: cont:          ;
        !            72:        }
        !            73: }
        !            74: 
        !            75: check_ext(forcomp)
        !            76: reg bool       forcomp; {
        !            77: 
        !            78: 
        !            79:        if (End == 700)
        !            80:                if (Play == PLAYER) {
        !            81:                        if (getyn("Extension? ")) {
        !            82: extend:
        !            83:                                if (!forcomp)
        !            84:                                        End = 1000;
        !            85:                                return TRUE;
        !            86:                        }
        !            87:                        else {
        !            88: done:
        !            89:                                if (!forcomp)
        !            90:                                        Finished = TRUE;
        !            91:                                return FALSE;
        !            92:                        }
        !            93:                }
        !            94:                else {
        !            95:                        reg PLAY        *pp, *op;
        !            96:                        reg int         i, safe, miles;
        !            97: 
        !            98:                        pp = &Player[COMP];
        !            99:                        op = &Player[PLAYER];
        !           100:                        for (safe = 0, i = 0; i < NUMSAFE; i++)
        !           101:                                if (pp->safety[i] != S_UNKNOWN)
        !           102:                                        safe++;
        !           103:                        if (safe < 2)
        !           104:                                goto done;
        !           105:                        if (op->mileage == 0 || onecard(op)
        !           106:                            || (op->can_go && op->mileage >= 500))
        !           107:                                goto done;
        !           108:                        for (miles = 0, i = 0; i < NUMSAFE; i++)
        !           109:                                if (op->safety[i] != S_PLAYED
        !           110:                                    && pp->safety[i] == S_UNKNOWN)
        !           111:                                        miles++;
        !           112:                        if (miles + safe == NUMSAFE)
        !           113:                                goto extend;
        !           114:                        for (miles = 0, i = 0; i < HAND_SZ; i++)
        !           115:                                if ((safe = pp->hand[i]) <= C_200)
        !           116:                                        miles += Value[safe]; 
        !           117:                        if (miles + (Topcard - Deck) * 3 > 1000)
        !           118:                                goto extend;
        !           119:                        goto done;
        !           120:                }
        !           121:        else
        !           122:                goto done;
        !           123: }
        !           124: 
        !           125: /*
        !           126:  *     Get a yes or no answer to the given question.  Saves are
        !           127:  * also allowed.  Return TRUE if the answer was yes, FALSE if no.
        !           128:  */
        !           129: getyn(prompt)
        !           130: reg char       *prompt; {
        !           131: 
        !           132:        reg char        c;
        !           133: 
        !           134:        Saved = FALSE;
        !           135:        for (;;) {
        !           136:                leaveok(Board, FALSE);
        !           137:                mvaddstr(MOVE_Y, MOVE_X, prompt);
        !           138:                clrtoeol();
        !           139:                refresh();
        !           140:                switch (c = readch()) {
        !           141:                  case 'n':     case 'N':
        !           142:                        addch('N');
        !           143:                        refresh();
        !           144:                        leaveok(Board, TRUE);
        !           145:                        return FALSE;
        !           146:                  case 'y':     case 'Y':
        !           147:                        addch('Y');
        !           148:                        refresh();
        !           149:                        leaveok(Board, TRUE);
        !           150:                        return TRUE;
        !           151:                  case 's':     case 'S':
        !           152:                        addch('S');
        !           153:                        refresh();
        !           154:                        Saved = save();
        !           155:                        continue;
        !           156:                  default:
        !           157:                        addstr(unctrl(c));
        !           158:                        refresh();
        !           159:                        putchar('');
        !           160:                        break;
        !           161:                }
        !           162:        }
        !           163: }
        !           164: 
        !           165: /*
        !           166:  *     Check to see if more games are desired.  If not, and game
        !           167:  * came from a saved file, make sure that they don't want to restore
        !           168:  * it.  Exit appropriately.
        !           169:  */
        !           170: check_more() {
        !           171: 
        !           172:        raw();  /* Flush input */
        !           173:        noraw();
        !           174: 
        !           175:        On_exit = TRUE;
        !           176:        if (Player[PLAYER].total >= 5000 || Player[COMP].total >= 5000)
        !           177:                if (getyn("Another game? "))
        !           178:                        return;
        !           179:                else {
        !           180:                        /*
        !           181:                         * must do accounting normally done in main()
        !           182:                         */
        !           183:                        if (Player[PLAYER].total > Player[COMP].total)
        !           184:                                Player[PLAYER].games++;
        !           185:                        else if (Player[PLAYER].total < Player[COMP].total)
        !           186:                                Player[COMP].games++;
        !           187:                        Player[COMP].total = 0;
        !           188:                        Player[PLAYER].total = 0;
        !           189:                }
        !           190:        else
        !           191:                if (getyn("Another hand? "))
        !           192:                        return;
        !           193:        if (!Saved && getyn("Save game? "))
        !           194:                if (!save())
        !           195:                        return;
        !           196:        die();
        !           197: }
        !           198: 
        !           199: readch()
        !           200: {
        !           201:        reg int         cnt;
        !           202:        static char     c;
        !           203: 
        !           204:        for (cnt = 0; read(0, &c, 1) <= 0; cnt++)
        !           205:                if (cnt > 100)
        !           206:                        exit(1);
        !           207:        return c;
        !           208: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.