]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - monop/execute.c
1 /* $NetBSD: execute.c,v 1.5 1998/09/11 13:54:08 hubertf Exp $ */
4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include <sys/cdefs.h>
39 static char sccsid
[] = "@(#)execute.c 8.1 (Berkeley) 5/31/93";
41 __RCSID("$NetBSD: execute.c,v 1.5 1998/09/11 13:54:08 hubertf Exp $");
49 #include <sys/types.h>
55 typedef struct stat STAT
;
56 typedef struct tm TIME
;
60 static bool new_play
; /* set if move on to new player */
62 static void show_move
__P((void));
65 * This routine executes the given command by index number
72 new_play
= FALSE
; /* new_play is true if fixing */
79 printf("%s rolled doubles. Goes again\n", cur_p
->name
);
82 * This routine moves a piece around.
91 new_play
= was_jail
= FALSE
;
92 printf("roll is %d, %d\n", r1
=roll(1, 6), r2
=roll(1, 6));
93 if (cur_p
->loc
== JAIL
) {
95 if (!move_jail(r1
, r2
)) {
101 if (r1
== r2
&& ++num_doub
== 3) {
102 printf("That's 3 doubles. You go to jail\n");
109 if (r1
!= r2
|| was_jail
)
115 * This routine moves a normal move
124 old_loc
= cur_p
->loc
;
125 cur_p
->loc
= (cur_p
->loc
+ rl
) % N_SQRS
;
126 if (cur_p
->loc
< old_loc
&& rl
> 0) {
128 printf("You pass %s and get $200\n", board
[0].name
);
133 * This routine shows the results of a move
141 sqp
= &board
[cur_p
->loc
];
142 printf("That puts you on %s\n", sqp
->name
);
145 printf("That is a safe place\n");
160 if (sqp
->owner
< 0) {
161 printf("That would cost $%d\n", sqp
->cost
);
162 if (getyn("Do you want to buy? ") == 0) {
164 cur_p
->money
-= sqp
->cost
;
166 else if (num_play
> 2)
169 else if (sqp
->owner
== player
)
170 printf("You own it.\n");
176 * This routine saves the current game for use at a later date
188 printf("Which file do you wish to save it in? ");
190 while ((*sp
++=getchar()) != '\n')
195 * check for existing files, and confirm overwrite if needed
198 if (stat(buf
, &sb
) > -1
199 && getyn("File exists. Do you wish to overwrite? ") > 0)
202 if ((outf
=creat(buf
, 0644)) < 0) {
206 printf("\"%s\" ", buf
);
207 time(&t
); /* get current time */
208 strcpy(buf
, ctime(&t
));
209 for (sp
= buf
; *sp
!= '\n'; sp
++)
214 while (start
< end
) { /* write out entire data space */
215 num
= start
+ 16 * 1024 > end
? end
- start
: 16 * 1024;
216 write(outf
, start
, num
);
220 printf("[%s]\n", buf
);
223 * This routine restores an old game from a file
231 printf("Which file do you wish to restore from? ");
232 for (sp
= buf
; (*sp
=getchar()) != '\n'; sp
++)
238 * This does the actual restoring. It returns TRUE if the
239 * backup was successful, else false.
252 if ((inf
=open(file
, O_RDONLY
)) < 0) {
256 printf("\"%s\" ", file
);
257 if (fstat(inf
, &sbuf
) < 0) { /* get file stats */
262 brk(end
= start
+ sbuf
.st_size
);
263 while (start
< end
) { /* write out entire data space */
264 num
= start
+ 16 * 1024 > end
? end
- start
: 16 * 1024;
265 read(inf
, start
, num
);
269 strcpy(buf
, ctime(&sbuf
.st_mtime
));
270 for (sp
= buf
; *sp
!= '\n'; sp
++)
273 printf("[%s]\n", buf
);