示例#1
0
    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;
        }
    }
示例#2
0
    private void DrawMap(Vector3 startPos)
    {
        _tileMap = new CustomTile[Rows, Columns];
        for (int row = 0; row < Rows; row++)
        {
            for (int col = 0; col < Columns; col++)
            {
                CustomTile tile = Instantiate(TilePrefab);
                tile.SetCity(this);
                tile.transform.position = startPos + new Vector3((row * tile.transform.localScale.x) + row * OffSetBetweenTiles, 0, (tile.transform.localScale.z * col) + col * OffSetBetweenTiles);
                tile.transform.parent   = this.transform;
                _tileMap[row, col]      = tile;
            }
        }

        CustomTile targetTile4 = _tileMap[5, 4];

        GameInitializer.GetBuildingHandler().QuickBuildBuilding(this, targetTile4, 7);

        _sign       = Instantiate(_signPrefab);
        _budgetText = _sign.GetComponentInChildren <Text>();
        BudgetChange(0);
        _sign.transform.parent = this.transform;

        if (_myManager is AICityManager)
        {
            _sign.transform.position = new Vector3(_sign.transform.position.x + Glob.CitySpacing, _sign.transform.position.y, _sign.transform.position.z);
            CustomTile targetTile1 = _tileMap[3, 4];
            GameInitializer.GetBuildingHandler().QuickBuildBuilding(this, targetTile1, 0);

            CustomTile targetTile2 = _tileMap[3, 3];
            GameInitializer.GetBuildingHandler().QuickBuildBuilding(this, targetTile2, 1);

            CustomTile targetTile3 = _tileMap[4, 4];
            GameInitializer.GetBuildingHandler().QuickBuildBuilding(this, targetTile3, 2);

            _budget = 10;
        }

        //Sets first tile to active.
        _selectedTile = GetTileAtPosition(0, 0);
    }
示例#3
0
    public void HandleChoice(int choice)
    {
        Choice chc = _currentEvent.choices[choice];

        effectBox.SetActive(true);
        string repercussionCostText = chc.repercussion.cost.ToString();

        if (chc.repercussion.cost < 0)
        {
            repercussionCostText = "+" + (-chc.repercussion.cost);
        }
        effectText.text = chc.repercussion.description + "\nCost: " + repercussionCostText;

        GameInitializer.GetBuildingHandler().GetCurrentCity().ReceiveCollection(-(chc.cost + chc.repercussion.cost));

        GameInitializer.AddAchieverScore(chc.achieverValue);
        GameInitializer.AddExplorerScore(chc.explorerValue);
        GameInitializer.AddKillerScore(chc.killerValue);
        GameInitializer.AddSocializerScore(chc.socializerValue);
    }
示例#4
0
    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
        }
    }
示例#5
0
    // Update is called once per frame
    void Update()
    {
        if (_tutorialActive)
        {
            if (Input.GetKeyDown(Glob.ConfirmButton))
            {
                if (_currentText == 1 && !_tileSelected || _currentText == 3 && !_tileSelected || _currentText == 6 && !_tileSelected || _currentText == 8 && !_turnEnded) //If the player needs to select the correct tile first.
                {
                    return;
                }
                else if (_currentText == 3 && _tileSelected && !_houseBuilt)
                {
                    GameInitializer.GetUIHandler().ToggleBuildPanel(true);
                    GameInitializer.GetBuildingHandler().ChangeBuildingSelection(0, false);
                    GameInitializer.GetUIHandler().SetActiveBuildingImage(0, false);
                    GameInitializer.GetBuildingHandler().PlaceBuilding(_myCity.GetSelectedTile());
                    _houseBuilt = true;
                    return;
                }
                else if (_currentText == 6 && _tileSelected && !_parkBuilt)
                {
                    GameInitializer.GetUIHandler().ToggleBuildPanel(true);
                    GameInitializer.GetBuildingHandler().ChangeBuildingSelection(2, false);
                    GameInitializer.GetUIHandler().SetActiveBuildingImage(2, false);
                    GameInitializer.GetBuildingHandler().PlaceBuilding(_myCity.GetSelectedTile());
                    _parkBuilt = true;
                    return;
                }

                _tileSelected = false;


                _currentText++;


                if (_currentText == 1)
                {
                    _myCity.HighlightTile(_tileSelectedX, _tileSelectedY, true); //TODO: Remove highlight after action.
                }
                else if (_currentText == 2)
                {
                    _myCity.HighlightTile(_tileSelectedX, _tileSelectedY, false);
                    GameInitializer.GetUIHandler().ToggleBuildPanel(true);
                    GameInitializer.GetBuildingHandler().ChangeBuildingSelection(1, false);
                    GameInitializer.GetUIHandler().SetActiveBuildingImage(1, false);
                    GameInitializer.GetBuildingHandler().PlaceBuilding(_myCity.GetSelectedTile());
                }
                else if (_currentText == 3)
                {
                    GameInitializer.GetBuildingHandler().StartBuilding();
                    GameInitializer.GetUIHandler().ToggleBuildPanel(false);

                    _myCity.HighlightTile(_houseBuiltX, _houseBuiltY, true);
                }
                else if (_currentText == 4)
                {
                    _myCity.HighlightTile(_houseBuiltX, _houseBuiltY, false);
                    GameInitializer.GetBuildingHandler().StartBuilding();
                    GameInitializer.GetUIHandler().ToggleBuildPanel(false);
                }
                else if (_currentText == 6)
                {
                    _myCity.HighlightTile(_parkBuiltX, _parkBuiltY, true);
                }
                else if (_currentText == 7)
                {
                    _myCity.HighlightTile(_parkBuiltX, _parkBuiltY, false);
                    GameInitializer.GetBuildingHandler().StartBuilding();
                    GameInitializer.GetUIHandler().ToggleBuildPanel(false);
                }
                else if (_currentText == 10)
                {
                    _myCity.CollectFromAllBuildings();
                    _myCity.ChangeSelectedTile(CityManager.DirectionKey.DOWN);
                    _myCity.BudgetChange(0);
                    //GameInitializer.GetUIHandler().SetResourcesBars((int)_myCity.GetBudget());

                    GameInitializer.GetCameraManager().MoveCameraTo(_myCity.transform.position + Glob.CameraCityOffset, Glob.CameraCitySwitchTime);
                }
                else if (_currentText == 11)
                {
                    GameInitializer.GetUIHandler().ToggleBuildPanel(true);
                    GameInitializer.GetBuildingHandler().ChangeBuildingSelection(3, false);
                    GameInitializer.GetUIHandler().SetActiveBuildingImage(3, false);
                    GameInitializer.GetBuildingHandler().PlaceBuilding(_myCity.GetSelectedTile());
                }
                else if (_currentText == 12)
                {
                    GameInitializer.GetBuildingHandler().ChangeBuildingSelection(5, false);
                    GameInitializer.GetUIHandler().SetActiveBuildingImage(5, false);
                    GameInitializer.GetBuildingHandler().PlaceBuilding(_myCity.GetSelectedTile());
                }
                else if (_currentText == 13)
                {
                    GameInitializer.GetBuildingHandler().ChangeBuildingSelection(6, false);
                    GameInitializer.GetUIHandler().SetActiveBuildingImage(6, false);
                    GameInitializer.GetBuildingHandler().PlaceBuilding(_myCity.GetSelectedTile());
                }
                else if (_currentText == 14)
                {
                    GameInitializer.GetBuildingHandler().ChangeBuildingSelection(4, false);
                    GameInitializer.GetUIHandler().SetActiveBuildingImage(4, false);
                    GameInitializer.GetBuildingHandler().PlaceBuilding(_myCity.GetSelectedTile());
                }
                else if (_currentText == 17)
                {
                    GameInitializer.GetBuildingHandler().DestroyPlacementBuilding();
                    GameInitializer.GetUIHandler().ToggleBuildPanel(false);
                    //GameInitializer.SetPaused(false);
                    //_tutorialActive = false;
                }
                else if (_currentText >= 18)
                {
                    //GameInitializer.GetBuildingHandler().DestroyPlacementBuilding();
                    //GameInitializer.GetUIHandler().ToggleBuildPanel(false);
                    GameInitializer.SetPaused(false);
                    _tutorialActive = false;
                    return;
                }

                UIHandler.ShowNotification(_allText[_currentText]);//Display the new information.
            }
            if (_currentText == 1 || _currentText == 3 && !_houseBuilt || _currentText == 6 && !_parkBuilt || _currentText == 8 && !_turnEnded)
            {
                handleInput();
            }
        }
    }
示例#6
0
    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");
        }
    }