]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - monop/execute.c
72d04773db730f0fcf7d4b637c2bde85566d20a9
1 /* $NetBSD: execute.c,v 1.13 2008/02/19 09:30:26 dholland 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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)execute.c 8.1 (Berkeley) 5/31/93";
37 __RCSID("$NetBSD: execute.c,v 1.13 2008/02/19 09:30:26 dholland Exp $");
45 #include <sys/types.h>
52 typedef struct stat STAT
;
53 typedef struct tm TIME
;
57 static bool new_play
; /* set if move on to new player */
58 extern void *heapstart
;
60 static void show_move(void);
63 * This routine executes the given command by index number
69 new_play
= FALSE
; /* new_play is true if fixing */
76 printf("%s rolled doubles. Goes again\n", cur_p
->name
);
80 * This routine moves a piece around.
88 new_play
= was_jail
= FALSE
;
89 printf("roll is %d, %d\n", r1
=roll(1, 6), r2
=roll(1, 6));
90 if (cur_p
->loc
== JAIL
) {
92 if (!move_jail(r1
, r2
)) {
98 if (r1
== r2
&& ++num_doub
== 3) {
99 printf("That's 3 doubles. You go to jail\n");
106 if (r1
!= r2
|| was_jail
)
113 * This routine moves a normal move
121 old_loc
= cur_p
->loc
;
122 cur_p
->loc
= (cur_p
->loc
+ rl
) % N_SQRS
;
123 if (cur_p
->loc
< old_loc
&& rl
> 0) {
125 printf("You pass %s and get $200\n", board
[0].name
);
131 * This routine shows the results of a move
138 sqp
= &board
[cur_p
->loc
];
139 printf("That puts you on %s\n", sqp
->name
);
142 printf("That is a safe place\n");
157 if (sqp
->owner
< 0) {
158 printf("That would cost $%d\n", sqp
->cost
);
159 if (getyn("Do you want to buy? ") == 0) {
161 cur_p
->money
-= sqp
->cost
;
163 else if (num_play
> 2)
166 else if (sqp
->owner
== player
)
167 printf("You own it.\n");
174 * This routine saves the current game for use at a later date
185 printf("Which file do you wish to save it in? ");
187 while ((*sp
++=getchar()) != '\n')
192 * check for existing files, and confirm overwrite if needed
195 if (stat(buf
, &sb
) > -1
196 && getyn("File exists. Do you wish to overwrite? ") > 0)
199 if ((outf
=creat(buf
, 0644)) < 0) {
203 printf("\"%s\" ", buf
);
204 time(&t
); /* get current time */
205 strcpy(buf
, ctime(&t
));
206 for (sp
= buf
; *sp
!= '\n'; sp
++)
211 while (start
< end
) { /* write out entire data space */
212 num
= start
+ 16 * 1024 > end
? end
- start
: 16 * 1024;
213 write(outf
, start
, num
);
217 printf("[%s]\n", buf
);
221 * This routine restores an old game from a file
228 printf("Which file do you wish to restore from? ");
229 for (sp
= buf
; (*sp
=getchar()) != '\n'; sp
++)
236 * This does the actual restoring. It returns TRUE if the
237 * backup was successful, else false.
249 if ((inf
=open(file
, O_RDONLY
)) < 0) {
253 printf("\"%s\" ", file
);
254 if (fstat(inf
, &sbuf
) < 0) { /* get file stats */
255 err(1, "%s: fstat", file
);
258 brk(end
= start
+ sbuf
.st_size
);
259 while (start
< end
) { /* write out entire data space */
260 num
= start
+ 16 * 1024 > end
? end
- start
: 16 * 1024;
261 read(inf
, start
, num
);
265 strcpy(xbuf
, ctime(&sbuf
.st_mtime
));
266 for (sp
= xbuf
; *sp
!= '\n'; sp
++)
269 printf("[%s]\n", xbuf
);