//backup data for undo // Use this for initialization void Start() { gamelength = 50; turn = 0; //initializing default game variable values data = new BackgroundData(10000, Random.Range(60, 80), 10000, 3); AverageTemperature = data.Temperature; //lake data.WaterSources[0] = new WaterSource("Lake", 100000, 5000, 1, 1); //aquifer data.WaterSources[1] = new WaterSource("Aquifer", 100000, 5000, 1, 1); //shipments data.WaterSources[2] = new WaterSource("Shipment", 0, 0, 1, 10); //set initial water towers data.CalculateWaterDistributionRate(); //Set Initial Rain Interval and TurnCount RainTurnCount = Random.Range(2, 4); RainInterval = Random.Range(3, 5); AverageRainInterval = RainInterval; //reseting event icons/text WinText.SetActive(false); // Rain.enabled = false; Drought.SetActive(false); Monsoon.SetActive(false); MigrationIn.SetActive(false); MigrationOut.SetActive(false); WarmFront.SetActive(false); ColdFront.SetActive(false); LoseText.SetActive(false); LoseCounterText.text = "Lives: 10"; //buttons Endturn.onClick.AddListener(EndturnListener); LakeReserve.maxValue = data.WaterSources[0].GetReserve(); AquiferReserve.maxValue = data.WaterSources[1].GetReserve(); ShipmentReserve.maxValue = 50000; City.SetLakeMax(100000); City.SetLakeCurrent(LakeReserve.maxValue); WTInvestment.onClick.AddListener(delegate { SetCurrentInvestment(0); }); LKInvestment.onClick.AddListener(delegate { SetCurrentInvestment(1); }); AQInvestment.onClick.AddListener(delegate { SetCurrentInvestment(2); }); Invest1000.onClick.AddListener(delegate { InvestInCurrent(1000); }); Invest2000.onClick.AddListener(delegate { InvestInCurrent(2000); }); Invest5000.onClick.AddListener(delegate { InvestInCurrent(5000); }); WaterShipment.onClick.AddListener(delegate { SetCurrentInvestment(3); }); }
//button listeners private void EndturnListener() { if (turn < gamelength) { if (LoseCounter == 0) { LoseText.SetActive(true); turn = 50; } else if (data.WaterDistributionRate < data.WaterConsumptionRate) { LoseCounter--; LoseCounterText.text = "Lives: " + LoseCounter.ToString(); } data.ExtractWaterSources(); Debug.Log("Lake Reserve: " + data.WaterSources[0].GetReserve() + " Max Reserve: " + 100000); City.SetLakeCurrent(data.WaterSources[0].GetReserve()); if (RainTurnCount == 0) { data.SetEvent(0, Random.Range(10, 20)); RainTurnCount = RainInterval; City.SetRainEnabled(true); } else { City.SetRainEnabled(false); RainTurnCount--; } if (CurrentTempEventTurnCount != 0 && CurrentTempEvent < 2) { if (CurrentTempEvent == 0) { data.SetEvent(1, Random.Range(5, 7)); CurrentTempEventTurnCount--; WarmFront.SetActive(true); ColdFront.SetActive(false); } else if (CurrentTempEvent == 1) { data.SetEvent(2, Random.Range(5, 7)); CurrentTempEventTurnCount--; WarmFront.SetActive(false); ColdFront.SetActive(true); } } else { if (CurrentTempEventTurnCount > 0) { CurrentTempEventTurnCount--; } if (data.Temperature < AverageTemperature) { data.SetEvent(1, Random.Range(3, 5)); } else { data.SetEvent(2, Random.Range(3, 5)); } WarmFront.SetActive(false); ColdFront.SetActive(false); } if (CurrentPopEventTurnCount != 0 && CurrentPopEvent < 2) { if (CurrentPopEvent == 0) { data.SetEvent(3, Random.Range(1000, 5000)); CurrentPopEventTurnCount--; MigrationIn.SetActive(true); MigrationOut.SetActive(false); } else if (CurrentPopEvent == 1) { data.SetEvent(4, Random.Range(1000, 5000)); CurrentPopEventTurnCount--; MigrationIn.SetActive(false); MigrationOut.SetActive(true); } } else { if (CurrentPopEventTurnCount > 0) { CurrentPopEventTurnCount--; } MigrationIn.SetActive(false); MigrationOut.SetActive(false); } if (CurrentRainEventTurnCount != 0 && CurrentRainEvent < 2) { if (CurrentRainEvent == 0) { Drought.SetActive(true); Monsoon.SetActive(false); CurrentRainEventTurnCount--; } else if (CurrentRainEvent == 1) { Drought.SetActive(false); Monsoon.SetActive(true); CurrentRainEventTurnCount--; } } else { if (CurrentRainEventTurnCount > 0) { CurrentRainEventTurnCount--; } Drought.SetActive(false); Monsoon.SetActive(false); } data.IncrementPopulation(10); data.CalculateWaterDistributionRate(); data.IncrementFund(); turn++; GenerateEvents(); Debug.Log("Current Rain Event: " + CurrentRainEvent + ". Turn Count: " + CurrentRainEventTurnCount + "| Current Pop Event: " + CurrentPopEvent + ". Turn Count: " + CurrentPopEventTurnCount + "| Current Temp Event: " + CurrentTempEvent + ". Turn Count: " + CurrentTempEventTurnCount); } else if (turn == gamelength) { WinText.SetActive(true); } }