/// <summary> /// The method used to instantiate the spots /// </summary> public void InstantiateList() { // First Row Spot temp = new Spot(0, "Go", SpotType.Go); this.Board.Add(temp); temp = new Spot(1, "Mediterranean Avenue", Color.Purple, 60, 2, 10, 30, 90, 160, 250, 30, 50, 50); this.Board.Add(temp); temp = new Spot(2, "Community Chest #1", SpotType.CommunityChest); this.Board.Add(temp); temp = new Spot(3, "Baltic Avenue", Color.Purple, 60, 4, 20, 60, 180, 320, 450, 30, 50, 50); this.Board.Add(temp); temp = new Spot(4, "Income Tax", 200); this.Board.Add(temp); temp = new Spot(5, "Reading Railroad", SpotType.Railroad, 200, 25); this.Board.Add(temp); temp = new Spot(6, "Oriental Avenue", Color.LightBlue, 100, 6, 30, 90, 270, 400, 550, 50, 50, 50); this.Board.Add(temp); temp = new Spot(7, "Chance #1", SpotType.Chance); this.Board.Add(temp); temp = new Spot(8, "Vermont Avenue", Color.LightBlue, 100, 6, 30, 90, 270, 400, 550, 50, 50, 50); this.Board.Add(temp); temp = new Spot(9, "Connecticut Avenue", Color.LightBlue, 120, 8, 40, 100, 300, 450, 600, 60, 50, 50); this.Board.Add(temp); // Second Row temp = new Spot(10, "Jail", SpotType.Jail); this.Board.Add(temp); temp = new Spot(11, "St. Charles Place", Color.MediumVioletRed, 140, 10, 50, 150, 450, 625, 750, 70, 100, 100); this.Board.Add(temp); temp = new Spot(12, "Electric Company", SpotType.Utility, 150, 75); this.Board.Add(temp); temp = new Spot(13, "States Avenue", Color.MediumVioletRed, 140, 10, 50, 150, 450, 625, 750, 70, 100, 100); this.Board.Add(temp); temp = new Spot(14, "Virginia Avenue", Color.MediumVioletRed, 160, 12, 60, 180, 500, 700, 900, 80, 100, 100); this.Board.Add(temp); temp = new Spot(15, "Pennsylvania Railroad", SpotType.Railroad, 200, 25); this.Board.Add(temp); temp = new Spot(16, "St. James Place", Color.DarkOrange, 180, 14, 70, 200, 550, 750, 950, 90, 100, 100); this.Board.Add(temp); temp = new Spot(17, "Community Chest #2", SpotType.CommunityChest); this.Board.Add(temp); temp = new Spot(18, "Tennessee Avenue", Color.DarkOrange, 180, 14, 70, 200, 550, 750, 950, 90, 100, 100); this.Board.Add(temp); temp = new Spot(19, "New York Avenue", Color.DarkOrange, 200, 16, 80, 220, 600, 800, 1000, 100, 100, 100); this.Board.Add(temp); // Third Row temp = new Spot(20, "Free Parking", SpotType.FreeParking); this.Board.Add(temp); temp = new Spot(21, "Kentucky Avenue", Color.Red, 220, 18, 90, 250, 700, 875, 1050, 110, 150, 150); this.Board.Add(temp); temp = new Spot(22, "Chance #2", SpotType.Chance); this.Board.Add(temp); temp = new Spot(23, "Indiana Avenue", Color.Red, 220, 18, 90, 250, 700, 875, 1050, 110, 150, 150); this.Board.Add(temp); temp = new Spot(24, "Illinois Avenue", Color.Red, 240, 20, 100, 300, 750, 925, 1100, 120, 150, 150); this.Board.Add(temp); temp = new Spot(25, "B. & O. Railroad", SpotType.Railroad, 200, 25); this.Board.Add(temp); temp = new Spot(26, "Atlantic Avenue", Color.Yellow, 260, 22, 110, 330, 800, 975, 1150, 130, 150, 150); this.Board.Add(temp); temp = new Spot(27, "Ventnor Avenue", Color.Yellow, 260, 22, 110, 330, 800, 975, 1150, 130, 150, 150); this.Board.Add(temp); temp = new Spot(28, "Water Works", SpotType.Utility, 150, 75); this.Board.Add(temp); temp = new Spot(29, "Marvin Gardens", Color.Yellow, 280, 24, 120, 360, 850, 1025, 1200, 140, 150, 150); this.Board.Add(temp); // Fourth Row temp = new Spot(30, "Go To Jail", SpotType.GoToJail); this.Board.Add(temp); temp = new Spot(31, "Pacific Avenue", Color.Green, 300, 26, 130, 390, 900, 1100, 1275, 150, 200, 200); this.Board.Add(temp); temp = new Spot(32, "North Carolina Avenue", Color.Green, 300, 26, 130, 390, 900, 1100, 1275, 150, 200, 200); this.Board.Add(temp); temp = new Spot(33, "Community Chest #3", SpotType.CommunityChest); this.Board.Add(temp); temp = new Spot(34, "Pennsylvania Avenue", Color.Green, 320, 28, 150, 450, 1000, 1200, 1400, 160, 200, 200); this.Board.Add(temp); temp = new Spot(35, "Short Line", SpotType.Railroad, 200, 25); this.Board.Add(temp); temp = new Spot(36, "Chance #3", SpotType.Chance); this.Board.Add(temp); temp = new Spot(37, "Park Place", Color.DarkBlue, 350, 35, 175, 500, 1100, 1300, 1500, 175, 200, 200); this.Board.Add(temp); temp = new Spot(38, "Luxury Tax", 200); this.Board.Add(temp); temp = new Spot(39, "Boardwalk", Color.DarkBlue, 400, 50, 200, 600, 1400, 1700, 2000, 200, 200, 200); this.Board.Add(temp); }
/// <summary> /// Initializes a new instance of the <see cref="UpgradeProperty"/> class /// </summary> /// <param name="game">brings forth the current game</param> /// <param name="currentPlayer">brings forth the currentPlayer</param> public UpgradeProperty(Game game, Player currentPlayer) { this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.ControlBox = false; this.MaximizeBox = false; this.MinimizeBox = false; this.InitializeComponent(); this.game = game; this.currentPlayer = currentPlayer; // fill the list with the list of spots that the currentPlayer has this.playerSpots = currentPlayer.GetPlayersPropertyList(this.game.Board); this.lblMoneyTotal.Text = currentPlayer.Money.ToString(); this.lblPlayerName.Text = currentPlayer.PlayerName; List <Spot> spotsEligible = new List <Spot>(); List <Color> colorsEligible = Game.CheckIfEligibleForHouse(this.playerSpots); List <Spot> mortgage = new List <Spot>(); foreach (Spot s in this.playerSpots) { if (s.IsMortgaged == true) { mortgage.Add(s); } } if (colorsEligible.Count > 0 || mortgage.Count > 0) { // Get every spot that matches a color in the list foreach (Spot s in this.playerSpots) { foreach (Color c in colorsEligible) { if ((s.Color == c || s.IsMortgaged == true) && !spotsEligible.Contains(s)) { spotsEligible.Add(s); } } if (!spotsEligible.Contains(s) && s.IsMortgaged) { spotsEligible.Add(s); } } // fill public slot this.eligible = spotsEligible; if (this.currentPlayer.IsAi == false) { // add them to the listView this.FillListView(this.listViewProperties, spotsEligible); } else { foreach (Spot s in this.eligible) { this.selectedSpot = s; // List that holds the spots of the same type this.sameType.Clear(); // Get a list of spots that share the same color foreach (Spot g in this.playerSpots) { if (g.Color == this.selectedSpot.Color && g.SpotName != this.selectedSpot.SpotName) { this.sameType.Add(g); } } // add houses/unmortgage/hotels to possible properties this.PropertyLogic(); } this.Close(); } } else { if (this.currentPlayer.IsAi == false) { MessageBox.Show("No Properties Eligible For Upgrade."); } this.Close(); } }
/// <summary> /// Has given player pay rent for given spot /// </summary> /// <param name="currentPlayer">The player to pay rent</param> /// <param name="currentLocation">The location the player is at</param> public void CheckPayRent(Player currentPlayer, Spot currentLocation) { // Check to see if the current location is a property, railroad, or utility if (currentLocation.Type == SpotType.Property || currentLocation.Type == SpotType.Railroad || currentLocation.Type == SpotType.Utility) { // If property is not mortgaged if (!currentLocation.IsMortgaged) { // Find the owner Player owner = currentLocation.Owner; if (!currentLocation.IsAvailable && owner != currentPlayer) { // Find the rent int rent = currentLocation.Rent; // If the current location is a railroad if (currentLocation.Type == SpotType.Railroad) { // Find the rent based on how many railroads the owner of the current location owns rent = currentLocation.FindCurrentRentOfRailroad(this.Board); } // If the current location is a utility if (currentLocation.Type == SpotType.Utility) { // Find the rent based on how many utilities the owner of the current location owns // and the dice roll (random number) rent = currentLocation.FindRentOfUtility(this.Board, currentPlayer); } // if the current location is a property with houses if (currentLocation.Type == SpotType.Property) { rent = currentLocation.FindRentOfRegularProperty(this.Board); } if (currentPlayer.TotalNetWorth(this.Board) < rent) { MessageBox.Show("You do not have enough net worth to pay rent!", currentPlayer.PlayerName + " is bankrupt!"); // Get the value of the unmortgaged properties so they are not double counted in value // (mortgaged properties are not included in the total net worth) int valueOfUnmortgagedProperties = 0; // Only bother handing over properties if there are more than 2 players - otherwise the game is almost over if (this.ActivePlayers() > 2) { // Hand over all properties foreach (Spot property in currentPlayer.GetPlayersPropertyList(this.Board)) { this.Board[property.SpotId].Owner = owner; if (this.Board[property.SpotId].IsMortgaged) { // Pay interest on mortgaged property this.Players[this.Players.IndexOf(owner)].Money -= (int)(this.Board[property.SpotId].Price * 0.1); // Ask owner of current location if they would like to unmortgage received mortgaged property string message = property.SpotName + " is mortgaged. Do you want to unmortgage it now?\n"; message += "If you choose later, interest will be paid twice.\n"; message += owner.PlayerName + "'s current balance is " + owner.Money.ToString("c0") + " and the mortgage value of the property is " + property.Mortgage.ToString("c0") + "."; DialogResult result = MessageBox.Show(message, "Receive Property - " + owner.PlayerName, MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { // Unmortgage property this.Board[property.SpotId].IsMortgaged = false; this.Players[this.Players.IndexOf(owner)].Money -= this.Board[property.SpotId].Mortgage; } } else { valueOfUnmortgagedProperties += property.Mortgage; } } } // Give the owner everything this.Players[this.Players.IndexOf(owner)].Money += currentPlayer.TotalNetWorth(this.Board) - valueOfUnmortgagedProperties; // Have current player give up everything to pay rent this.Players[this.Players.IndexOf(currentPlayer)].Money -= currentPlayer.TotalNetWorth(this.Board) - valueOfUnmortgagedProperties; this.Forfeit(currentPlayer); } else { // Give the owner the rent this.Players[this.Players.IndexOf(owner)].Money += rent; // Have current player pay rent this.Players[this.Players.IndexOf(currentPlayer)].Money -= rent; // Check if current player could not afford rent this.CheckIfPlayerHasEnoughMoney(currentPlayer); } } } } }
/// <summary> /// Initializes a new instance of the GetMoney class /// </summary> /// <param name="game">The game</param> /// <param name="currentPlayer">The current player</param> /// <param name="debt">The players debt</param> public GetMoney(Game game, Player currentPlayer, int debt) { this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.MaximizeBox = false; this.MinimizeBox = false; this.InitializeComponent(); this.Debt = debt; this.game = game; this.currentPlayer = currentPlayer; // Get the current players list of properties this.playerSpots = currentPlayer.GetPlayersPropertyList(game.Board); if (this.currentPlayer.IsAi == false) { this.FillListView(this.listViewProperties, this.playerSpots); this.lblTotalDebt.Text = debt.ToString(); this.lblDebtCurrent.Text = debt.ToString(); this.lblPlayerName.Text = this.currentPlayer.PlayerName; this.lblMoney.Text = this.currentPlayer.Money.ToString(); this.FillColors(this.playerSpots); } else { while (this.Debt > 0) { for (int x = 0; x < this.playerSpots.Count; x++) { if (this.Debt > 0) { this.currentSpot = this.playerSpots[x]; if (this.currentSpot.HasHotel == true) { this.BtnSellHotel_Click(this.currentSpot, EventArgs.Empty); } else if (this.currentSpot.NumberOfHouses > 0) { this.BtnSellHouse_Click(this.currentSpot, EventArgs.Empty); } else if (this.currentSpot.IsMortgaged == false) { this.BtnMortgage_Click(this.currentSpot, EventArgs.Empty); } if (x == this.playerSpots.Count) { if (this.Debt > 0) { this.game.CheckPayRent(this.currentPlayer, this.currentSpot); break; } } } else { this.BtnSubmit_Click(this.currentPlayer, EventArgs.Empty); break; } } if (this.Debt <= 0) { this.BtnSubmit_Click(this.currentPlayer, EventArgs.Empty); break; } else { this.game.CheckPayRent(this.currentPlayer, this.currentSpot); break; } } } }
/// <summary> /// The click event for the items in the list view of properties /// </summary> /// <param name="sender">The object</param> /// <param name="e">The event</param> private void ListViewProperties_Click(object sender, EventArgs e) { // check if selected item isn't null if (this.listViewProperties.SelectedItems[0] != null) { this.txtErrors.Text = string.Empty; this.Reset(); // find the current spot foreach (Spot s in this.playerSpots) { if (s.SpotName == this.listViewProperties.SelectedItems[0].Text) { this.currentSpot = s; } } // Create a list of properties with the same color as the original List <Spot> sameType = new List <Spot>(); foreach (Spot s in this.playerSpots) { if (s.Color == this.currentSpot.Color && s.SpotName != this.currentSpot.SpotName) { sameType.Add(s); } } // fill the labels with information if (this.currentSpot.HasHotel) { this.btnSellHotel.Enabled = true; } else { if (this.currentSpot.IsMortgaged == false) { // one of the property colors with only 2 properties if (sameType.Count == 1 && (this.currentSpot.Color == Color.Purple || this.currentSpot.Color == Color.DarkBlue)) { // both properties have the same number of houses if (sameType[0].NumberOfHouses == this.currentSpot.NumberOfHouses) { // if the other property with the same color has a hotel still if (sameType[0].HasHotel) { txtErrors.Text = "Must sell hotel on other property"; } else { if (this.currentSpot.NumberOfHouses > 0) { this.btnSellHouse.Enabled = true; } if (this.currentSpot.NumberOfHouses == 0 && sameType[0].NumberOfHouses == 0) { this.btnMortage.Enabled = true; } } } else { // if they have more houses than the other property of the same color if (this.currentSpot.NumberOfHouses > sameType[0].NumberOfHouses) { this.btnSellHouse.Enabled = true; } else { this.txtErrors.Text = "Another property of the same color has more houses than this one."; } } } else if (sameType.Count == 2) { // both properties have the same number of houses if (sameType[0].NumberOfHouses == this.currentSpot.NumberOfHouses && this.currentSpot.NumberOfHouses == sameType[1].NumberOfHouses) { // if the other property with the same color has a hotel still if (sameType[0].HasHotel || sameType[1].HasHotel) { txtErrors.Text = "Must sell hotel on other property"; } else { if (this.currentSpot.NumberOfHouses > 0) { this.btnSellHouse.Enabled = true; } if (this.currentSpot.NumberOfHouses == 0 && sameType[0].NumberOfHouses == 0 && sameType[1].NumberOfHouses == 0) { this.btnMortage.Enabled = true; } } } else { // if they have more houses than the other property of the same color if (this.currentSpot.NumberOfHouses > sameType[0].NumberOfHouses || this.currentSpot.NumberOfHouses > sameType[1].NumberOfHouses) { this.btnSellHouse.Enabled = true; } else { this.txtErrors.Text = "Another property of the same color has more houses than this one."; } } } else { if (!this.currentSpot.IsMortgaged) { this.btnMortage.Enabled = true; } } } else { this.btnMortage.Enabled = false; } } this.lblMoneyGainFromHotel.Text = "+" + (this.currentSpot.HotelCost / 2).ToString("c0"); this.lblMoneyGainFromHouse.Text = "+" + (this.currentSpot.HouseCost / 2).ToString("c0"); // Put on the property name this.lblPropertyName.Text = this.currentSpot.SpotName; this.lblPropertyName.ForeColor = this.currentSpot.Color; if (this.lblPropertyName.ForeColor == Color.Yellow) { this.lblPropertyName.ForeColor = Color.YellowGreen; } if (this.lblPropertyName.ForeColor == Color.LightBlue) { this.lblPropertyName.ForeColor = Color.Blue; } } }
/// <summary> /// Fills a given list view with the given list of spots (name and price) /// </summary> /// <param name="listView">The list view to fill</param> /// <param name="spots">The list of spots used to fill list view</param> public void FillListView(ListView listView, List <Spot> spots) { listView.Clear(); // Add Column Headers only if they don't already exist if (listView.Columns.Count == 0) { listView.Columns.Add("Property Name", 100); listView.Columns.Add("Mortgage", 60); listView.Columns.Add("Is Mortgaged", 75); listView.Columns.Add("Houses", 50); listView.Columns.Add("Hotel", 50); } // Array to hold to contents of each row of the list view string[] rowContents = new string[5]; // Loop through each spot in list of spots given foreach (Spot s in spots) { // Put the spot name in the first column rowContents[0] = s.SpotName; // Put the price in the second column rowContents[1] = s.Mortgage.ToString("c0"); // Put whether the property is mortgaged in the third column rowContents[2] = s.IsMortgaged.ToString(); // Put the number of houses a property has in the fourth column rowContents[3] = s.NumberOfHouses.ToString(); // Put whether a property has a hotel has in the fifth column rowContents[4] = s.HasHotel.ToString(); // Create a list view item that is a row made up of the spot name and price var row = new ListViewItem(rowContents); // Add created row to list view listView.Items.Add(row); } // Loop through each item in the list view foreach (ListViewItem item in listView.Items) { // Get the spot that corresponds with the spot name Spot spot = this.game.GetSpotByName(item.Text); // If a spot was found with that name if (spot != null) { // Set the text color to the property's color item.ForeColor = spot.Color; // Change the color for the lighter colors to darker colors if (spot.Color == Color.LightBlue) { item.ForeColor = Color.DodgerBlue; } else if (spot.Color == Color.Yellow) { item.ForeColor = Color.FromArgb(255, 220, 220, 0); } } } }
/* * public BuyProp() * { * InitializeComponent(); * } */ /// <summary> /// Initializes a new instance of the <see cref="BuyProp"/> class. /// </summary> /// <param name="spot">The spot that was selected</param> /// <param name="p">The current player</param> /// <param name="g">The game</param> public BuyProp(Spot spot, Player p, Game g) { this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.ControlBox = false; this.Text = string.Empty; this.MaximizeBox = false; this.MinimizeBox = false; // Copy the info from the MonPopUp to display card info this.InitializeComponent(); this.spotNameLabel.Text = spot.SpotName; this.spotNameLabel.BackColor = spot.Color; // Adjust text color so it is visible against the background if (spot.Color == Color.Purple || spot.Color == Color.Green || spot.Color == Color.DarkBlue || spot.Color == Color.Black || spot.Color == Color.Red || spot.Color == Color.MediumVioletRed) { this.spotNameLabel.ForeColor = Color.White; } else { this.spotNameLabel.ForeColor = Color.Black; } this.priceLabel.Text = "Price: " + spot.Price.ToString("C0"); this.mortgageLabel.Text = "Mortgage: " + spot.Mortgage.ToString("C0"); this.rentLabel.Text = string.Empty; if (spot.Type == SpotType.Property) { this.rentLabel.Text += "Rent: " + spot.Rent.ToString("C0") + '\n'; this.rentLabel.Text += "Rent with 1 House: " + spot.Rent1House.ToString("C0") + '\n'; this.rentLabel.Text += "Rent with 2 Houses: " + spot.Rent2Houses.ToString("C0") + '\n'; this.rentLabel.Text += "Rent with 3 Houses: " + spot.Rent3Houses.ToString("C0") + '\n'; this.rentLabel.Text += "Rent with 4 Houses: " + spot.Rent4Houses.ToString("C0") + '\n'; this.rentLabel.Text += "Rent with a Hotel: " + spot.RentHotel.ToString("C0"); } else if (spot.Type == SpotType.Railroad) { this.rentLabel.Text += "Rent: " + spot.Rent.ToString("C0") + '\n'; this.rentLabel.Text += "If 2 are owned: " + (spot.Rent * 2).ToString("C0") + '\n'; this.rentLabel.Text += "If 3 are owned: " + (spot.Rent * 4).ToString("C0") + '\n'; this.rentLabel.Text += "If 4 are owned: " + (spot.Rent * 8).ToString("C0"); } else if (spot.Type == SpotType.Utility) { this.rentLabel.Text += "If one Utility is owned, rent is 4 times amount shown on dice." + '\n'; this.rentLabel.Text += "If both Utilities are owned, rent is 10 times amount shown on dice."; } // Output the players balance this.lblYourMoney.Text = p.Money.ToString("c0"); // Check to see if the player is even able to purchase the property if (p.Money < spot.Price) { // If they aren't able to purchase it, then close the form this.Close(); } // Set a temporary variable in this form to store the spot s and the currentPlayer p this.s = spot; this.currentPlayer = p; // Use the same version of game. this.game = g; if (p.IsAi == true) { if (p.Money >= spot.Price) { this.BtnYes_Click(p, EventArgs.Empty); } else { this.BtnNo_Click(p, EventArgs.Empty); } } }