|
|
1.1 root 1: /*
2: * Copyright (c) 1980 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
6: * provided that the above copyright notice and this paragraph are
7: * duplicated in all such forms and that any documentation,
8: * advertising materials, and other materials related to such
9: * distribution and use acknowledge that the software was developed
10: * by the University of California, Berkeley. The name of the
11: * University may not be used to endorse or promote products derived
12: * from this software without specific prior written permission.
13: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15: * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16: */
17:
18: #ifndef lint
19: char copyright[] =
20: "@(#) Copyright (c) 1980 Regents of the University of California.\n\
21: All rights reserved.\n";
22: #endif /* not lint */
23:
24: #ifndef lint
25: static char sccsid[] = "@(#)monop.c 5.6 (Berkeley) 6/18/88";
26: #endif /* not lint */
27:
28: # include "monop.def"
29:
30: /*
31: * This program implements a monopoly game
32: */
33: main(ac, av)
34: reg int ac;
35: reg char *av[]; {
36:
37:
38: srand(getpid());
39: if (ac > 1) {
40: if (!rest_f(av[1]))
41: restore();
42: }
43: else {
44: getplayers();
45: init_players();
46: init_monops();
47: }
48: num_luck = sizeof lucky_mes / sizeof (char *);
49: init_decks();
50: signal(2, quit);
51: for (;;) {
52: printf("\n%s (%d) (cash $%d) on %s\n", cur_p->name, player + 1,
53: cur_p->money, board[cur_p->loc].name);
54: printturn();
55: force_morg();
56: execute(getinp("-- Command: ", comlist));
57: }
58: }
59: /*
60: * This routine gets the names of the players
61: */
62: getplayers() {
63:
64: reg char *sp;
65: reg int i, j;
66: char buf[257];
67:
68: blew_it:
69: for (;;) {
70: if ((num_play=get_int("How many players? ")) <= 0 ||
71: num_play > MAX_PL)
72: printf("Sorry. Number must range from 1 to 9\n");
73: else
74: break;
75: }
76: cur_p = play = (PLAY *) calloc(num_play, sizeof (PLAY));
77: for (i = 0; i < num_play; i++) {
78: over:
79: printf("Player %d's name: ", i + 1);
80: for (sp = buf; (*sp=getchar()) != '\n'; sp++)
81: continue;
82: if (sp == buf)
83: goto over;
84: *sp++ = '\0';
85: strcpy(name_list[i]=play[i].name=(char *)calloc(1,sp-buf),buf);
86: play[i].money = 1500;
87: }
88: name_list[i++] = "done";
89: name_list[i] = 0;
90: for (i = 0; i < num_play; i++)
91: for (j = i + 1; j < num_play; j++)
92: if (strcasecmp(name_list[i], name_list[j]) == 0) {
93: if (i != num_play - 1)
94: printf("Hey!!! Some of those are IDENTICAL!! Let's try that again....\n");
95: else
96: printf("\"done\" is a reserved word. Please try again\n");
97: for (i = 0; i < num_play; i++)
98: cfree(play[i].name);
99: cfree(play);
100: goto blew_it;
101: }
102: }
103: /*
104: * This routine figures out who goes first
105: */
106: init_players() {
107:
108: reg int i, rl, cur_max;
109: bool over;
110: int max_pl;
111:
112: again:
113: putchar('\n');
114: for (cur_max = i = 0; i < num_play; i++) {
115: printf("%s (%d) rolls %d\n", play[i].name, i+1, rl=roll(2, 6));
116: if (rl > cur_max) {
117: over = FALSE;
118: cur_max = rl;
119: max_pl = i;
120: }
121: else if (rl == cur_max)
122: over++;
123: }
124: if (over) {
125: printf("%d people rolled the same thing, so we'll try again\n",
126: over + 1);
127: goto again;
128: }
129: player = max_pl;
130: cur_p = &play[max_pl];
131: printf("%s (%d) goes first\n", cur_p->name, max_pl + 1);
132: }
133: /*
134: * This routine initalizes the monopoly structures.
135: */
136: init_monops() {
137:
138: reg MON *mp;
139: reg int i;
140:
141: for (mp = mon; mp < &mon[N_MON]; mp++) {
142: mp->name = mp->not_m;
143: for (i = 0; i < mp->num_in; i++)
144: mp->sq[i] = &board[mp->sqnums[i]];
145: }
146: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.