Beispiel #1
0
    private void Awake() {
        grid = new GameGridCell[Width, Height];

        Vector2 topLeftPos;

        // Start spawning from top left
        if(Width % 2 == 0) {
            topLeftPos.x = (CellSize * (float)(-Width / 2)) + (CellSize / 2f);
        } else {
            topLeftPos.x = CellSize * Mathf.Floor(-Width / 2);
        }
        if(Height % 2 == 0) {
            topLeftPos.y = (CellSize * (float)(-Height / 2)) + (CellSize / 2f);
        } else {
            topLeftPos.y = CellSize * Mathf.Floor(-Height / 2);
        }

        for(int y = 0; y < Height; y++) {
            for(int x = 0; x < Width; x++) {
                Vector2 spawnPos = new Vector2(topLeftPos.x + CellSize * x, topLeftPos.y + CellSize * y);

                GameGridCell newCell = new GameGridCell(spawnPos, new Vector2Int(x, y));
                grid[x, y] = newCell;
            }
        }
    }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        var selected = Grid.SelectedCell;
        var pointed = Grid.PointedCell;

        if (State == TurnState.SelectFigure)
        {
            if (selected != null && Players[PlayerTurn].Figures.Contains(selected.GetComponentInChildren<GameUnit>()))
            {
                lastSelected = selected;
                State = TurnState.SelectMoveTo;
            }
            //GameGridCell.
        }

        if (State == TurnState.SelectMoveTo)
        {
            if (selected == null)
            {
                if (lastNotErrorPointed == null)
                    State = TurnState.SelectFigure;
                else
                {
                    State = TurnState.Moving;
                    var gameUnit = lastSelected.GetComponentInChildren<GameUnit>();
                    var gameUnitOnDestination = lastNotErrorPointed.GetComponentInChildren<GameUnit>();

                    bool moveOnDestination = gameUnitOnDestination == null;
                    if (gameUnitOnDestination != null)
                    {
                        gameUnit.CooperateWith(gameUnitOnDestination);
                        if (gameUnitOnDestination.Deffence <= 0)
                        {
                            DestroyUnit(gameUnitOnDestination);
                            moveOnDestination = true;
                        }
                        else
                        {

                            gameUnitOnDestination.FeedbackTo(gameUnit);
                            gameUnit.Deffence = gameUnit.Deffence - gameUnitOnDestination.Attack;
                            if (gameUnit.Deffence <= 0)
                                DestroyUnit(gameUnit);
                            moveOnDestination = false;
                        }

                    }

                    var gameBonusOnDestination = lastNotErrorPointed.GetComponentInChildren<GameBonus>();
                    if (gameBonusOnDestination != null)
                    {

                        gameBonusOnDestination.FeedbackTo(gameUnit);
                        if (gameUnit.Deffence <= 0)
                            DestroyUnit(gameUnit);
                        DestroyBonus(gameBonusOnDestination);
                        moveOnDestination = true;
                    }

                    if (moveOnDestination)
                    {
                        gameUnit.transform.parent = lastNotErrorPointed.transform;
                        gameUnit.transform.localPosition = Vector3.zero;
                    }

                    State = TurnState.EndTurn;
                    lastNotErrorPointed = null;
                    lastSelected = null;
                }
            }
            else
            if (pointed != null)
            {
                pointed.IsError = !selected.Neiborhoods.Contains(pointed);
                if (!pointed.IsError)
                    lastNotErrorPointed = pointed;
                else
                    lastNotErrorPointed = null;
            }
        }

        if ( State == TurnState.EndTurn)
        {
            PlayerTurn = 1 - PlayerTurn;
            State = TurnState.SelectFigure;
            UpdateFigures();
        }
    }