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