/// <summary> /// Creates a new hotel chain /// </summary> /// <param name="cell">Cell containing tile to create chain with</param> /// <param name="largestChain">Out parameter to be used for adding additional tiles to new chain</param> public void CreateChain(Cell cell, out HotelChain largestChain) { cell.hotelTile.GetComponent <HotelTile>().HotelChain = gameManager.hotelChains[0]; hotelTile.GetComponent <HotelTile>().HotelChain = gameManager.hotelChains[0]; SetTileColor(gameManager.hotelChains[0].color); cell.SetTileColor(gameManager.hotelChains[0].color); largestChain = gameManager.hotelChains[0]; Debug.Log(gameManager.playerTurn + " Created " + gameManager.hotelChains[0].name + " hotel chain!"); GameObject.Find("lblGameWarning").GetComponent <UnityEngine.UI.Text>().text = gameManager.playerTurn + " Created " + gameManager.hotelChains[0].name + " hotel chain!"; gameManager.playerTurn.ownedStocks.Add(largestChain.availableStocks[0]); largestChain.availableStocks.RemoveAt(0); gameManager.hotelChains.RemoveAt(0); }
/// <summary> /// Sells stocks from a defunct chain /// </summary> /// <param name="chain">Owning chain of the stocks to be sold</param> /// <param name="quantity">The amount of stocks to be sold</param> public void Sell(HotelChain chain, int quantity) { var sellableStocks = ownedStocks.Where(stock => stock.OwningChain.Equals(chain)).ToList(); while (quantity != 0 && sellableStocks.Count != 0) { balance += sellableStocks[0].Price; chain.availableStocks.Add(sellableStocks[0]); ownedStocks.Remove(sellableStocks[0]); sellableStocks.RemoveAt(0); quantity--; } }
/// <summary> /// Gets the largest hotelChain of this cells surrounding neighbors /// </summary> /// <returns>Null if cell is isolated from tiles, or the largest hotel chain</returns> public HotelChain GetLargestChain() { HotelChain largestChain = null; foreach (Cell cell in GetOccupiedNeighbors()) { if (cell.hotelTile.GetComponent <HotelTile>().HotelChain != null) { if (largestChain == null || largestChain.hotelTiles.Count < cell.hotelTile.GetComponent <HotelTile>().HotelChain.hotelTiles.Count) { largestChain = cell.hotelTile.GetComponent <HotelTile>().HotelChain; } } } return(largestChain); }
/// <summary> /// Purchase stocks from a hotel chain using balance /// </summary> /// <param name="chain">The chain to buy stocks in</param> /// <param name="quantity">The amount of stocks to buy (MAX = 3)</param> public void Buy(HotelChain chain, int quantity) { if (chain.availableStocks[0].Price * quantity > balance) { throw new Exception("This player doesn't have enough money to buy that specified number of stocks."); } else if (quantity > 3) { throw new Exception("The max amount of stocks you can buy in a turn is three."); } else { balance = balance - (chain.availableStocks[0].Price * quantity); ownedStocks.Add(chain.availableStocks[0]); chain.availableStocks.RemoveAt(0); } }
/// <summary> /// Updates the size labels for each hotel chain /// </summary> public void DisplayChainInfo() { int arcadiaSize = 0; int arcadiaStocks = 25; int fanfareSize = 0; int fanfareStocks = 25; int globalSize = 0; int globalStocks = 25; int lusterSize = 0; int lusterStocks = 25; int regalSize = 0; int regalStocks = 25; int tetonSize = 0; int tetonStocks = 25; int nobelSize = 0; int nobelStocks = 25; int arcadiaStockPrice = 300; int fanfareStockPrice = 300; int globalStockPrice = 300; int lusterStockPrice = 300; int regalStockPrice = 300; int tetonStockPrice = 300; int nobelStockPrice = 300; for (int row = 0; row < 9; row++) { for (int column = 0; column < 12; column++) { Cell cell = board.cells[row, column].GetComponent <Cell>(); if (cell.hotelTile != null && cell.hotelTile.GetComponent <HotelTile>().HotelChain != null) { HotelChain hc = cell.hotelTile.GetComponent <HotelTile>().HotelChain; if (hc.Equals(new HotelChain("Arcadia", Color.blue))) { arcadiaSize = hc.hotelTiles.Count; arcadiaStocks = hc.availableStocks.Count; if (hc.NumberOfStocksAvailable() != 0) { arcadiaStockPrice = hc.availableStocks.Find(x => x.OwningChain.name == "Arcadia").Price; } } else if (hc.Equals(new HotelChain("Fanfare", Color.green))) { fanfareSize = hc.hotelTiles.Count; fanfareStocks = hc.availableStocks.Count; if (hc.NumberOfStocksAvailable() != 0) { fanfareStockPrice = hc.availableStocks.Find(x => x.OwningChain.name == "Fanfare").Price; } } else if (hc.Equals(new HotelChain("Global", Color.gray))) { globalSize = hc.hotelTiles.Count; globalStocks = hc.availableStocks.Count; if (hc.NumberOfStocksAvailable() != 0) { globalStockPrice = hc.availableStocks.Find(x => x.OwningChain.name == "Global").Price; } } else if (hc.Equals(new HotelChain("Luster", Color.red))) { lusterSize = hc.hotelTiles.Count; lusterStocks = hc.availableStocks.Count; if (hc.NumberOfStocksAvailable() != 0) { lusterStockPrice = hc.availableStocks.Find(x => x.OwningChain.name == "Luster").Price; } } else if (hc.Equals(new HotelChain("Regal", Color.magenta))) { regalSize = hc.hotelTiles.Count; regalStocks = hc.availableStocks.Count; if (hc.NumberOfStocksAvailable() != 0) { regalStockPrice = hc.availableStocks.Find(x => x.OwningChain.name == "Regal").Price; } } else if (hc.Equals(new HotelChain("Teton", Color.yellow))) { tetonSize = hc.hotelTiles.Count; tetonStocks = hc.availableStocks.Count; if (hc.NumberOfStocksAvailable() != 0) { tetonStockPrice = hc.availableStocks.Find(x => x.OwningChain.name == "Teton").Price; } } else if (hc.Equals(new HotelChain("Nobel", Color.cyan))) { nobelSize = hc.hotelTiles.Count; tetonStocks = hc.availableStocks.Count; if (hc.NumberOfStocksAvailable() != 0) { nobelStockPrice = hc.availableStocks.Find(x => x.OwningChain.name == "Nobel").Price; } } } } } foreach (Player player in players) { foreach (Stock stock in player.ownedStocks) { if (stock.OwningChain.Equals(new HotelChain("Arcadia", Color.blue))) { arcadiaStocks = stock.OwningChain.availableStocks.Count; } else if (stock.OwningChain.Equals(new HotelChain("Fanfare", Color.green))) { fanfareStocks = stock.OwningChain.availableStocks.Count; } else if (stock.OwningChain.Equals(new HotelChain("Global", Color.gray))) { globalStocks = stock.OwningChain.availableStocks.Count; } else if (stock.OwningChain.Equals(new HotelChain("Luster", Color.red))) { lusterStocks = stock.OwningChain.availableStocks.Count; } else if (stock.OwningChain.Equals(new HotelChain("Regal", Color.magenta))) { regalStocks = stock.OwningChain.availableStocks.Count; } else if (stock.OwningChain.Equals(new HotelChain("Teton", Color.yellow))) { tetonStocks = stock.OwningChain.availableStocks.Count; } else if (stock.OwningChain.Equals(new HotelChain("Nobel", Color.cyan))) { nobelStocks = stock.OwningChain.availableStocks.Count; } } } int arcadiaOwnedStocks = 0; int fanfareOwnedStocks = 0; int globalOwnedStocks = 0; int lusterOwnedStocks = 0; int regalOwnedStocks = 0; int tetonOwnedStocks = 0; int nobelOwnedStocks = 0; foreach (Stock stock in playerTurn.ownedStocks) { if (stock.OwningChain.Equals(new HotelChain("Arcadia", Color.blue))) { arcadiaOwnedStocks++; } else if (stock.OwningChain.Equals(new HotelChain("Fanfare", Color.green))) { fanfareOwnedStocks++; } else if (stock.OwningChain.Equals(new HotelChain("Global", Color.gray))) { globalOwnedStocks++; } else if (stock.OwningChain.Equals(new HotelChain("Luster", Color.red))) { lusterOwnedStocks++; } else if (stock.OwningChain.Equals(new HotelChain("Regal", Color.magenta))) { regalOwnedStocks++; } else if (stock.OwningChain.Equals(new HotelChain("Teton", Color.yellow))) { tetonOwnedStocks++; } else if (stock.OwningChain.Equals(new HotelChain("Nobel", Color.cyan))) { nobelOwnedStocks++; } } foreach (Player player in players) { foreach (Stock stock in player.ownedStocks) { if (stock.OwningChain.Equals(new HotelChain("Arcadia", Color.blue))) { arcadiaStockPrice = stock.Price; } else if (stock.OwningChain.Equals(new HotelChain("Fanfare", Color.green))) { fanfareStockPrice = stock.Price; } else if (stock.OwningChain.Equals(new HotelChain("Global", Color.gray))) { globalStockPrice = stock.Price; } else if (stock.OwningChain.Equals(new HotelChain("Luster", Color.red))) { lusterStockPrice = stock.Price; } else if (stock.OwningChain.Equals(new HotelChain("Regal", Color.magenta))) { regalStockPrice = stock.Price; } else if (stock.OwningChain.Equals(new HotelChain("Teton", Color.yellow))) { tetonStockPrice = stock.Price; } else if (stock.OwningChain.Equals(new HotelChain("Nobel", Color.cyan))) { nobelStockPrice = stock.Price; } } } hotelInformationLabels.transform.Find("lblArcadiaSize").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = arcadiaSize.ToString(); hotelInformationLabels.transform.Find("lblArcadiaStocks").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = arcadiaStocks.ToString(); hotelInformationLabels.transform.Find("lblFanFareSize").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = fanfareSize.ToString(); hotelInformationLabels.transform.Find("lblFanFareStocks").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = fanfareStocks.ToString(); hotelInformationLabels.transform.Find("lblGlobalSize").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = globalSize.ToString(); hotelInformationLabels.transform.Find("lblGlobalStocks").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = globalStocks.ToString(); hotelInformationLabels.transform.Find("lblLusterSize").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = lusterSize.ToString(); hotelInformationLabels.transform.Find("lblLusterStocks").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = lusterStocks.ToString(); hotelInformationLabels.transform.Find("lblRegalSize").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = regalSize.ToString(); hotelInformationLabels.transform.Find("lblRegalStocks").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = regalStocks.ToString(); hotelInformationLabels.transform.Find("lblTetonSize").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = tetonSize.ToString(); hotelInformationLabels.transform.Find("lblTetonStocks").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = tetonStocks.ToString(); hotelInformationLabels.transform.Find("lblNobelSize").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = nobelSize.ToString(); hotelInformationLabels.transform.Find("lblNobelStocks").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = nobelStocks.ToString(); hotelInformationLabels.transform.Find("lblOwnedStocks").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = playerTurn.name + "\r\nOwned\r\nStocks:"; hotelInformationLabels.transform.Find("lblOwnedArcadiaStocks").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = arcadiaOwnedStocks.ToString(); hotelInformationLabels.transform.Find("lblOwnedFanFareStocks").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = fanfareOwnedStocks.ToString(); hotelInformationLabels.transform.Find("lblOwnedGlobalStocks").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = globalOwnedStocks.ToString(); hotelInformationLabels.transform.Find("lblOwnedLusterStocks").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = lusterOwnedStocks.ToString(); hotelInformationLabels.transform.Find("lblOwnedRegalStocks").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = regalOwnedStocks.ToString(); hotelInformationLabels.transform.Find("lblOwnedTetonStocks").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = tetonOwnedStocks.ToString(); hotelInformationLabels.transform.Find("lblOwnedNobelStocks").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = nobelOwnedStocks.ToString(); hotelInformationLabels.transform.Find("lblArcadiaStockPrice").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = "$" + arcadiaStockPrice; hotelInformationLabels.transform.Find("lblFanFareStockPrice").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = "$" + fanfareStockPrice; hotelInformationLabels.transform.Find("lblGlobalStockPrice").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = "$" + globalStockPrice; hotelInformationLabels.transform.Find("lblLusterStockPrice").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = "$" + lusterStockPrice; hotelInformationLabels.transform.Find("lblRegalStockPrice").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = "$" + regalStockPrice; hotelInformationLabels.transform.Find("lblNobelStockPrice").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = "$" + nobelStockPrice; hotelInformationLabels.transform.Find("lblTetonStockPrice").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = "$" + tetonStockPrice; }
public Stock(HotelChain owningChain, int price) { this.owningChain = owningChain; this.price = price; }
/// <summary> /// Creates a hotelTile gameobject and places it in this cell, handling merging logic /// </summary> /// <returns>Bool indicating if tile was placed successfully</returns> public bool AddHotelTile() { List <Cell> occupiedNeighbors = GetOccupiedNeighbors(); bool tileIsPlaced = true; bool neighborsHaveChain = false; foreach (Cell cell in occupiedNeighbors) { if (cell.hotelTile.GetComponent <HotelTile>().HotelChain != null) { neighborsHaveChain = true; } } if (occupiedNeighbors.Count == 0 || gameManager.hotelChains.Count != 0 || neighborsHaveChain == true) { GameObject hotelTile = Instantiate(hotelTilePrefab) as GameObject; hotelTile.transform.parent = this.transform; hotelTile.transform.localPosition = new Vector3(0.0f, 0.5f, 0.0f); hotelTile.GetComponent <HotelTile>().row = row; hotelTile.GetComponent <HotelTile>().column = column; this.hotelTile = hotelTile; if (occupiedNeighbors.Count != 0) { HotelChain largestChain = GetLargestChain(); // Handling merging of chains foreach (Cell cell in occupiedNeighbors) { if (cell.hotelTile.GetComponent <HotelTile>().HotelChain != null && occupiedNeighbors.Count > 1 && cell.hotelTile.GetComponent <HotelTile>().HotelChain.hotelTiles.Count < 11) { foreach (GameObject tile in cell.hotelTile.GetComponent <HotelTile>().HotelChain.hotelTiles.ToList()) { if (!(gameManager.hotelChains.Contains(tile.GetComponent <HotelTile>().HotelChain)) && !tile.GetComponent <HotelTile>().HotelChain.Equals(largestChain)) { gameManager.hotelChains.Add(tile.GetComponent <HotelTile>().HotelChain); } if (tile.GetComponent <HotelTile>().HotelChain != null) { tile.GetComponent <HotelTile>().HotelChain.hotelTiles.Remove(tile); } tile.GetComponent <HotelTile>().HotelChain = largestChain; tile.GetComponent <HotelTile>().SetMaterialColor(largestChain.color); } hotelTile.GetComponent <HotelTile>().HotelChain = largestChain; SetTileColor(largestChain.color); } else if (cell.hotelTile.GetComponent <HotelTile>().HotelChain != null && cell.hotelTile.GetComponent <HotelTile>().HotelChain.hotelTiles.Count >= 11 && !cell.hotelTile.GetComponent <HotelTile>().HotelChain.Equals(largestChain)) { GameObject.Find("lblGameWarning").GetComponent <UnityEngine.UI.Text>().text = "Cannot merge chains that are safe!"; Debug.Log("Cannot merge chains that are safe!"); Destroy(hotelTile); tileIsPlaced = false; return(tileIsPlaced); } else if (cell.hotelTile.GetComponent <HotelTile>().HotelChain == null && largestChain != null) { cell.hotelTile.GetComponent <HotelTile>().HotelChain = largestChain; cell.SetTileColor(largestChain.color); } } foreach (Cell cell in occupiedNeighbors) { // Create new hotel chain if (cell.hotelTile.GetComponent <HotelTile>().HotelChain == null && hotelTile.GetComponent <HotelTile>().HotelChain == null && gameManager.hotelChains.Count != 0) { CreateChain(cell, out largestChain); // Add hoteltile in this cell adjacent hoteltiles to existing chain } else { hotelTile.GetComponent <HotelTile>().HotelChain = largestChain; SetTileColor(largestChain.color); cell.hotelTile.GetComponent <HotelTile>().HotelChain = hotelTile.GetComponent <HotelTile>().HotelChain; cell.SetTileColor(hotelTile.GetComponent <HotelTile>().HotelChain.color); } } } } else { tileIsPlaced = false; } return(tileIsPlaced); }
/// <summary> /// Method for subtraction buttons in buyStocksUI /// </summary> public void SellStock() { HotelChain arcadia = null; HotelChain fanfare = null; HotelChain global = null; HotelChain luster = null; HotelChain regal = null; HotelChain nobel = null; HotelChain teton = null; // get references to all active hotelchains in the game for (int row = 0; row < 9; row++) { for (int column = 0; column < 12; column++) { Cell cell = gameManager.board.cells[row, column].GetComponent <Cell>(); if (cell.hotelTile != null && cell.hotelTile.GetComponent <HotelTile>().HotelChain != null) { HotelChain hc = cell.hotelTile.GetComponent <HotelTile>().HotelChain; if (hc.Equals(new HotelChain("Arcadia", Color.blue))) { arcadia = hc; } else if (hc.Equals(new HotelChain("Fanfare", Color.green))) { fanfare = hc; } else if (hc.Equals(new HotelChain("Global", Color.gray))) { global = hc; } else if (hc.Equals(new HotelChain("Luster", Color.red))) { luster = hc; } else if (hc.Equals(new HotelChain("Regal", Color.magenta))) { regal = hc; } else if (hc.Equals(new HotelChain("Teton", Color.yellow))) { teton = hc; } else if (hc.Equals(new HotelChain("Nobel", Color.cyan))) { nobel = hc; } } } } if (gameManager.boughtStocks.Count > 0) { if (EventSystem.current.currentSelectedGameObject.name == "btnSubtractArcadiaStock" && arcadia != null && gameManager.boughtStocks.Contains(arcadia.availableStocks[0])) { gameManager.playerTurn.Sell(arcadia, 1); gameManager.boughtStocks.Remove(arcadia.availableStocks[0]); gameManager.buyStocksUI.transform.Find("txtBuyStocks").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = "Buy Stocks"; } else if (EventSystem.current.currentSelectedGameObject.name == "btnSubtractFanFareStock" && fanfare != null && gameManager.boughtStocks.Contains(fanfare.availableStocks[0])) { gameManager.playerTurn.Sell(fanfare, 1); gameManager.boughtStocks.Remove(fanfare.availableStocks[0]); gameManager.buyStocksUI.transform.Find("txtBuyStocks").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = "Buy stocks"; } else if (EventSystem.current.currentSelectedGameObject.name == "btnSubtractGlobalStock" && global != null && gameManager.boughtStocks.Contains(global.availableStocks[0])) { gameManager.playerTurn.Sell(global, 1); gameManager.boughtStocks.Remove(global.availableStocks[0]); gameManager.buyStocksUI.transform.Find("txtBuyStocks").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = "Buy stocks"; } else if (EventSystem.current.currentSelectedGameObject.name == "btnSubtractLusterStock" && luster != null && gameManager.boughtStocks.Contains(luster.availableStocks[0])) { gameManager.playerTurn.Sell(luster, 1); gameManager.boughtStocks.Remove(luster.availableStocks[0]); gameManager.buyStocksUI.transform.Find("txtBuyStocks").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = "Buy stocks"; } else if (EventSystem.current.currentSelectedGameObject.name == "btnSubtractRegalStock" && regal != null && gameManager.boughtStocks.Contains(regal.availableStocks[0])) { gameManager.playerTurn.Sell(regal, 1); gameManager.boughtStocks.Remove(regal.availableStocks[0]); gameManager.buyStocksUI.transform.Find("txtBuyStocks").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = "Buy stocks"; } else if (EventSystem.current.currentSelectedGameObject.name == "btnSubtractNobelStock" && nobel != null && gameManager.boughtStocks.Contains(nobel.availableStocks[0])) { gameManager.playerTurn.Sell(nobel, 1); gameManager.boughtStocks.Remove(nobel.availableStocks[0]); gameManager.buyStocksUI.transform.Find("txtBuyStocks").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = "Buy stocks"; } else if (EventSystem.current.currentSelectedGameObject.name == "btnSubtractTetonStock" && teton != null && gameManager.boughtStocks.Contains(teton.availableStocks[0])) { gameManager.playerTurn.Sell(teton, 1); gameManager.boughtStocks.Remove(teton.availableStocks[0]); gameManager.buyStocksUI.transform.Find("txtBuyStocks").gameObject.GetComponent <TMPro.TextMeshProUGUI>().text = "Buy stocks"; } } gameManager.DisplayChainInfo(); GameObject.Find("lblPlayerBalance").GetComponent <Text>().text = "$" + gameManager.playerTurn.balance; }