Commit | Line | Data |
---|---|---|
c6a4b686 | 1 | /* |
8d242c56 KB |
2 | * Copyright (c) 1982 Regents of the University of California. |
3 | * All rights reserved. | |
4 | * | |
7c5ab767 | 5 | * %sccs.include.redist.c% |
c6a4b686 KB |
6 | */ |
7 | ||
8 | #ifndef lint | |
8d242c56 KB |
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 | |
786b3585 | 15 | static char sccsid[] = "@(#)mille.c 5.5 (Berkeley) %G%"; |
8d242c56 | 16 | #endif /* not lint */ |
c6a4b686 KB |
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 | ||
786b3585 | 28 | void rub(); |
c6a4b686 | 29 | |
c6a4b686 KB |
30 | main(ac, av) |
31 | reg int ac; | |
32 | reg char *av[]; { | |
33 | ||
34 | reg bool restore; | |
8d242c56 KB |
35 | |
36 | /* run as the user */ | |
37 | setuid(getuid()); | |
c6a4b686 KB |
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; | |
c6a4b686 KB |
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 | } | |
c6a4b686 KB |
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 | */ | |
786b3585 | 123 | void |
c6a4b686 KB |
124 | rub() { |
125 | ||
8d242c56 | 126 | (void)signal(SIGINT, SIG_IGN); |
c6a4b686 KB |
127 | if (getyn(REALLYPROMPT)) |
128 | die(); | |
8d242c56 | 129 | (void)signal(SIGINT, rub); |
c6a4b686 KB |
130 | } |
131 | ||
132 | /* | |
133 | * Time to go beddy-by | |
134 | */ | |
135 | die() { | |
136 | ||
8d242c56 | 137 | (void)signal(SIGINT, SIG_IGN); |
c6a4b686 KB |
138 | if (outf) |
139 | fflush(outf); | |
140 | mvcur(0, COLS - 1, LINES - 1, 0); | |
141 | endwin(); | |
142 | exit(1); | |
143 | } | |
144 |