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