public static void sellProperty(Player player) { Property[] properties; Property property; int propertyCount, response, sellValue; String message; propertyCount = displayProperties(player); if (propertyCount == 0) { System.out.println("You don't own any properties"); handlePlayerInput(player); return; } message = String.format( "Pick a number between 1 and %s " + "to sell the associated property", propertyCount); System.out.println(message); response = Util.getOptionNum(propertyCount); if (response == 0) { handlePlayerInput(player); return; } properties = new Property[] {}; properties = player.getProperties().toArray(properties); property = properties[response - 1]; sellValue = property.getSellValue(); System.out.println( "Are you sure you want to sell " + property.getName() + " for " + sellValue + " bits? Y/N"); if (Util.getResponse()) { property.sell(); System.out.println( "*" + player.getName() + " sold " + property.getName() + " for " + sellValue + " bits*"); } else { System.out.println("Transaction cancelled"); } handlePlayerInput(player); }
public static void listProperties(Player player) { Property[] properties; properties = new Property[] {}; properties = player.getProperties().toArray(properties); if (properties.length == 0) { System.out.println("You don't own any properties"); handlePlayerInput(player); return; } System.out.println("\nProperties you own:"); for (Property property : properties) { System.out.println(property); board.getPropertyCard(property.getName()).display(); } handlePlayerInput(player); }
public static void buyStable(Player player) { Property[] properties; Property property; int propertyCount, response, stablePrice; String message; propertyCount = displayProperties(player); if (propertyCount == 0) { System.out.println("You don't own any properties"); handlePlayerInput(player); return; } message = String.format( "Pick a number between 1 and %s " + "to buy stables for the associated property " + "or press Enter to cancel", propertyCount); System.out.println(message); response = Util.getOptionNum(propertyCount); if (response == 0) { handlePlayerInput(player); return; } properties = new Property[] {}; properties = player.getProperties().toArray(properties); property = properties[response - 1]; if (property.getNumStables() == Property.MAXSTABLES) { System.out.println(property.getName() + " already has the " + "maximum number of stables"); handlePlayerInput(player); return; } if (property.getType() != PropertyType.NORMAL) { System.out.println(property.getName() + " can not " + "support stables"); handlePlayerInput(player); return; } stablePrice = board.findPropertyIndex(property.getName()) / (Board.BOARDSPACES / 4) + 1; stablePrice *= 50; Property[] groupProperties; groupProperties = board.getGroupProperties(property); for (Property groupProperty : groupProperties) { if (!groupProperty.getOwner().equals(player)) { System.out.println( "You can not buy stables on this " + "property until you own every property in " + property.getGroup() + " group"); handlePlayerInput(player); return; } } if (player.getCash() < stablePrice) { System.out.println("You cannot afford to place a stable " + "on this property"); handlePlayerInput(player); return; } System.out.println( "Are you sure you want to put an additional " + "stable on " + property.getName() + " for " + stablePrice + " bits? Y/N"); if (Util.getResponse()) { property.purchase(player); System.out.println( "*" + player.getName() + " purchased an " + "additional stable on " + property.getName() + "*"); } else { System.out.println("Transaction cancelled"); } handlePlayerInput(player); }