public class Houses { static String[] names = new String[Monop.N_MON + 2]; static String cur_prop = new String(); static Mon_st[] monops = new Mon_st[Monop.N_MON]; static { for (int i = 0;i < Monop.N_MON;i++) { monops[i] = new Mon_st(); } for (int i = 0;i < Monop.N_MON + 2;i++) { names[i] = new String(); } } public static void buy_houses() { int num_mon = 0; Mon_st mp = null; Own_st op = null; boolean good = false; boolean got_morg = false; int i = 0; int p = 0; do { num_mon = 0; good = true; got_morg = false; for (op = Monop.cur_p.own_list;op != null && (int) op.sqr.type != Monop.PRPTY;op = op.next) { continue; } while (op != null) { if (op.sqr.desc.monop) { mp = op.sqr.desc.mon_desc; monops[num_mon] = mp; names[num_mon] = monops[num_mon].name; num_mon++; good = false; got_morg = good; for (i = 0;i < mp.num_in;i++) { if (op.sqr.desc.morg) { got_morg = true; } if (op.sqr.desc.houses != 5) { good = true; } op = op.next; } if ( ! good || got_morg) { --num_mon; } } else { op = op.next; } } if (num_mon == 0) { if (got_morg) { System.out.println("You can't build on mortgaged monopolies."); } else if ( ! good) { System.out.println("You can't build any more."); } else { System.out.println("But you don't have any monopolies!!"); } return; } if (num_mon == 1) { buy_h(monops[0]); } else { names[num_mon++] = "done"; names[num_mon--] = null; p = GetInput.getinp("Which property do you wish to buy houses for? ", names); if (p == num_mon) { return; } buy_h(monops[p]); continue; } } while (false); } static void buy_h(Mon_st mnp) { int i = 0; Mon_st mp = null; int price = 0; int[] input = new int[3]; int[] inputIndex = input; int[] temp = new int[3]; int[] tempIndex = temp; int tot = 0; Prp_st pp = null; mp = mnp; price = mp.h_cost * 50; do { list_cur(mp); System.out.println("Houses will cost $" + price); System.out.println("How many houses do you wish to buy for"); for (i = 0;i < mp.num_in;i++) { pp = mp.sq[i].desc; if (pp.houses == 5) { System.out.println((mp.sq[i].name) + " (H):"); inputIndex[i] = 0; tempIndex[i] = 5; continue; } cur_prop = (mp.sq[i].name) + " (" + pp.houses + "): "; inputIndex[i] = Misc.get_int(cur_prop); tempIndex[i] = inputIndex[i] + pp.houses; if (tempIndex[i] > 5) { System.out.println("That's too many. The most you can buy is " + (5 - pp.houses)); continue; } } if (mp.num_in == 3 && (Math.abs(tempIndex[0] - tempIndex[1]) > 1 || Math.abs(tempIndex[0] - tempIndex[2]) > 1 || Math.abs(tempIndex[1] - tempIndex[2]) > 1)) { System.out.println("That makes the spread too wide. Try again"); continue; } else if (mp.num_in == 2 && Math.abs(tempIndex[0] - tempIndex[1]) > 1) { System.out.println("That makes the spread too wide. Try again"); continue; } } while (false); i = 0; for (tot = i;i < mp.num_in;i++) { tot += inputIndex[i]; } if (tot != 0) { System.out.println("You asked for " + tot + " houses for $" + (tot * price)); if (Misc.getyn("Is that ok? ") == 0) { Monop.cur_p.money -= tot * price; i = 0; for (tot = i;i < mp.num_in;i++) { mp.sq[i].desc.houses = tempIndex[i]; } } } } public static void sell_houses() { int num_mon = 0; Mon_st mp = null; Own_st op = null; boolean good = false; int p = 0; do { num_mon = 0; good = true; for (op = Monop.cur_p.own_list;op != null;op = op.next) { if (op.sqr.type == Monop.PRPTY && op.sqr.desc.monop) { mp = op.sqr.desc.mon_desc; monops[num_mon] = mp; names[num_mon] = monops[num_mon].name; num_mon++; good = false; do { if ( ! good && op.sqr.desc.houses != 0) { good = true; } } while (op.next != null && op.sqr.desc.mon_desc == mp && (op = op.next) != null); if ( ! good) { --num_mon; } } } if (num_mon == 0) { System.out.println("You don't have any houses to sell!!"); return; } if (num_mon == 1) { sell_h(monops[0]); } else { names[num_mon++] = "done"; names[num_mon--] = null; p = GetInput.getinp("Which property do you wish to sell houses from? ", names); if (p == num_mon) { return; } sell_h(monops[p]); Misc.notify1(); continue; } } while (false); } static void sell_h(Mon_st mnp) { int i = 0; Mon_st mp = null; int price = 0; int[] input = new int[3]; int[] inputIndex = input; int[] temp = new int[3]; int[] tempIndex = temp; int tot = 0; Prp_st pp = null; mp = mnp; price = mp.h_cost * 25; do { System.out.println("Houses will get you $" + price + " apiece"); list_cur(mp); System.out.println("How many houses do you wish to sell from"); for (i = 0;i < mp.num_in;i++) { pp = mp.sq[i].desc; if (pp.houses == 0) { System.out.println((mp.sq[i].name) + " (0):"); tempIndex[i] = 0; inputIndex[i] = tempIndex[i]; continue; } if (pp.houses < 5) { cur_prop = (mp.sq[i].name) + " (" + pp.houses + "): "; } else { cur_prop = (mp.sq[i].name) + " (H): "; } inputIndex[i] = Misc.get_int(cur_prop); tempIndex[i] = pp.houses - inputIndex[i]; if (tempIndex[i] < 0) { System.out.println("That's too many. The most you can sell is " + pp.houses); continue; } } if (mp.num_in == 3 && (Math.abs(tempIndex[0] - tempIndex[1]) > 1 || Math.abs(tempIndex[0] - tempIndex[2]) > 1 || Math.abs(tempIndex[1] - tempIndex[2]) > 1)) { System.out.println("That makes the spread too wide. Try again"); continue; } else if (mp.num_in == 2 && Math.abs(tempIndex[0] - tempIndex[1]) > 1) { System.out.println("That makes the spread too wide. Try again"); continue; } } while (false); i = 0; for (tot = i;i < mp.num_in;i++) { tot += inputIndex[i]; } if (tot != 0) { System.out.println("You asked to sell " + tot + " houses for $" + (tot * price)); if (Misc.getyn("Is that ok? ") == 0) { Monop.cur_p.money += tot * price; i = 0; for (tot = i;i < mp.num_in;i++) { mp.sq[i].desc.houses = tempIndex[i]; } } } } static void list_cur(Mon_st mp) { int i = 0; Sqr_st sqp = null; for (i = 0;i < mp.num_in;i++) { sqp = mp.sq[i]; if (sqp.desc.houses == 5) { System.out.print(sqp.name + " (H) "); } else { System.out.print(sqp.name + " (" + sqp.desc.houses + ") "); } } System.out.println(); } }