import java.util.*; import java.io.IOException; public class Monop { public final static int JAIL = 40; public final static int IN_JAIL = 9; public final static int LUX_TAX = 8; public final static int GOTO_J = 7; public final static int INC_TAX = 6; public final static int CHANCE = 5; public final static int CC = 4; public final static int SAFE = 3; public final static int UTIL = 2; public final static int RR = 1; public final static int PRPTY = 0; public final static int N_UTIL = 2; public final static int N_RR = 4; public final static int N_PROP = 22; public final static int MAX_PL = 9; public final static int N_SQRS = 40; public final static int N_MON = 8; static boolean fixing; static boolean trading; static boolean told_em; static boolean spec; static String[] name_list = new String[MAX_PL + 2]; static String[] comlist = { "quit", "print", "where", "own holdings", "holdings", "mortgage", "unmortgage", "buy houses", "sell houses", "card", "pay", "trade", "resign", "save", "restore", "roll", "", null}; static String[] yn = { "yes", "no", "quit", "print", "where", "own holdings", "holdings", null}; static String[] lucky_mes = { "You lucky stiff", "You got lucky", "What a lucky person!", "You must have a 4-leaf clover", "My, my! Aren't we lucky!", "Luck smiles upon you", "You got lucky this time", "Lucky person!", "Your karma must certainly be together", "How beautifully Cosmic", "Wow, you must be really with it"}; static int player; static int num_play; static int num_doub; static int num_luck = lucky_mes.length; static String[] func = { "Misc.quit", "Print.printboard", "Print.where", "Misc.list", "Misc.list_all", "Mortgage.mortgage", "Mortgage.unmortgage", "Houses.buy_houses", "Houses.sell_houses", "Jail.card", "Jail.pay", "Trade.trade", "Trade.resign", "Execute.save", "Execute.restore", "Execute.do_move", "Execute.do_move"}; static Dk_st[] deck = new Dk_st[2]; static Plr_st[] play; static Plr_st cur_p; static Prp_st[] rr = new Prp_st[N_RR]; static Prp_st[] util = new Prp_st[2]; static Mon_st[] mon = { new Mon_st(null, - 1, (char) 2, (char) 0, 1, "Purple", "PURPLE", new int[]{1, 3}) , new Mon_st(null, - 1, (char) 3, (char) 0, 1, "Lt. Blue", "LT. BLUE", new int[]{6, 8, 9}) , new Mon_st(null, - 1, (char) 3, (char) 0, 2, "Violet", "VIOLET", new int[]{11, 13, 14}) , new Mon_st(null, - 1, (char) 3, (char) 0, 2, "Orange", "ORANGE", new int[]{16, 18, 19}) , new Mon_st(null, - 1, (char) 3, (char) 0, 3, "Red", "RED", new int[]{21, 23, 24}) , new Mon_st(null, - 1, (char) 3, (char) 0, 3, "Yellow", "YELLOW", new int[]{26, 27, 29}) , new Mon_st(null, - 1, (char) 3, (char) 0, 4, "Green", "GREEN", new int[]{31, 32, 34}) , new Mon_st(null, - 1, (char) 2, (char) 0, 4, "Dk. Blue", "DK. BLUE", new int[]{37, 39}) }; static Prp_st[] prop = { new Prp_st(false, false, (char) 1, 0, mon[0], new int[]{2, 10, 30, 90, 160, 250}) , new Prp_st(false, false, (char) 3, 0, mon[0], new int[]{4, 20, 60, 180, 320, 450}) , new Prp_st(false, false, (char) 6, 0, mon[1], new int[]{6, 30, 90, 270, 400, 550}) , new Prp_st(false, false, (char) 7, 0, mon[1], new int[]{6, 30, 90, 270, 400, 550}) , new Prp_st(false, false, (char) 9, 0, mon[1], new int[]{8, 40, 100, 300, 450, 600}) , new Prp_st(false, false, (char) 11, 0, mon[2], new int[]{10, 50, 150, 450, 625, 750}) , new Prp_st(false, false, (char) 13, 0, mon[2], new int[]{10, 50, 150, 450, 625, 750}) , new Prp_st(false, false, (char) 14, 0, mon[2], new int[]{12, 60, 180, 500, 700, 900}) , new Prp_st(false, false, (char) 16, 0, mon[3], new int[]{14, 70, 200, 550, 750, 950}) , new Prp_st(false, false, (char) 17, 0, mon[3], new int[]{14, 70, 200, 550, 750, 950}) , new Prp_st(false, false, (char) 19, 0, mon[3], new int[]{16, 80, 220, 600, 800, 1000}) , new Prp_st(false, false, (char) 21, 0, mon[4], new int[]{18, 90, 250, 700, 875, 1050}) , new Prp_st(false, false, (char) 23, 0, mon[4], new int[]{18, 90, 250, 700, 875, 1050}) , new Prp_st(false, false, (char) 24, 0, mon[4], new int[]{20, 100, 300, 750, 925, 1100}) , new Prp_st(false, false, (char) 26, 0, mon[5], new int[]{22, 110, 330, 800, 975, 1150}) , new Prp_st(false, false, (char) 27, 0, mon[5], new int[]{22, 110, 330, 800, 975, 1150}) , new Prp_st(false, false, (char) 29, 0, mon[5], new int[]{24, 120, 360, 850, 1025, 1200}) , new Prp_st(false, false, (char) 31, 0, mon[6], new int[]{26, 130, 390, 900, 1100, 1275}) , new Prp_st(false, false, (char) 32, 0, mon[6], new int[]{26, 130, 390, 900, 1100, 1275}) , new Prp_st(false, false, (char) 34, 0, mon[6], new int[]{28, 150, 450, 1000, 1200, 1400}) , new Prp_st(false, false, (char) 37, 0, mon[7], new int[]{35, 175, 500, 1100, 1300, 1500}) , new Prp_st(false, false, (char) 39, 0, mon[7], new int[]{50, 200, 600, 1400, 1700, 2000}) }; static Sqr_st[] board = { new Sqr_st("=== GO ===", - 1, (char) SAFE, null) , new Sqr_st("Mediterranean ave. (P)", - 1, (char) PRPTY, prop[0], 60) , new Sqr_st("Community Chest i", - 1, (char) CC) , new Sqr_st("Baltic ave. (P)", - 1, (char) PRPTY, prop[1], 60) , new Sqr_st("Income Tax", - 1, (char) INC_TAX) , new Sqr_st("Reading RR", - 1, (char) RR, rr[0], 200) , new Sqr_st("Oriental ave. (L)", - 1, (char) PRPTY, prop[2], 100) , new Sqr_st("Chance i", - 1, (char) CHANCE) , new Sqr_st("Vermont ave. (L)", - 1, (char) PRPTY, prop[3], 100) , new Sqr_st("Connecticut ave. (L)", - 1, (char) PRPTY, prop[4], 120) , new Sqr_st("Just Visiting", - 1, (char) SAFE, null) , new Sqr_st("St. Charles pl. (V)", - 1, (char) PRPTY, prop[5], 140) , new Sqr_st("Electric Co.", - 1, (char) UTIL, util[0], 150) , new Sqr_st("States ave. (V)", - 1, (char) PRPTY, prop[6], 140) , new Sqr_st("Virginia ave. (V)", - 1, (char) PRPTY, prop[7], 160) , new Sqr_st("Pennsylvania RR", - 1, (char) RR, rr[1], 200) , new Sqr_st("St. James pl. (O)", - 1, (char) PRPTY, prop[8], 180) , new Sqr_st("Community Chest ii", - 1, (char) CC) , new Sqr_st("Tennessee ave. (O)", - 1, (char) PRPTY, prop[9], 180) , new Sqr_st("New York ave. (O)", - 1, (char) PRPTY, prop[10], 200) , new Sqr_st("Free Parking", - 1, (char) SAFE, null) , new Sqr_st("Kentucky ave. (R)", - 1, (char) PRPTY, prop[11], 220) , new Sqr_st("Chance ii", - 1, (char) CHANCE) , new Sqr_st("Indiana ave. (R)", - 1, (char) PRPTY, prop[12], 220) , new Sqr_st("Illinois ave. (R)", - 1, (char) PRPTY, prop[13], 240) , new Sqr_st("B&O RR", - 1, (char) RR, rr[2], 200) , new Sqr_st("Atlantic ave. (Y)", - 1, (char) PRPTY, prop[14], 260) , new Sqr_st("Ventnor ave. (Y)", - 1, (char) PRPTY, prop[15], 260) , new Sqr_st("Water Works", - 1, (char) UTIL, util[1], 150) , new Sqr_st("Marvin Gardens (Y)", - 1, (char) PRPTY, prop[16], 280) , new Sqr_st("GO TO JAIL", - 1, (char) GOTO_J) , new Sqr_st("Pacific ave. (G)", - 1, (char) PRPTY, prop[17], 300) , new Sqr_st("N. Carolina ave. (G)", - 1, (char) PRPTY, prop[18], 300) , new Sqr_st("Community Chest iii", - 1, (char) CC) , new Sqr_st("Pennsylvania ave. (G)", - 1, (char) PRPTY, prop[19], 320) , new Sqr_st("Short Line RR", - 1, (char) RR, rr[3], 200) , new Sqr_st("Chance iii", - 1, (char) CHANCE) , new Sqr_st("Park place (D)", - 1, (char) PRPTY, prop[20], 350) , new Sqr_st("Luxury Tax", - 1, (char) LUX_TAX) , new Sqr_st("Boardwalk (D)", - 1, (char) PRPTY, prop[21], 400) , new Sqr_st("JAIL", - 1, (char) IN_JAIL) }; static { for (int i = 0;i < 2;i++) { util[i] = new Prp_st(); } for (int i = 0;i < N_RR;i++) { rr[i] = new Prp_st(); } for (int i = 0;i < 2;i++) { deck[i] = new Dk_st(); } for (int i = 0;i < MAX_PL + 2;i++) { name_list[i] = new String(); } } public static int sqnum(Object sqp) { List tmpList = Arrays.asList(board); return tmpList.indexOf(sqp); } public static int printline() { System.out.println("------------------------------"); return 0; } public static int lucky(String str) { System.out.println(str + (lucky_mes[Roll.roll(1, num_luck) - 1])); return 0; } public static int MAX_PRP() { return N_PROP + N_RR + N_UTIL; } public static void main(String[] args) { String[] argv = new String[args.length + 1]; argv[0] = "Monop"; for (int i = 1;i < args.length;i++) { argv[i] = args[i - 1]; } Monop instance = new Monop(); System.exit(instance.main(argv.length, argv)); } int main(int ac, String[] av) { if (ac > 1) { if ( ! Execute.rest_f(av[1])) { Execute.restore(); } } else { getplayers(); init_players(); init_monops(); } num_luck = lucky_mes.length; CardReader.init_decks(); while (true) { System.out.println("\n" + cur_p.name + " (" + (player + 1) + ") (cash $" + cur_p.money + ") on " + (board[cur_p.loc].name)); Jail.printturn(); Mortgage.force_morg(); Execute.execute(GetInput.getinp("-- Command: ", comlist)); } } void getplayers() { while ( ! getplayers2()); } boolean getplayers2() { String sp = null; int i = 0; int j = 0; String buf = new String(); while (true) { num_play = Misc.get_int("How many players? "); if (num_play <= 0 || num_play > MAX_PL) { System.out.println("Sorry. Number must range from 1 to 9"); } else { break; } } play = new Plr_st[num_play]; for (int tmpi = 0;tmpi < num_play;tmpi++) { play[tmpi] = new Plr_st(); } cur_p = play[0]; for (i = 0;i < num_play;i++) { System.out.print("Player " + (i + 1) + "'s name: "); try { buf = CIOUtils.stdin.readLine(); } catch (IOException e) { System.err.println("IO Exception:" + e); } if (buf.length() == 0) { i--; continue; } sp = ""; play[i].name = buf; name_list[i] = play[i].name; play[i].money = 1500; } name_list[i++] = "done"; name_list[i] = null; for (i = 0;i < num_play;i++) { for (j = i + 1;j < num_play;j++) { if (name_list[i].equalsIgnoreCase(name_list[j])) { if (i != num_play - 1) { System.out.println("Hey!!! Some of those are IDENTICAL!! Let's try that again...."); } else { System.out.println("\"done\" is a reserved word. Please try again"); } for (i = 0;i < num_play;i++) { } return false; } } } return true; } void init_players() { int i = 0; int rl = 0; int cur_max = 0; boolean over = false; int max_pl = 0; do { System.out.println(); i = 0; for (cur_max = i;i < num_play;i++) { System.out.println((play[i].name) + " (" + (i + 1) + ") rolls " + (rl = Roll.roll(2, 6))); if (rl > cur_max) { over = false; cur_max = rl; max_pl = i; } else if (rl == cur_max) { over = true; } } if (over) { System.out.println(over + " people rolled the same thing, so we'll try again"); continue; } } while (false); player = max_pl; cur_p = play[max_pl]; System.out.println(cur_p.name + " (" + (max_pl + 1) + ") goes first"); } void init_monops() { Mon_st mp = null; int i = 0; for (int count = 0;count < N_MON;count++) { mp = mon[count]; mp.name = mp.not_m; for (i = 0;i < mp.num_in;i++) { mp.sq[i] = board[mp.sqnums[i]]; } } } }