version 1.3, 1995/03/23 08:34:38 |
version 1.4, 1997/10/12 17:45:09 |
|
|
* SUCH DAMAGE. |
* SUCH DAMAGE. |
*/ |
*/ |
|
|
|
#include <sys/cdefs.h> |
#ifndef lint |
#ifndef lint |
#if 0 |
#if 0 |
static char sccsid[] = "@(#)execute.c 8.1 (Berkeley) 5/31/93"; |
static char sccsid[] = "@(#)execute.c 8.1 (Berkeley) 5/31/93"; |
#else |
#else |
static char rcsid[] = "$NetBSD$"; |
__RCSID("$NetBSD$"); |
#endif |
#endif |
#endif /* not lint */ |
#endif /* not lint */ |
|
|
# include "monop.ext" |
#include "monop.ext" |
# include <sys/types.h> |
#include <fcntl.h> |
# include <sys/stat.h> |
#include <stdlib.h> |
# include <sys/time.h> |
#include <unistd.h> |
|
#include <sys/types.h> |
|
#include <sys/stat.h> |
|
#include <sys/time.h> |
|
|
# define SEGSIZE 8192 |
# define SEGSIZE 8192 |
|
|
typedef struct stat STAT; |
typedef struct stat STAT; |
typedef struct tm TIME; |
typedef struct tm TIME; |
|
|
extern char etext[], /* end of text space */ |
static char buf[257]; |
rub(); |
|
|
|
static char buf[257], |
|
*yn_only[] = { "yes", "no"}; |
|
|
|
static bool new_play; /* set if move on to new player */ |
static bool new_play; /* set if move on to new player */ |
|
|
|
static void show_move __P((void)); |
|
|
/* |
/* |
* This routine executes the given command by index number |
* This routine executes the given command by index number |
*/ |
*/ |
|
void |
execute(com_num) |
execute(com_num) |
reg int com_num; { |
int com_num; |
|
{ |
|
|
new_play = FALSE; /* new_play is true if fixing */ |
new_play = FALSE; /* new_play is true if fixing */ |
(*func[com_num])(); |
(*func[com_num])(); |
Line 77 reg int com_num; { |
|
Line 81 reg int com_num; { |
|
/* |
/* |
* This routine moves a piece around. |
* This routine moves a piece around. |
*/ |
*/ |
do_move() { |
void |
|
do_move() |
|
{ |
|
|
reg int r1, r2; |
int r1, r2; |
reg bool was_jail; |
bool was_jail; |
|
|
new_play = was_jail = FALSE; |
new_play = was_jail = FALSE; |
printf("roll is %d, %d\n", r1=roll(1, 6), r2=roll(1, 6)); |
printf("roll is %d, %d\n", r1=roll(1, 6), r2=roll(1, 6)); |
|
|
/* |
/* |
* This routine moves a normal move |
* This routine moves a normal move |
*/ |
*/ |
|
void |
move(rl) |
move(rl) |
reg int rl; { |
int rl; |
|
{ |
|
|
reg int old_loc; |
int old_loc; |
|
|
old_loc = cur_p->loc; |
old_loc = cur_p->loc; |
cur_p->loc = (cur_p->loc + rl) % N_SQRS; |
cur_p->loc = (cur_p->loc + rl) % N_SQRS; |
|
|
/* |
/* |
* This routine shows the results of a move |
* This routine shows the results of a move |
*/ |
*/ |
show_move() { |
static void |
|
show_move() |
|
{ |
|
|
reg SQUARE *sqp; |
SQUARE *sqp; |
|
|
sqp = &board[cur_p->loc]; |
sqp = &board[cur_p->loc]; |
printf("That puts you on %s\n", sqp->name); |
printf("That puts you on %s\n", sqp->name); |
|
|
cur_p->money -= sqp->cost; |
cur_p->money -= sqp->cost; |
} |
} |
else if (num_play > 2) |
else if (num_play > 2) |
bid(sqp); |
bid(); |
} |
} |
else if (sqp->owner == player) |
else if (sqp->owner == player) |
printf("You own it.\n"); |
printf("You own it.\n"); |
|
|
/* |
/* |
* This routine saves the current game for use at a later date |
* This routine saves the current game for use at a later date |
*/ |
*/ |
save() { |
void |
|
save() |
|
{ |
|
|
reg char *sp; |
char *sp; |
reg int outf, num; |
int outf, num; |
time_t t; |
time_t t; |
int *dat_end; |
|
struct stat sb; |
struct stat sb; |
unsgn start, end; |
char *start, *end; |
|
|
printf("Which file do you wish to save it in? "); |
printf("Which file do you wish to save it in? "); |
sp = buf; |
sp = buf; |
|
|
*/ |
*/ |
|
|
if (stat(buf, &sb) > -1 |
if (stat(buf, &sb) > -1 |
&& getyn("File exists. Do you wish to overwrite? ", yn_only) > 0) |
&& getyn("File exists. Do you wish to overwrite? ") > 0) |
return; |
return; |
|
|
if ((outf=creat(buf, 0644)) < 0) { |
if ((outf=creat(buf, 0644)) < 0) { |
|
|
for (sp = buf; *sp != '\n'; sp++) |
for (sp = buf; *sp != '\n'; sp++) |
continue; |
continue; |
*sp = '\0'; |
*sp = '\0'; |
# if 0 |
|
start = (((int) etext + (SEGSIZE-1)) / SEGSIZE ) * SEGSIZE; |
|
# else |
|
start = 0; |
start = 0; |
# endif |
|
end = sbrk(0); |
end = sbrk(0); |
while (start < end) { /* write out entire data space */ |
while (start < end) { /* write out entire data space */ |
num = start + 16 * 1024 > end ? end - start : 16 * 1024; |
num = start + 16 * 1024 > end ? end - start : 16 * 1024; |
|
|
/* |
/* |
* This routine restores an old game from a file |
* This routine restores an old game from a file |
*/ |
*/ |
restore() { |
void |
|
restore() |
|
{ |
|
|
reg char *sp; |
char *sp; |
|
|
printf("Which file do you wish to restore from? "); |
printf("Which file do you wish to restore from? "); |
for (sp = buf; (*sp=getchar()) != '\n'; sp++) |
for (sp = buf; (*sp=getchar()) != '\n'; sp++) |
|
|
* This does the actual restoring. It returns TRUE if the |
* This does the actual restoring. It returns TRUE if the |
* backup was successful, else false. |
* backup was successful, else false. |
*/ |
*/ |
|
int |
rest_f(file) |
rest_f(file) |
reg char *file; { |
char *file; |
|
{ |
|
|
reg char *sp; |
char *sp; |
reg int inf, num; |
int inf, num; |
char buf[80]; |
char buf[80]; |
unsgn start, end; |
char *start, *end; |
STAT sbuf; |
STAT sbuf; |
|
|
if ((inf=open(file, 0)) < 0) { |
if ((inf=open(file, 0)) < 0) { |
Line 247 reg char *file; { |
|
Line 258 reg char *file; { |
|
perror(file); |
perror(file); |
exit(1); |
exit(1); |
} |
} |
# if 0 |
|
start = (((int) etext + (SEGSIZE-1)) / SEGSIZE ) * SEGSIZE; |
|
# else |
|
start = 0; |
start = 0; |
# endif |
|
brk(end = start + sbuf.st_size); |
brk(end = start + sbuf.st_size); |
while (start < end) { /* write out entire data space */ |
while (start < end) { /* write out entire data space */ |
num = start + 16 * 1024 > end ? end - start : 16 * 1024; |
num = start + 16 * 1024 > end ? end - start : 16 * 1024; |