|
|
1.1 ! root 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'; sp++) ! 54: continue; ! 55: if (sp == buf) ! 56: goto over; ! 57: *sp++ = '\0'; ! 58: strcpy(name_list[i]=play[i].name=(char *)calloc(1,sp-buf),buf); ! 59: play[i].money = 1500; ! 60: } ! 61: name_list[i++] = "done"; ! 62: name_list[i] = 0; ! 63: for (i = 0; i < num_play; i++) ! 64: for (j = i + 1; j < num_play; j++) ! 65: if (strcmp(name_list[i], name_list[j]) == 0) { ! 66: if (i != num_play - 1) ! 67: printf("Hey!!! Some of those are IDENTICAL!! Let's try that again....\n"); ! 68: else ! 69: printf("\"done\" is a reserved word. Please try again\n"); ! 70: for (i = 0; i < num_play; i++) ! 71: cfree(play[i].name); ! 72: cfree(play); ! 73: goto blew_it; ! 74: } ! 75: } ! 76: /* ! 77: * This routine figures out who goes first ! 78: */ ! 79: init_players() { ! 80: ! 81: reg int i, rl, cur_max; ! 82: bool over; ! 83: int max_pl; ! 84: ! 85: again: ! 86: putchar('\n'); ! 87: for (cur_max = i = 0; i < num_play; i++) { ! 88: printf("%s (%d) rolls %d\n", play[i].name, i+1, rl=roll(2, 6)); ! 89: if (rl > cur_max) { ! 90: over = FALSE; ! 91: cur_max = rl; ! 92: max_pl = i; ! 93: } ! 94: else if (rl == cur_max) ! 95: over++; ! 96: } ! 97: if (over) { ! 98: printf("%d people rolled the same thing, so we'll try again\n", ! 99: over + 1); ! 100: goto again; ! 101: } ! 102: player = max_pl; ! 103: cur_p = &play[max_pl]; ! 104: printf("%s (%d) goes first\n", cur_p->name, max_pl + 1); ! 105: } ! 106: /* ! 107: * This routine initalizes the monopoly structures. ! 108: */ ! 109: init_monops() { ! 110: ! 111: reg MON *mp; ! 112: reg int i; ! 113: ! 114: for (mp = mon; mp < &mon[N_MON]; mp++) { ! 115: mp->name = mp->not_m; ! 116: for (i = 0; i < mp->num_in; i++) ! 117: mp->sq[i] = &board[(int)(mp->sq[i])]; ! 118: } ! 119: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.