1: # include   "monop.def"
   2: 
   3: /*
   4:  *	This program implements a monopoly game
   5:  */
   6: main(ac, av)
   7: reg int     ac;
   8: reg char    *av[]; {
   9: 
  10: 
  11:     srand(getpid());
  12:     if (ac > 1) {
  13:         if (!rest_f(av[1]))
  14:             restore();
  15:     }
  16:     else {
  17:         getplayers();
  18:         init_players();
  19:         init_monops();
  20:     }
  21:     num_luck = sizeof lucky_mes / sizeof (char *);
  22:     init_decks();
  23:     signal(2, quit);
  24:     for (;;) {
  25:         printf("\n%s (%d) (cash $%d) on %s\n", cur_p->name, player + 1,
  26:             cur_p->money, board[cur_p->loc].name);
  27:         printturn();
  28:         force_morg();
  29:         execute(getinp("-- Command: ", comlist));
  30:     }
  31: }
  32: /*
  33:  *	This routine gets the names of the players
  34:  */
  35: getplayers() {
  36: 
  37:     reg char    *sp;
  38:     reg int     i, j;
  39:     char        buf[257];
  40: 
  41: blew_it:
  42:     for (;;) {
  43:         if ((num_play=get_int("How many players? ")) <= 0 ||
  44:             num_play > MAX_PL)
  45:             printf("Sorry. Number must range from 1 to 9\n");
  46:         else
  47:             break;
  48:     }
  49:     cur_p = play = (PLAY *) calloc(num_play, sizeof (PLAY));
  50:     for (i = 0; i < num_play; i++) {
  51: over:
  52:         printf("Player %d's name: ", i + 1);
  53:         for (sp = buf; (*sp=getchar()) != '\n' && !feof(stdin); sp++)
  54:             continue;
  55:         if (feof(stdin))
  56:             clearerr(stdin);
  57:         if (sp == buf)
  58:             goto over;
  59:         *sp++ = '\0';
  60:         strcpy(name_list[i]=play[i].name=(char *)calloc(1,sp-buf),buf);
  61:         play[i].money = 1500;
  62:     }
  63:     name_list[i++] = "done";
  64:     name_list[i] = 0;
  65:     for (i = 0; i < num_play; i++)
  66:         for (j = i + 1; j < num_play; j++)
  67:             if (strcmp(name_list[i], name_list[j]) == 0) {
  68:                 if (i != num_play - 1)
  69:                     printf("Hey!!! Some of those are IDENTICAL!!  Let's try that again....\n");
  70:                 else
  71:                     printf("\"done\" is a reserved word.  Please try again\n");
  72:                 for (i = 0; i < num_play; i++)
  73:                     cfree(play[i].name);
  74:                 cfree(play);
  75:                 goto blew_it;
  76:             }
  77: }
  78: /*
  79:  *	This routine figures out who goes first
  80:  */
  81: init_players() {
  82: 
  83:     reg int i, rl, cur_max;
  84:     bool    over;
  85:     int max_pl;
  86: 
  87: again:
  88:     putchar('\n');
  89:     for (cur_max = i = 0; i < num_play; i++) {
  90:         printf("%s (%d) rolls %d\n", play[i].name, i+1, rl=roll(2, 6));
  91:         if (rl > cur_max) {
  92:             over = FALSE;
  93:             cur_max = rl;
  94:             max_pl = i;
  95:         }
  96:         else if (rl == cur_max)
  97:             over++;
  98:     }
  99:     if (over) {
 100:         printf("%d people rolled the same thing, so we'll try again\n",
 101:             over + 1);
 102:         goto again;
 103:     }
 104:     player = max_pl;
 105:     cur_p = &play[max_pl];
 106:     printf("%s (%d) goes first\n", cur_p->name, max_pl + 1);
 107: }
 108: /*
 109:  *	This routine initalizes the monopoly structures.
 110:  */
 111: init_monops() {
 112: 
 113:     reg MON *mp;
 114:     reg int i;
 115: 
 116:     for (mp = mon; mp < &mon[N_MON]; mp++) {
 117:         mp->name = mp->not_m;
 118:         for (i = 0; i < mp->num_in; i++)
 119:             mp->sq[i] = &board[(int)(mp->sq[i])];
 120:     }
 121: }

Defined functions

getplayers defined in line 35; used 1 times
  • in line 17
init_monops defined in line 111; used 1 times
  • in line 19
init_players defined in line 81; used 1 times
  • in line 18
main defined in line 6; never used
Last modified: 1987-08-26
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3056
Valid CSS Valid XHTML 1.0 Strict