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