1 /* 2 * Copyright (c) 1982 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 char copyright[] = 10 "@(#) Copyright (c) 1982 Regents of the University of California.\n\ 11 All rights reserved.\n"; 12 #endif /* not lint */ 13 14 #ifndef lint 15 static char sccsid[] = "@(#)mille.c 5.4 (Berkeley) 06/01/90"; 16 #endif /* not lint */ 17 18 # include "mille.h" 19 # include <signal.h> 20 # ifdef attron 21 # include <term.h> 22 # endif attron 23 24 /* 25 * @(#)mille.c 1.3 (Berkeley) 5/10/83 26 */ 27 28 int rub(); 29 30 main(ac, av) 31 reg int ac; 32 reg char *av[]; { 33 34 reg bool restore; 35 36 /* run as the user */ 37 setuid(getuid()); 38 39 if (strcmp(av[0], "a.out") == 0) { 40 outf = fopen("q", "w"); 41 setbuf(outf, (char *)NULL); 42 Debug = TRUE; 43 } 44 restore = FALSE; 45 switch (ac) { 46 case 2: 47 rest_f(av[1]); 48 restore = TRUE; 49 case 1: 50 break; 51 default: 52 printf("usage: milles [ restore_file ]\n"); 53 exit(-1); 54 /* NOTREACHED */ 55 } 56 Play = PLAYER; 57 initscr(); 58 # ifdef attron 59 # define CA cursor_address 60 # endif 61 if (!CA) { 62 printf("Sorry. Need cursor addressing to play mille\n"); 63 exit(-1); 64 } 65 delwin(stdscr); 66 stdscr = Board = newwin(BOARD_Y, BOARD_X, 0, 0); 67 Score = newwin(SCORE_Y, SCORE_X, 0, 40); 68 Miles = newwin(MILES_Y, MILES_X, 17, 0); 69 #ifdef attron 70 idlok(Board, TRUE); 71 idlok(Score, TRUE); 72 idlok(Miles, TRUE); 73 #endif 74 leaveok(Score, TRUE); 75 leaveok(Miles, TRUE); 76 clearok(curscr, TRUE); 77 # ifndef PROF 78 srandom(getpid()); 79 # else 80 srandom(0); 81 # endif 82 crmode(); 83 noecho(); 84 signal(SIGINT, rub); 85 for (;;) { 86 if (!restore || (Player[PLAYER].total >= 5000 87 || Player[COMP].total >= 5000)) { 88 if (Player[COMP].total < Player[PLAYER].total) 89 Player[PLAYER].games++; 90 else if (Player[COMP].total > Player[PLAYER].total) 91 Player[COMP].games++; 92 Player[COMP].total = 0; 93 Player[PLAYER].total = 0; 94 } 95 do { 96 if (!restore) 97 Handstart = Play = other(Handstart); 98 if (!restore || On_exit) { 99 shuffle(); 100 init(); 101 } 102 newboard(); 103 if (restore) 104 mvwaddstr(Score, ERR_Y, ERR_X, Initstr); 105 prboard(); 106 do { 107 domove(); 108 if (Finished) 109 newscore(); 110 prboard(); 111 } while (!Finished); 112 check_more(); 113 restore = On_exit = FALSE; 114 } while (Player[COMP].total < 5000 115 && Player[PLAYER].total < 5000); 116 } 117 } 118 119 /* 120 * Routine to trap rubouts, and make sure they really want to 121 * quit. 122 */ 123 rub() { 124 125 (void)signal(SIGINT, SIG_IGN); 126 if (getyn(REALLYPROMPT)) 127 die(); 128 (void)signal(SIGINT, rub); 129 } 130 131 /* 132 * Time to go beddy-by 133 */ 134 die() { 135 136 (void)signal(SIGINT, SIG_IGN); 137 if (outf) 138 fflush(outf); 139 mvcur(0, COLS - 1, LINES - 1, 0); 140 endwin(); 141 exit(1); 142 } 143 144