public void buyProperty() { if (board.locations[PlayerManager.location] is Property) { Property boughtProperty = (Property)board.locations[PlayerManager.location]; PlayerManager.balance -= boughtProperty.price; // Subtract price from balance } else if (board.locations[PlayerManager.location] is Utility) { Utility boughtProperty = (Utility)board.locations[PlayerManager.location]; PlayerManager.balance -= boughtProperty.price; // Subtract price from balance } else //Railroad { Railroad boughtProperty = (Railroad)board.locations[PlayerManager.location]; PlayerManager.balance -= boughtProperty.price; // Subtract price from balance } // Change our ownedProperties CustomProperty bool[] ownedProperties = (bool[])PhotonNetwork.LocalPlayer.CustomProperties["OwnedProperties"]; ownedProperties[PlayerManager.location] = true; ExitGames.Client.Photon.Hashtable hash = new ExitGames.Client.Photon.Hashtable(); hash.Add("OwnedProperties", ownedProperties); PhotonNetwork.LocalPlayer.SetCustomProperties(hash); // This will change the property on our local player since the message is also sent to us object[] data = new object[] { PlayerManager.location, "owner", currentPlayer }; SendEvent(PropertyChangeCode, data); // Send activity message as well string text = "bought " + board.locations[PlayerManager.location].name; SendActivityMessage(text, currentPlayer); DisableButton("buyPropertyButton"); }
public override void OnPlayerLeftRoom(Player other) { string text = other.NickName + " has left the game."; PlayerUi.SendMessage("AddActivityText", text, SendMessageOptions.RequireReceiver); // Reset all owned properties of the player // We do this locally for every player so we don't need to use the network for (int i = 0; i < 40; i++) { if (board.locations[i] is Property) { Property property = (Property)board.locations[i]; if (property.owner == other) { property.Reset(); } } else if (board.locations[i] is Utility) { Utility property = (Utility)board.locations[i]; if (property.owner == other) { property.owner = null; } } else if (board.locations[i] is Railroad) { Railroad property = (Railroad)board.locations[i]; if (property.owner == other) { property.owner = null; } } } if (PhotonNetwork.IsMasterClient) { if (players[currentPlayer] == other) { players = PhotonNetwork.PlayerList; NextPlayer(); } else { players = PhotonNetwork.PlayerList; CheckNumBankrupt(); } } else { players = PhotonNetwork.PlayerList; } }
public void SellProperty(int property) { if (board.locations[property] is Property) { Property boughtProperty = (Property)board.locations[property]; // Sells for half price - plus houses at half price PlayerManager.balance += (int)(0.5 * boughtProperty.price); PlayerManager.balance += (int)(0.5 * boughtProperty.housePrice * boughtProperty.numHouses); // Send message to reset property // This will change the property on our local player since the message is also sent to us object[] data = new object[] { property, "reset" }; SendEvent(PropertyChangeCode, data); } else if (board.locations[property] is Utility) { Utility boughtProperty = (Utility)board.locations[property]; PlayerManager.balance += (int)(0.5 * boughtProperty.price); } else //Railroad { Railroad boughtProperty = (Railroad)board.locations[property]; PlayerManager.balance += (int)(0.5 * boughtProperty.price); } // Change our ownedProperties CustomProperty bool[] ownedProperties = (bool[])PhotonNetwork.LocalPlayer.CustomProperties["OwnedProperties"]; ownedProperties[property] = false; ExitGames.Client.Photon.Hashtable hash = new ExitGames.Client.Photon.Hashtable(); hash.Add("OwnedProperties", ownedProperties); PhotonNetwork.LocalPlayer.SetCustomProperties(hash); // This will change the property on our local player since the message is also sent to us object[] data2 = new object[] { property, "owner", null }; SendEvent(PropertyChangeCode, data2); // Send activity message as well string text = "sold " + board.locations[property].name; int localPlayer = 0; for (int i = 0; i < PhotonNetwork.CurrentRoom.PlayerCount; i++) { if (players[i] == PhotonNetwork.LocalPlayer) { localPlayer = i; } } SendActivityMessage(text, localPlayer); }
public Board(int size) { Size = size; spaces = new Space[size]; spaces[0] = new Go(); for (int i = 1; i < size; i++) { if (i % 5 == 0) { spaces[i] = new Railroad("F" + (i / 5).ToString()); } else { spaces[i] = new Property("P" + i.ToString()); } } }
public void UpdateDropdownOptions() { propertyDropdown.ClearOptions(); List <string> options = new List <string>(); ownedProperties = new List <int>(); bool[] ownedProp = (bool[])PhotonNetwork.LocalPlayer.CustomProperties["OwnedProperties"]; for (int i = 0; i < 40; i++) { if (ownedProp[i] == true) { string dropDownText = GameManager.instance.board.locations[i].name; int price = 0; // Calculate sell price if (GameManager.instance.board.locations[i] is Property) { Property property = (Property)GameManager.instance.board.locations[i]; price = (int)(0.5 * property.price); price += (int)(0.5 * property.housePrice * property.numHouses); } else if (GameManager.instance.board.locations[i] is Utility) { Utility property = (Utility)GameManager.instance.board.locations[i]; price = (int)(0.5 * property.price); } else if (GameManager.instance.board.locations[i] is Railroad) { Railroad property = (Railroad)GameManager.instance.board.locations[i]; price = (int)(0.5 * property.price); } dropDownText = dropDownText + " - $" + price.ToString(); options.Add(dropDownText); ownedProperties.Add(i); } } propertyDropdown.AddOptions(options); propertyDropdown.value = 0; propertyDropdown.RefreshShownValue(); currentDropdown = 0; }
public void NoMoney(int amount) { DisableButton("buyPropertyButton"); DisableButton("buildHouseButton"); DisableButton("sellPropertyButton"); DisableButton("endTurnButton"); int amountFromProperties = 0; bool[] ownedProperties = (bool[])PhotonNetwork.LocalPlayer.CustomProperties["OwnedProperties"]; for (int i = 0; i < 40; i++) { if (ownedProperties[i] == true) { if (board.locations[i] is Property) { Property property = (Property)board.locations[i]; amountFromProperties += (int)(0.5 * property.price); amountFromProperties += (int)(0.5 * property.housePrice * property.numHouses); } else if (board.locations[i] is Utility) { Utility property = (Utility)board.locations[i]; amountFromProperties += (int)(0.5 * property.price); } else { Railroad property = (Railroad)board.locations[i]; amountFromProperties += (int)(0.5 * property.price); } } } if (amountFromProperties >= amount) { PlayerManager.noMoneyAmount = amount; noMoneyOptions.SetActive(true); } else { Bankrupt(); } }
public void BuyRailroad(Railroad railroad) { Money -= railroad.Price; railroad.Owner = this; Railroads.Add(railroad); }
public void DisplayPropertyInfo(int propertyNum) { if (propertyNum == -1) { string text = "<b>Reading Railroad</b>"; Railroad readingRailroad = (Railroad)GameManager.instance.board.locations[5]; if (readingRailroad.owner == null) { text = text + " - Owner: None"; } else { text = text + " - Owner: " + readingRailroad.owner.NickName; } Railroad pennsylvaniaRailroad = (Railroad)GameManager.instance.board.locations[15]; text = text + "\n<b>Pennsylvania Railroad</b>"; if (pennsylvaniaRailroad.owner == null) { text = text + " - Owner: None"; } else { text = text + " - Owner: " + pennsylvaniaRailroad.owner.NickName; } Railroad bAndORailroad = (Railroad)GameManager.instance.board.locations[25]; text = text + "\n<b>B & O Railroad</b>"; if (bAndORailroad.owner == null) { text = text + " - Owner: None"; } else { text = text + " - Owner: " + bAndORailroad.owner.NickName; } Railroad shortLine = (Railroad)GameManager.instance.board.locations[35]; text = text + "\n<b>Short Line</b>"; if (shortLine.owner == null) { text = text + " - Owner: None"; } else { text = text + " - Owner: " + shortLine.owner.NickName; } text = text + "\n\nPrice: $200\n\nRent:\n1 owned: $25\n2 owned: $50\n3 owned: $100\n4 owned: $200"; windowText.text = text; } else if (propertyNum == -2) { string text = "<b>Electric Company</b>\n"; Utility electricCompany = (Utility)GameManager.instance.board.locations[12]; if (electricCompany.owner == null) { text = text + "Owner: None"; } else { text = text + "Owner: " + electricCompany.owner.NickName; } text = text + "\n\n<b>Water Works</b>\n"; Utility waterWorks = (Utility)GameManager.instance.board.locations[28]; if (waterWorks.owner == null) { text = text + "Owner: None"; } else { text = text + "Owner: " + waterWorks.owner.NickName; } text = text + "\n\nPrice: $150"; text = text + "\n\nRent:\n1 utility owned: $4 x diceroll"; text = text + "\n2 utility owned: $10 x diceroll"; windowText.text = text; } else if (GameManager.instance.board.locations[propertyNum] is Property) { Property property = (Property)GameManager.instance.board.locations[propertyNum]; string text = "<b>" + property.name + "</b>\n"; if (property.owner == null) { text = text + "Owner: None"; } else { text = text + "Owner: " + property.owner.NickName; } text = text + "\nPrice: $" + property.price; text = text + "\nHouse price: $" + property.housePrice; text = text + "\nNumber of houses built: " + property.numHouses; int baseRent = property.baseRent; text = text + "\n\nRent:\n0 houses: $" + baseRent; text = text + "\n1 house: $" + (baseRent * 5); text = text + "\n2 houses: $" + (baseRent * 15); text = text + "\n3 houses: $" + (baseRent * 45); text = text + "\n4 houses: $" + ((baseRent * 45) + 200); text = text + "\n5 houses (hotel): $" + ((baseRent * 45) + 400); windowText.text = text; } this.gameObject.SetActive(true); }
public void OnEvent(EventData photonEvent) { byte eventCode = photonEvent.Code; switch (eventCode) { case SendNewActivityLineCode: object[] arr = (object[])photonEvent.CustomData; ReceiveActivityMessage(arr); break; case PlayerTurnCode: currentPlayer = (int)photonEvent.CustomData; StartTurn(); break; case ReceiveMoneyCode: int amount = (int)photonEvent.CustomData; PlayerManager.balance += amount; break; case PropertyChangeCode: object[] data = (object[])photonEvent.CustomData; int location = (int)data[0]; string property = (string)data[1]; if (board.locations[location] is Utility) { Utility temp = (Utility)board.locations[location]; if (property == "owner") { if (data[2] == null) { temp.owner = null; } else { temp.owner = players[(int)data[2]]; } } board.locations[location] = temp; } else if (board.locations[location] is Railroad) { Railroad temp = (Railroad)board.locations[location]; if (property == "owner") { if (data[2] == null) { temp.owner = null; } else { temp.owner = players[(int)data[2]]; } } board.locations[location] = temp; } else if (board.locations[location] is Property) { Property temp = (Property)board.locations[location]; if (property == "owner") { if (data[2] == null) { temp.owner = null; } else { temp.owner = players[(int)data[2]]; } board.locations[location] = temp; } else if (property == "buildHouse") { temp.BuildHouse(); } else if (property == "reset") { temp.Reset(); } board.locations[location] = temp; } break; case EndGameCode: int?playerNum = (int?)photonEvent.CustomData; if (playerNum == null) { EndGame(null); } else { EndGame(players[(int)playerNum], true); } break; case CardCode: string[] data2 = (string[])photonEvent.CustomData; cardWindow.DisplayCard(data2[0], data2[1]); break; } }
public void Bankrupt() { // Set custom player property as bankrupt ExitGames.Client.Photon.Hashtable hash = new ExitGames.Client.Photon.Hashtable(); hash.Add("Bankrupt", true); hash.Add("OwnedProperties", new bool[40]); PhotonNetwork.LocalPlayer.SetCustomProperties(hash); SendActivityMessage("went bankrupt!", currentPlayer); // Check how many players are not bankrupt // We do this here because the custom properties are not set fast enough List <Player> notBankrupt = new List <Player>(); foreach (Player player in players) { if (player == PhotonNetwork.LocalPlayer) { continue; } if ((bool)player.CustomProperties["Bankrupt"] == false) { notBankrupt.Add(player); } } if (notBankrupt.Count == 0) { EndGame(null); return; } else if (notBankrupt.Count == 1) // Only one person left, they are the winner { EndGame(notBankrupt[0]); return; } // Reset all owned properties for (int i = 0; i < 40; i++) { if (board.locations[i] is Property) { Property property = (Property)board.locations[i]; if (property.owner == PhotonNetwork.LocalPlayer) { object[] data = { i, "reset" }; SendEvent(PropertyChangeCode, data); } } else if (board.locations[i] is Utility) { Utility property = (Utility)board.locations[i]; if (property.owner == PhotonNetwork.LocalPlayer) { object[] data = { i, "owner", null }; SendEvent(PropertyChangeCode, data); } } else { Railroad property = (Railroad)board.locations[i]; if (property.owner == PhotonNetwork.LocalPlayer) { object[] data = { i, "owner", null }; SendEvent(PropertyChangeCode, data); } } } NextPlayer(); }
public void LandedOn(int?diceRoll = null) { string landedOnText = "landed on " + board.locations[PlayerManager.location].name; SendActivityMessage(landedOnText, currentPlayer); if (board.locations[PlayerManager.location] is Property) { Property currentLocation = (Property)board.locations[PlayerManager.location]; // Unowned if (currentLocation.owner == null) { if (PlayerManager.balance >= currentLocation.price) { EnableButton("buyPropertyButton"); } } else // Owned { if (currentLocation.owner != players[currentPlayer]) // By other { int rent = currentLocation.GetRent(); bool paid = PayMoney(rent, currentLocation.owner); if (paid) { string text = "paid $" + rent + " in rent to " + currentLocation.owner.NickName; SendActivityMessage(text, currentPlayer); } else { isRent = true; } } } } else if (board.locations[PlayerManager.location] is Railroad) { Railroad currentLocation = (Railroad)board.locations[PlayerManager.location]; if (currentLocation.owner == null) { if (PlayerManager.balance >= currentLocation.price) { EnableButton("buyPropertyButton"); } } else // Owned { if (currentLocation.owner != players[currentPlayer]) // By other { int rent = currentLocation.GetRent(); bool paid = PayMoney(rent, currentLocation.owner); if (paid) { string text = "paid $" + rent + " in rent to " + currentLocation.owner.NickName; SendActivityMessage(text, currentPlayer); } else { isRent = true; } } } } else if (board.locations[PlayerManager.location] is Utility) { Utility currentLocation = (Utility)board.locations[PlayerManager.location]; if (currentLocation.owner == null) { if (PlayerManager.balance >= currentLocation.price) { EnableButton("buyPropertyButton"); } } else // Owned { if (currentLocation.owner != players[currentPlayer]) // By other { int rent = currentLocation.GetRent((int)diceRoll); bool paid = PayMoney(rent, currentLocation.owner); if (paid) { string text = "paid $" + rent + " in rent to " + currentLocation.owner.NickName; SendActivityMessage(text, currentPlayer); } else { isRent = true; } } } } else if (board.locations[PlayerManager.location] is Tax) { Tax currentLocation = (Tax)board.locations[PlayerManager.location]; bool paid = PayMoney(currentLocation.tax); if (paid) { string text = "paid $" + currentLocation.tax + " in taxes"; SendActivityMessage(text, currentPlayer); } } else if (board.locations[PlayerManager.location] is Location) { switch (board.locations[PlayerManager.location].name) { case "GO": ReceiveMoney(200); break; case "Jail": break; case "Free Parking": break; case "Go To Jail": MoveToLocation(10); LandedOn(); bool paid = PayMoney(50); if (paid) { int amountPaid = 50; string paidMessage = "paid $" + amountPaid.ToString(); SendActivityMessage(paidMessage, currentPlayer); } break; case "Chance": Card drawnCard = board.DrawChance(); string[] data = { "Chance", drawnCard.description }; SendEvent(CardCode, data); // If receive money if (drawnCard.amountMoney > 0) { ReceiveMoney(drawnCard.amountMoney); string receivedMessage = "received $" + drawnCard.amountMoney.ToString(); SendActivityMessage(receivedMessage, currentPlayer); } else if (drawnCard.amountMoney < 0) { bool paid2 = PayMoney(Math.Abs(drawnCard.amountMoney)); if (paid2) { string paidMessage = "paid $" + Math.Abs(drawnCard.amountMoney).ToString(); SendActivityMessage(paidMessage, currentPlayer); } } if (drawnCard.moveTo != null) { MoveToLocation((int)drawnCard.moveTo); LandedOn(); } break; case "Community Chest": Card drawnCard2 = board.DrawCommunityChest(); string[] data2 = { "Community Chance", drawnCard2.description }; SendEvent(CardCode, data2); // If receive money if (drawnCard2.amountMoney > 0) { ReceiveMoney(drawnCard2.amountMoney); string receivedMessage2 = "received $" + drawnCard2.amountMoney.ToString(); SendActivityMessage(receivedMessage2, currentPlayer); } else if (drawnCard2.amountMoney < 0) { bool paid3 = PayMoney(Math.Abs(drawnCard2.amountMoney)); if (paid3) { string paidMessage2 = "paid $" + Math.Abs(drawnCard2.amountMoney).ToString(); SendActivityMessage(paidMessage2, currentPlayer); } } if (drawnCard2.moveTo != null) { MoveToLocation((int)drawnCard2.moveTo); LandedOn(); } break; } } }