1: # include   "monop.ext"
   2: # include   <sys/types.h>
   3: # include   <sys/stat.h>
   4: # include   <sys/time.h>
   5: 
   6: # define    SEGSIZE 8192
   7: 
   8: typedef struct stat STAT;
   9: typedef struct tm   TIME;
  10: 
  11: extern char etext[],    /* end of text space			*/
  12:         rub();
  13: 
  14: static char buf[257],
  15:         *yn_only[]  = { "yes", "no"};
  16: 
  17: static bool new_play;   /* set if move on to new player		*/
  18: 
  19: /*
  20:  *	This routine executes the given command by index number
  21:  */
  22: execute(com_num)
  23: reg int com_num; {
  24: 
  25:     new_play = FALSE;   /* new_play is true if fixing	*/
  26:     (*func[com_num])();
  27:     notify();
  28:     force_morg();
  29:     if (new_play)
  30:         next_play();
  31:     else if (num_doub)
  32:         printf("%s rolled doubles.  Goes again\n", cur_p->name);
  33: }
  34: /*
  35:  *	This routine moves a piece around.
  36:  */
  37: do_move() {
  38: 
  39:     reg int     r1, r2;
  40:     reg bool    was_jail;
  41: 
  42:     new_play = was_jail = FALSE;
  43:     printf("roll is %d, %d\n", r1=roll(1, 6), r2=roll(1, 6));
  44:     if (cur_p->loc == JAIL) {
  45:         was_jail++;
  46:         if (!move_jail(r1, r2)) {
  47:             new_play++;
  48:             goto ret;
  49:         }
  50:     }
  51:     else {
  52:         if (r1 == r2 && ++num_doub == 3) {
  53:             printf("That's 3 doubles.  You go to jail\n");
  54:             goto_jail();
  55:             new_play++;
  56:             goto ret;
  57:         }
  58:         move(r1+r2);
  59:     }
  60:     if (r1 != r2 || was_jail)
  61:         new_play++;
  62: ret:
  63:     return;
  64: }
  65: /*
  66:  *	This routine moves a normal move
  67:  */
  68: move(rl)
  69: reg int rl; {
  70: 
  71:     reg int old_loc;
  72: 
  73:     old_loc = cur_p->loc;
  74:     cur_p->loc = (cur_p->loc + rl) % N_SQRS;
  75:     if (cur_p->loc < old_loc && rl > 0) {
  76:         cur_p->money += 200;
  77:         printf("You pass %s and get $200\n", board[0].name);
  78:     }
  79:     show_move();
  80: }
  81: /*
  82:  *	This routine shows the results of a move
  83:  */
  84: show_move() {
  85: 
  86:     reg SQUARE  *sqp;
  87: 
  88:     sqp = &board[cur_p->loc];
  89:     printf("That puts you on %s\n", sqp->name);
  90:     switch (sqp->type) {
  91:       case SAFE:
  92:         printf("That is a safe place\n");
  93:         break;
  94:       case CC:
  95:       case CHANCE:
  96:       case SPEC:
  97:         (*((int (*)())(sqp->desc)))();
  98:         break;
  99:       case PRPTY:
 100:       case RR:
 101:       case UTIL:
 102:         if (sqp->owner < 0) {
 103:             printf("That would cost $%d\n", sqp->cost);
 104:             if (getyn("Do you want to buy? ") == 0) {
 105:                 buy(player, sqp);
 106:                 cur_p->money -= sqp->cost;
 107:             }
 108:             else if (num_play > 2)
 109:                 bid(sqp);
 110:         }
 111:         else if (sqp->owner == player)
 112:             printf("You own it.\n");
 113:         else
 114:             rent(sqp);
 115:     }
 116: }
 117: /*
 118:  *	This routine saves the current game for use at a later date
 119:  */
 120: save() {
 121: 
 122:     reg char    *sp;
 123:     reg int     outf, num;
 124:     TIME        tme, *tp;
 125:     int     *dat_end, junk[18];
 126:     unsgn       start, end;
 127: 
 128:     tp = &tme;
 129:     printf("Which file do you wish to save it in? ");
 130:     sp = buf;
 131:     while ((*sp++=getchar()) != '\n' && !feof(stdin))
 132:         continue;
 133:     *--sp = '\0';
 134:     if (feof(stdin))
 135:         clearerr(stdin);
 136: 
 137:     /*
 138: 	 * check for existing files, and confirm overwrite if needed
 139: 	 */
 140: 
 141:     if (stat(buf, junk) > -1
 142:         && getyn("File exists.  Do you wish to overwrite? ", yn_only) > 0)
 143:         return;
 144: 
 145:     if ((outf=creat(buf, 0644)) < 0) {
 146:         perror(buf);
 147:         return;
 148:     }
 149:     printf("\"%s\" ", buf);
 150:     time(tp);           /* get current time		*/
 151:     strcpy(buf, ctime(tp));
 152:     for (sp = buf; *sp != '\n'; sp++)
 153:         continue;
 154:     *sp = '\0';
 155: # if 0
 156:     start = (((int) etext + (SEGSIZE-1)) / SEGSIZE ) * SEGSIZE;
 157: # else
 158:     start = 0;
 159: # endif
 160:     end = sbrk(0);
 161:     while (start < end) {       /* write out entire data space */
 162:         num = start + 16 * 1024 > end ? end - start : 16 * 1024;
 163:         write(outf, start, num);
 164:         start += num;
 165:     }
 166:     close(outf);
 167:     printf("[%s]\n", buf);
 168: }
 169: /*
 170:  *	This routine restores an old game from a file
 171:  */
 172: restore() {
 173: 
 174:     reg char    *sp;
 175: 
 176:     printf("Which file do you wish to restore from? ");
 177:     for (sp = buf; (*sp=getchar()) != '\n' && !feof(stdin); sp++)
 178:         continue;
 179:     *sp = '\0';
 180:     if (feof(stdin))
 181:         clearerr(stdin);
 182:     rest_f(buf);
 183: }
 184: /*
 185:  *	This does the actual restoring.  It returns TRUE if the
 186:  * backup was successful, else false.
 187:  */
 188: rest_f(file)
 189: reg char    *file; {
 190: 
 191:     reg char    *sp;
 192:     reg int     inf, num;
 193:     char        buf[80];
 194:     unsgn       start, end;
 195:     STAT        sbuf;
 196: 
 197:     if ((inf=open(file, 0)) < 0) {
 198:         perror(file);
 199:         return FALSE;
 200:     }
 201:     printf("\"%s\" ", file);
 202:     if (fstat(inf, &sbuf) < 0) {        /* get file stats	*/
 203:         perror(file);
 204:         exit(1);
 205:     }
 206: # if 0
 207:     start = (((int) etext + (SEGSIZE-1)) / SEGSIZE ) * SEGSIZE;
 208: # else
 209:     start = 0;
 210: # endif
 211:     brk(end = start + sbuf.st_size);
 212:     while (start < end) {       /* write out entire data space */
 213:         num = start + 16 * 1024 > end ? end - start : 16 * 1024;
 214:         read(inf, start, num);
 215:         start += num;
 216:     }
 217:     close(inf);
 218:     strcpy(buf, ctime(sbuf.st_mtime));
 219:     for (sp = buf; *sp != '\n'; sp++)
 220:         continue;
 221:     *sp = '\0';
 222:     printf("[%s]\n", buf);
 223:     return TRUE;
 224: }

Defined functions

do_move defined in line 37; never used
execute defined in line 22; used 1 times
move defined in line 68; used 3 times
rest_f defined in line 188; used 2 times
restore defined in line 172; used 1 times
save defined in line 120; never used
show_move defined in line 84; used 1 times
  • in line 79

Defined variables

buf defined in line 14; used 14 times
yn_only defined in line 15; used 1 times

Defined typedef's

STAT defined in line 8; used 1 times
TIME defined in line 9; used 1 times

Defined macros

SEGSIZE defined in line 6; used 6 times
Last modified: 1987-08-26
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3397
Valid CSS Valid XHTML 1.0 Strict