date and time created 88/06/01 18:39:34 by bostic
[unix-history] / usr / src / games / robots / main.c
CommitLineData
dfd0969b
KM
1/*
2 * Copyright (c) 1980 Regents of the University of California.
4cd7a139
KB
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.
dfd0969b
KM
11 */
12
13#ifndef lint
14char copyright[] =
15"@(#) Copyright (c) 1980 Regents of the University of California.\n\
16 All rights reserved.\n";
4cd7a139 17#endif /* not lint */
dfd0969b
KM
18
19#ifndef lint
4cd7a139
KB
20static char sccsid[] = "@(#)main.c 5.2 (Berkeley) %G%";
21#endif /* not lint */
dfd0969b
KM
22
23# include "robots.h"
24# include <signal.h>
25# include <ctype.h>
26
27main(ac, av)
28int ac;
29char **av;
30{
31 register char *sp;
32 register bool bad_arg;
33 register bool show_only;
34 extern char *Scorefile;
35 extern int Max_per_uid;
36 extern char *rindex();
37
38 show_only = FALSE;
39 if (ac > 1) {
40 bad_arg = FALSE;
41 for (++av; ac > 1 && *av[0]; av++, ac--)
42 if (av[0][0] != '-')
43 if (isdigit(av[0][0]))
44 Max_per_uid = atoi(av[0]);
45 else {
46 setuid(getuid());
47 setgid(getgid());
48 Scorefile = av[0];
49# ifdef FANCY
50 sp = rindex(Scorefile, '/');
51 if (sp == NULL)
52 sp = Scorefile;
53 if (strcmp(sp, "pattern_roll") == 0)
54 Pattern_roll = TRUE;
55 else if (strcmp(sp, "stand_still") == 0)
56 Stand_still = TRUE;
57 if (Pattern_roll || Stand_still)
58 Teleport = TRUE;
59# endif
60 }
61 else
62 for (sp = &av[0][1]; *sp; sp++)
63 switch (*sp) {
64 case 's':
65 show_only = TRUE;
66 break;
67 case 'r':
68 Real_time = TRUE;
69 break;
70 case 'a':
71 Start_level = 4;
72 break;
73 case 'j':
74 Jump = TRUE;
75 break;
76 case 't':
77 Teleport = TRUE;
78 break;
79 default:
80 fprintf(stderr, "robots: uknown option: %c\n", *sp);
81 bad_arg = TRUE;
82 break;
83 }
84 if (bad_arg) {
85 exit(1);
86 /* NOTREACHED */
87 }
88 }
89
90 if (show_only) {
91 show_score();
92 exit(0);
93 /* NOTREACHED */
94 }
95
96 initscr();
97 signal(SIGINT, quit);
98 crmode();
99 noecho();
100 nonl();
101 if (LINES != Y_SIZE || COLS != X_SIZE) {
102 if (LINES < Y_SIZE || COLS < X_SIZE) {
103 endwin();
104 printf("Need at least a %dx%d screen\n", Y_SIZE, X_SIZE);
105 exit(1);
106 }
107 delwin(stdscr);
108 stdscr = newwin(Y_SIZE, X_SIZE, 0, 0);
109 }
110
111 srand(getpid());
112 if (Real_time)
113 signal(SIGALRM, move_robots);
114 do {
115 init_field();
116 for (Level = Start_level; !Dead; Level++) {
117 make_level();
118 play_level();
119 }
120 move(My_pos.y, My_pos.x);
121 printw("AARRrrgghhhh....");
122 refresh();
123 score();
124 } while (another());
125 quit();
126}
127
128/*
129 * quit:
130 * Leave the program elegantly.
131 */
132quit()
133{
134 extern int _putchar();
135
136 mvcur(0, COLS - 1, LINES - 1, 0);
137 if (CE) {
138 tputs(CE, 1, _putchar);
139 endwin();
140 }
141 else {
142 endwin();
143 putchar('\n');
144 }
145 exit(0);
146 /* NOTREACHED */
147}
148
149/*
150 * another:
151 * See if another game is desired
152 */
153another()
154{
155 register int y;
156
157#ifdef FANCY
158 if ((Stand_still || Pattern_roll) && !Newscore)
159 return TRUE;
160#endif
161
162 if (query("Another game?")) {
163 if (Full_clear) {
164 for (y = 1; y <= Num_scores; y++) {
165 move(y, 1);
166 clrtoeol();
167 }
168 refresh();
169 }
170 return TRUE;
171 }
172 return FALSE;
173}