/// <summary> /// Pays rent to the owner and takes the rent away from the current player /// </summary> /// <param name="player">the current player's turn</param> private void PayRent(Player player) { // Check if a utility, and calculates the rent if (GetType() == typeof(Utility)) { Utility currentUtility = (Utility)this; currentUtility.CalculateRent((Utility)GameLoop.getInstance().Gameboard.TileOrder[12], (Utility)GameLoop.getInstance().Gameboard.TileOrder[28], currentUtility.NearstUtility); } // Checks if a railroad, and and calculates the rent if (GetType() == typeof(Railroad)) { Railroad currentRailroad = (Railroad)this; currentRailroad.CalculateRent((Railroad)GameLoop.getInstance().Gameboard.TileOrder[5], (Railroad)GameLoop.getInstance().Gameboard.TileOrder[15], (Railroad)GameLoop.getInstance().Gameboard.TileOrder[25], (Railroad)GameLoop.getInstance().Gameboard.TileOrder[35], currentRailroad.NearestRailroad); } // Takes the money away from the current player player.Money -= Rent; // Pays rent to the owner foreach (Player plyr in GameLoop.getInstance().Gameboard.Players) { if (plyr == Owner) { plyr.Money += Rent; break; } } }
/// <summary> /// Display the pay rent form or the purchase property form /// </summary> /// <param name="player">Current player</param> /// <param name="property">Property tile that the current player landed on</param> private void DisplayPayRentOrPurchasePropertyForm(Player player, Property property) { Player propertyOwner = property.Owner; // if a property and is not owned, call the purchase property form if (propertyOwner == null) { // Figured out how to center windows with respect to their predecessors: // https://stackoverflow.com/questions/4306593/wpf-how-to-set-a-dialog-position-to-show-at-the-center-of-the-application PurchaseProperty purchaseProperty = new PurchaseProperty(); purchaseProperty.Owner = this; // Output information to the purchase property form purchaseProperty.tbOutputName.Text = player.Name; purchaseProperty.tbOutputMoney.Text = string.Format("{0:$#,##0}", player.Money); foreach (Property proprty in player.PropertiesOwned) { purchaseProperty.lbOutputPropertiesOwned.Items.Add(proprty.Name); } purchaseProperty.tbOutputCostOfProperty.Text = property.Cost.ToString("c0"); if (player.Money >= property.Cost) { purchaseProperty.tbUserInformation.Text = "Would you like to buy " + property.Name + "?"; } else { purchaseProperty.tbUserInformation.Text = "Sorry, you do not have enough money to purchase " + property.Name + "."; purchaseProperty.btnYesBuy.IsEnabled = false; } purchaseProperty.ShowDialog(); } // if the current player owns the property, do nothing else if (propertyOwner.Name == player.Name) { } // if another player owns the property, call the PayRent form else { PayRent payRent = new PayRent(); payRent.Owner = this; // Output information to pay rent form payRent.tbOutputName.Text = player.Name; payRent.tbOutputMoney.Text = string.Format("{0:$#,##0}", player.Money); payRent.tbOutputPayRentTo.Text = propertyOwner.Name; // Calculates the rent for utility or railroad property before output to the pay rent form if (GameLoop.getInstance().Gameboard.TileOrder[player.Location].GetType() == typeof(Utility)) { Utility utilityProperty = (Utility)property; utilityProperty.CalculateRent((Utility)GameLoop.getInstance().Gameboard.TileOrder[12], (Utility)GameLoop.getInstance().Gameboard.TileOrder[28], utilityProperty.NearstUtility); } else if (GameLoop.getInstance().Gameboard.TileOrder[player.Location].GetType() == typeof(Railroad)) { Railroad railroadProperty = (Railroad)property; railroadProperty.CalculateRent((Railroad)GameLoop.getInstance().Gameboard.TileOrder[5], (Railroad)GameLoop.getInstance().Gameboard.TileOrder[15], (Railroad)GameLoop.getInstance().Gameboard.TileOrder[25], (Railroad)GameLoop.getInstance().Gameboard.TileOrder[35], railroadProperty.NearestRailroad); } payRent.tbOutputRentIsHowMuch.Text = property.Rent.ToString("c0"); payRent.ShowDialog(); } }