public void AddBridgeBuilt() { _bridgesBuilt++; int index = 0; if (_myManager is AICityManager) { index = 1; } Debug.Log(index); GameInitializer.SetBridgeActive(index); if (_bridgesBuilt <= Glob.AmountOfBridgesNeededToWin && _myManager is PlayerCityManager) { GameInitializer.AddSocializerScore(30); } if (_bridgesBuilt >= Glob.AmountOfBridgesNeededToWin) { if (GameInitializer.GetNextCity(this).GetBridgesBuilt() >= Glob.AmountOfBridgesNeededToWin) { GameInitializer.GetCameraManager().MoveCameraTo(new Vector3(53, 6, 19), Glob.CameraBuildingZoomTime); UIHandler.ShowNotification("Through combined efforts, a bridge connecting both cities has been built. The cities are now at peace, and are even thinking of merging to improve the quality of life for everyone."); GameInitializer.EndGame(true); } } }
public void AddMissileLaunched() { _missilesLaunched++; if (_myManager is PlayerCityManager) { AICityManager AICity = GameInitializer.GetNextCity(this).GetManager() as AICityManager; AICity.ChangeAnimosity(50, GameInitializer.GetNextCity(this)); } if (_myManager is PlayerCityManager) { GameInitializer.AddKillerScore(20); } if (_missilesLaunched >= Glob.AmountOfMissilesNeededToWin) { CustomTile targetTile = _tileMap[0, 0]; foreach (CustomTile tile in _tileMap) { if (tile.GetBuildingOnTile() is MissileSilo) { targetTile = tile; break; } } GameInitializer.GetCameraManager().MoveCameraTo(targetTile.transform.position + Glob.CameraBuildingOffset, Glob.CameraBuildingZoomTime); //TODO: Zoom in on a digsite if (_myManager is PlayerCityManager) { UIHandler.ShowNotification("AIton has surrendered! He was too afraid of your firepower and decided to run away, leaving his city and inhabitants behind."); } else { UIHandler.ShowNotification("All of your inhabitants have fled your city after all the bombardments AIton launched at you. You have no choice but to surrender."); } GameInitializer.EndGame(false, this); } }
public override void HandleTurn(City pCity) { if (!_turnEnded) { if (Time.time - _prevBuild >= Glob.AIBuildDelay) { if (_buildings == null) { _buildings = Glob.GetBuildingPrefabs(); } City targetCity = pCity; _prevBuild = Time.time; if (currentMode == CurrentMode.MISSILEAIM) { targetCity = GameInitializer.GetNextCity(pCity); launchMissile(getBestFactory(targetCity)); targetCity = pCity; GameInitializer.GetCameraManager().MoveCameraTo(targetCity.transform.position + Glob.CameraCityOffset, Glob.CameraCitySwitchTime / 2, 4); pCity.AddMissileLaunched(); return; } Move myMove = getMove(pCity, _difficulty, pCity.GetCurrentTurn() * 2); pCity.SetSelectedTile(myMove._tile); //Select the tile pCity.GetSelectedTile().Reset(); GameInitializer.GetBuildingHandler().ChangeBuildingSelection(myMove._building); GameInitializer.GetBuildingHandler().StartBuilding(); if (pCity.GetBudget() < 20 && currentMode != CurrentMode.MISSILEAIM) { _turnEnded = true; _turnEndTime = Time.time; } else if (currentMode == CurrentMode.MISSILEAIM) { targetCity = GameInitializer.GetNextCity(pCity); GameInitializer.GetCameraManager().MoveCameraTo(targetCity.transform.position + Glob.CameraCityOffset, Glob.CameraCitySwitchTime / 2, 4); targetCity.SetSelectedTile(getBestFactory(targetCity)); _prevBuild = Time.time + Glob.AIMissileDelay; } } } else if (Time.time - _turnEndTime >= Glob.AIEndTurnDelay) { GameInitializer.EndTurn(); _turnEnded = false; } }
void Update() { if (GameInitializer.GetBuildingHandler().GetCurrentCity() == this && GameInitializer.GetBuildingHandler().IsReadyToBuild()) { if (!GameInitializer.GetPaused()) { if (_currentTurn > Glob.TurnAmount) { GameInitializer.EndGame(); return; } if (!_collectedThisTurn) { if ((_currentTurn - Glob.EventTurnStart) % Glob.EventTurnInterval == 0 && _myManager is PlayerCityManager && _currentTurn >= Glob.EventTurnStart) { if (!_gotEventThisTurn) { _gotEventThisTurn = true; _eventManager.EnableRandomEvent(); return; } } GameInitializer.GetUIHandler().SetTurnText(_currentTurn); UIHandler.ToggleNotificationPanel(false); CollectFromAllBuildings(); if (_myManager is PlayerCityManager) { AICityManager AICity = GameInitializer.GetNextCity(this).GetManager() as AICityManager; AICity.ChangeAnimosity(-Mathf.RoundToInt(GetHappyHouseAmount() * Glob.HappyHouseAnimosityChange), GameInitializer.GetNextCity(this)); } _collectedThisTurn = true; _gotEventThisTurn = false; _mayorOffice.UpdateHatPosition(_budget); BudgetChange(0); //_uiHandler.SetResourcesBars((int)_budget); //Just in case no buildings collected anything if (_currentTurn >= 6 && _currentTurn <= 8 && _myManager is PlayerCityManager) { switch (_currentTurn) { case 6: int scoreTurn6 = Mathf.Clamp(Glob.OptimalBudgetTurn6 - (int)_budget, 0, 10); GameInitializer.AddAchieverScore(10 - scoreTurn6); break; case 7: int scoreTurn7 = Mathf.Clamp(Glob.OptimalBudgetTurn7 - (int)_budget, 0, 20) / 2; GameInitializer.AddAchieverScore(10 - scoreTurn7); break; case 8: int scoreTurn8 = Mathf.Clamp(Glob.OptimalBudgetTurn8 - (int)_budget, 0, 40) / 4; GameInitializer.AddAchieverScore(10 - scoreTurn8); break; default: break; } } } _myManager.HandleTurn(this); } } else if (_collectedThisTurn) { _collectedThisTurn = false; _currentTurn++; } else if (GameInitializer.GetBuildingHandler().GetCurrentCity() == this && !GameInitializer.GetBuildingHandler().IsReadyToBuild()) { BudgetChange(0); // _uiHandler.SetResourcesBars((int)_budget); //Just in case no buildings collected anything } }
private void handleInput() { if (_currentText != 8) { if (Input.GetKeyDown(Glob.RightButton)) { _myCity.ChangeSelectedTile(CityManager.DirectionKey.RIGHT); } if (Input.GetKeyDown(Glob.LeftButton)) { _myCity.ChangeSelectedTile(CityManager.DirectionKey.LEFT); } if (Input.GetKeyDown(Glob.UpButton)) { _myCity.ChangeSelectedTile(CityManager.DirectionKey.UP); } if (Input.GetKeyDown(Glob.DownButton)) { _myCity.ChangeSelectedTile(CityManager.DirectionKey.DOWN); } } int[] currentTile = _myCity.GetTilePosition(_myCity.GetSelectedTile()); if (_currentText == 1) { if (currentTile[0] == _tileSelectedX && currentTile[1] == _tileSelectedY) { _tileSelected = true; } else { _tileSelected = false; } } else if (_currentText == 3) { if (currentTile[0] == _houseBuiltX && currentTile[1] == _houseBuiltY) { _tileSelected = true; } else { _tileSelected = false; } } else if (_currentText == 6) { if (currentTile[0] == _parkBuiltX && currentTile[1] == _parkBuiltY) { _tileSelected = true; } else { _tileSelected = false; } } else if (_currentText == 8) { if (Input.GetKeyDown(Glob.CancelButton)) //TODO: End turn when Glob.CancelButton is held down 2 sec. { _cancelKeyPressed = Time.time; } else if (Time.time - _cancelKeyPressed >= Glob.EndTurnButtonTime && Input.GetKey(Glob.CancelButton)) { GameInitializer.GetCameraManager().MoveCameraTo(GameInitializer.GetNextCity(_myCity).transform.position + Glob.CameraCityOffset, Glob.CameraCitySwitchTime); _turnEnded = true; _currentText++; UIHandler.ShowNotification(_allText[_currentText]); } /*if (Input.GetKeyDown(KeyCode.Return))//TODO: Correct button * { * GameInitializer.GetCameraManager().MoveCameraTo(GameInitializer.GetNextCity(_myCity).transform.position + Glob.CameraOffset, Glob.CameraCitySwitchTime); * _turnEnded = true; * _currentText++; * UIHandler.ShowNotification(_allText[_currentText]); * }*/ } }
public override void HandleTurn(City pCity) { if (_soundHandler == null) { _soundHandler = GameInitializer.GetSoundHandler(); } City targetCity = pCity; if (currentMode == CurrentMode.MISSILEAIM && _isFocusedOnOwnCity) { targetCity = GameInitializer.GetNextCity(targetCity); GameInitializer.GetCameraManager().MoveCameraTo(targetCity.transform.position + Glob.CameraCityOffset, Glob.CameraCitySwitchTime / 2, 4); _isFocusedOnOwnCity = false; UIHandler.ShowNotification("BOMBS AWAY!"); //TODO: Placeholder text } if (Input.anyKeyDown) { if (!_isFocusedOnOwnCity) { targetCity = GameInitializer.GetNextCity(targetCity); } if (Input.GetKeyDown(Glob.ExamineButton) && currentMode == CurrentMode.SELECTINGTILE) { if (_isFocusedOnOwnCity) { targetCity = GameInitializer.GetNextCity(pCity); GameInitializer.GetCameraManager().MoveCameraTo(targetCity.transform.position + Glob.CameraCityOffset, Glob.CameraCitySwitchTime / 2); _isFocusedOnOwnCity = false; } else { targetCity = pCity; GameInitializer.GetCameraManager().MoveCameraTo(targetCity.transform.position + Glob.CameraCityOffset, Glob.CameraCitySwitchTime / 2); _isFocusedOnOwnCity = true; } } if (currentMode == CurrentMode.SELECTINGTILE || currentMode == CurrentMode.MISSILEAIM) { if (Input.GetKeyDown(Glob.RightButton)) { targetCity.ChangeSelectedTile(DirectionKey.RIGHT); } if (Input.GetKeyDown(Glob.LeftButton)) { targetCity.ChangeSelectedTile(DirectionKey.LEFT); } if (Input.GetKeyDown(Glob.UpButton)) { targetCity.ChangeSelectedTile(DirectionKey.UP); } if (Input.GetKeyDown(Glob.DownButton)) { targetCity.ChangeSelectedTile(DirectionKey.DOWN); } if (Input.GetKeyDown(Glob.ConfirmButton)) { if (targetCity.GetSelectedTile().GetBuildingOnTile() == null) { if (_isFocusedOnOwnCity) { //_soundHandler.PlaySound(SoundHandler.Sounds.CONFIRM); SetCurrentMode(CurrentMode.BUILDINGTILE); targetCity.GetSelectedTile().Reset(); GameInitializer.GetUIHandler().ToggleBuildPanel(true); } } else if (currentMode == CurrentMode.MISSILEAIM) { Debug.Log(GameInitializer.GetCameraManager().isAnimationDone()); if (GameInitializer.GetCameraManager().isAnimationDone()) { Missile missile = Instantiate(Glob.GetMissile()); missile.SetMissileTile(targetCity.GetSelectedTile()); Destroy(targetCity.GetSelectedTile().GetBuildingOnTile().gameObject); targetCity.GetSelectedTile().SetBuilding(null); SetCurrentMode(CurrentMode.SELECTINGTILE); _isFocusedOnOwnCity = true; targetCity = pCity; //AddMissile with sound. GameInitializer.GetCameraManager().MoveCameraTo(targetCity.transform.position + Glob.CameraCityOffset, Glob.CameraCitySwitchTime / 2, 4); pCity.AddMissileLaunched(); } else { Debug.Log("nawh"); } } else { SetCurrentMode(CurrentMode.EXAMINEMODE); GameInitializer.GetUIHandler().SetExamineMode(targetCity.GetSelectedTile().GetBuildingOnTile()); targetCity.GetSelectedTile().Reset(); } } } if (currentMode == CurrentMode.BUILDINGTILE) { //Places a building in placement mode, can switch between buildings. if (GameInitializer.GetBuildingHandler().PlacementBuildingActive()) { if (Input.GetKeyDown(Glob.DownButton) || Input.GetKeyDown(Glob.RightButton)) { //BuildingHandler should probably tell UIHandler what to do. _soundHandler.PlaySound(SoundHandler.Sounds.MOVE); GameInitializer.GetBuildingHandler().ChangeBuildingSelection(1); GameInitializer.GetUIHandler().SetActiveBuildingImage(1); } if (Input.GetKeyDown(Glob.UpButton) || Input.GetKeyDown(Glob.LeftButton)) { _soundHandler.PlaySound(SoundHandler.Sounds.MOVE); GameInitializer.GetBuildingHandler().ChangeBuildingSelection(-1); GameInitializer.GetUIHandler().SetActiveBuildingImage(-1); } if (Input.GetKeyDown(Glob.ConfirmButton)) { if (GameInitializer.GetBuildingHandler().StartBuilding()) { if (currentMode == CurrentMode.BUILDINGTILE)//If nothing changed the current mode { SetCurrentMode(CurrentMode.SELECTINGTILE); } GameInitializer.GetUIHandler().ToggleBuildPanel(false); } else { _soundHandler.PlaySound(SoundHandler.Sounds.ERROR); } } if (Input.GetKeyDown(Glob.CancelButton)) { GameInitializer.GetBuildingHandler().DestroyPlacementBuilding(); SetCurrentMode(CurrentMode.SELECTINGTILE); GameInitializer.GetUIHandler().ToggleBuildPanel(false); } } else { GameInitializer.GetBuildingHandler().ChangeBuildingSelection(0, false); GameInitializer.GetUIHandler().SetActiveBuildingImage(0, false); } } if (currentMode == CurrentMode.EXAMINEMODE) { if (Input.GetKeyDown(Glob.CancelButton)) { GameInitializer.GetUIHandler().ToggleExaminePanel(false); SetCurrentMode(CurrentMode.SELECTINGTILE); } } if (Input.GetKeyDown(Glob.CancelButton) && currentMode != CurrentMode.MISSILEAIM) { _cancelKeyPressed = Time.time; } } if (Time.time - _cancelKeyPressed >= Glob.EndTurnButtonTime && Input.GetKey(Glob.CancelButton)) { GameInitializer.EndTurn(); //Debug.Log(GameInitializer.GetBuildingHandler().GetCurrentCity()); UIHandler.ShowNotification("Turn has ended"); } }