public class Trade { static String[] list = new String[Monop.MAX_PRP() + 2]; static int[] used = new int[Monop.MAX_PRP() ]; static Trd_st[] trades = new Trd_st[2]; static { for (int i = 0;i < 2;i++) { trades[i] = new Trd_st(); } for (int i = 0;i < Monop.MAX_PRP() + 2;i++) { list[i] = new String(); } } public static void trade() { int tradee = 0; int i = 0; Monop.trading = true; for (i = 0;i < 2;i++) { trades[i].cash = 0; trades[i].gojf = 0; trades[i].prop_list = null; } while (true) { if (Monop.num_play == 1) { System.out.println("There ain't no-one around to trade WITH!!"); return; } if (Monop.num_play > 2) { tradee = GetInput.getinp("Which player do you wish to trade with? ", Monop.name_list); if (tradee == Monop.num_play) { return; } if (tradee == Monop.player) { System.out.println("You can't trade with yourself!"); continue; } } else { tradee = 1 - Monop.player; } break; } get_list(0, Monop.player); get_list(1, tradee); if (Misc.getyn("Do you wish a summary? ") == 0) { summate(); } if (Misc.getyn("Is the trade ok? ") == 0) { do_trade(); } } static void get_list(int struct_no, int play_no) { int sn = 0; int pn = 0; Plr_st pp = null; int numin = 0; int prop = 0; int num_prp = 0; Own_st op = null; Trd_st tp = null; for (numin = 0;numin < Monop.MAX_PRP();numin++) { used[numin] = 0; } sn = struct_no; pn = play_no; pp = Monop.play[pn]; tp = trades[sn]; tp.trader = pn; System.out.println("player " + pp.name + " (" + (pn + 1) + "):"); if (pp.own_list != null) { numin = set_list(pp.own_list); for (num_prp = numin;num_prp != 0;) { prop = GetInput.getinp("Which property do you wish to trade? ", list); if (prop == numin) { break; } else if (used[prop] != 0) { System.out.println("You've already allocated that."); } else { num_prp--; used[prop] = 1; for (op = pp.own_list;prop-- != 0;op = op.next) { continue; } PropertyFunctions.add_list(pn, tp.prop_list, Monop.sqnum(op.sqr)); } } } if (pp.money > 0) { System.out.print("You have $" + pp.money + " "); tp.cash = Misc.get_int("How much are you trading? "); } if (pp.num_gojf > 0) { while (true) { System.out.print("You have " + pp.num_gojf + " get-out-of-jail-free cards. "); tp.gojf = Misc.get_int("How many are you trading? "); if (tp.gojf > pp.num_gojf) { System.out.println("You don't have that many. Try again."); continue; } break; } } } static int set_list(Own_st the_list) { int i = 0; Own_st op = null; i = 0; for (op = the_list;op != null;op = op.next) { if ( ! (used[i] != 0)) { list[i++] = op.sqr.name; } } list[i++] = "done"; list[i--] = null; return i; } static void summate() { boolean some = false; int i = 0; Trd_st tp = null; Own_st op = null; for (i = 0;i < 2;i++) { tp = trades[i]; some = false; System.out.println("Player " + (Monop.play[tp.trader].name) + " (" + (tp.trader + 1) + ") gives:"); if (tp.cash > 0) { System.out.println("\t$" + tp.cash); some = true; } if (tp.gojf > 0) { System.out.println("\t" + tp.gojf + " get-out-of-jail-free card(s)"); some = true; } if (tp.prop_list != null) { for (op = tp.prop_list;op != null;op = op.next) { System.out.print('\t'); Print.printsq(Monop.sqnum(op.sqr) , true); } some = true; } if ( ! some) { System.out.println("\t-- Nothing --"); } } } static void do_trade() { move_em(trades[0], trades[1]); move_em(trades[1], trades[0]); } static void move_em(Trd_st from, Trd_st to) { Plr_st pl_fr = null; Plr_st pl_to = null; Own_st op = null; pl_fr = Monop.play[from.trader]; pl_to = Monop.play[to.trader]; pl_fr.money -= from.cash; pl_to.money += from.cash; pl_fr.num_gojf -= from.gojf; pl_to.num_gojf += from.gojf; for (op = from.prop_list;op != null;op = op.next) { PropertyFunctions.add_list(to.trader, pl_to.own_list, Monop.sqnum(op.sqr)); op.sqr.owner = to.trader; PropertyFunctions.del_list(from.trader, pl_fr.own_list, Monop.sqnum(op.sqr)); } Misc.set_ownlist(to.trader); } public static void resign() { int i = 0; int new_own = 0; Own_st op = null; Sqr_st sqp = null; if (Monop.cur_p.money <= 0) { switch (Monop.board[Monop.cur_p.loc].type) { case Monop.UTIL: case Monop.RR: case Monop.PRPTY: new_own = Monop.board[Monop.cur_p.loc].owner; break; default : new_own = Monop.num_play; break; } if (new_own == Monop.num_play) { System.out.println("You would resign to the bank"); } else { System.out.println("You would resign to " + (Monop.name_list[new_own])); } } else if (Monop.num_play == 1) { new_own = Monop.num_play; System.out.println("You would resign to the bank"); } else { Monop.name_list[Monop.num_play] = "bank"; do { new_own = GetInput.getinp("Who do you wish to resign to? ", Monop.name_list); if (new_own == Monop.player) { System.out.println("You can't resign to yourself!!"); } } while (new_own == Monop.player); Monop.name_list[Monop.num_play] = "done"; } if (Misc.getyn("Do you really want to resign? ") != 0) { return; } if (Monop.num_play == 1) { System.out.println("Then NOBODY wins (not even YOU!)"); System.exit(0); } if (new_own < Monop.num_play) { System.out.println("resigning to player"); trades[0].trader = new_own; trades[0].gojf = 0; trades[0].cash = trades[0].gojf; trades[0].prop_list = null; trades[1].trader = Monop.player; trades[1].cash = Math.max(Monop.cur_p.money, 0); trades[1].gojf = Monop.cur_p.num_gojf; trades[1].prop_list = Monop.cur_p.own_list; do_trade(); } else { System.out.println("resigning to bank"); for (op = Monop.cur_p.own_list;op != null;op = op.next) { sqp = op.sqr; sqp.owner = - 1; sqp.desc.morg = false; if ((int) sqp.type == Monop.PRPTY) { Misc.isnot_monop(sqp.desc.mon_desc); sqp.desc.houses = 0; } } if (Monop.cur_p.num_gojf != 0) { Jail.ret_card(Monop.cur_p); } } for (i = Monop.player;i < Monop.num_play;i++) { Monop.name_list[i] = Monop.name_list[i + 1]; if (i + 1 < Monop.num_play) { Monop.play[i] = Monop.play[i + 1]; } } Monop.name_list[Monop.num_play--] = null; for (i = 0;i < Monop.N_SQRS;i++) { if (Monop.board[i].owner > Monop.player) { --Monop.board[i].owner; } } Monop.player =--Monop.player < 0 ? Monop.num_play - 1:Monop.player; Misc.next_play(); if (Monop.num_play < 2) { System.out.println("\nThen " + (Monop.play[0].name) + " WINS!!!!!"); Print.printhold(0); System.out.println("That's a grand worth of $" + (Monop.play[0].money + PropertyFunctions.prop_worth(Monop.play[0]))); System.exit(0); } } }