Пример #1
0
    private void ValidateNextPosition(BoardPosition position)
    {
        bool add    = false;
        bool exists = BoardManager.PositionExists(position);

        if (exists)
        {
            UnitPiece existing = UnitManager.GetUnitPieceForPosition(position);
            if (!existing.Equals(UnitPiece.UNKNOWN))
            {
                bool owner = false;
                if (GameManager.CurrentMode.Equals(GameMode.PlayerOne))
                {
                    owner = existing.Owner.Equals(GameManager.PlayerOne);
                }
                else if (GameManager.CurrentMode.Equals(GameMode.PlayerTwo))
                {
                    owner = existing.Owner.Equals(GameManager.PlayerTwo);
                }
                if (!owner)
                {
                    //We're not the owner
                    add = true;
                }
            }
            else
            {
                // Unoccupied space
                add = true;
            }
        }
        if (add)
        {
            validPositions.Add(position);
        }
    }
Пример #2
0
    private void HandleGame(RaycastHit[] hits, bool selectable, BoardPosition position, UnitPiece unit, Vector3 tileVector)
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (hits.Length == 0)
            {
                highlightCube.SetActive(false);
                previous = position;
            }
            else if (selectable && !unit.Equals(UnitPiece.UNKNOWN))
            {
                //We've selected a unit
                //Check if we're the owner
                bool owner = false;
                if (GameManager.CurrentMode.Equals(GameMode.PlayerOne))
                {
                    owner = unit.Owner.Equals(GameManager.PlayerOne);
                }
                else if (GameManager.CurrentMode.Equals(GameMode.PlayerTwo))
                {
                    owner = unit.Owner.Equals(GameManager.PlayerTwo);
                }

                if (owner)
                {
                    //If the previous position was off the board, this is our first selection
                    if (previous.Equals(BoardPosition.OFF_BOARD))
                    {
                        previous = position;
                        MoveHighlight(tileVector);

                        //Determine what the valid next positions are
                        ClearValid();
                        //Add current position, for deselection
                        validPositions.Add(position);
                        ValidateNextPosition(new BoardPosition(position.X - 1, position.Y));
                        ValidateNextPosition(new BoardPosition(position.X, position.Y - 1));
                        ValidateNextPosition(new BoardPosition(position.X + 1, position.Y));
                        ValidateNextPosition(new BoardPosition(position.X, position.Y + 1));
                        MoveValid();
                    }
                    else if (previous.Equals(position))
                    {
                        //We selected the same space, deselect
                        previous = BoardPosition.OFF_BOARD;
                        highlightCube.SetActive(false);
                        ClearValid();
                    }
                }
                else if (validPositions.Contains(position))
                {
                    //If our previous position contains a piece that we own, then we should do battle
                    UnitPiece previousPiece = UnitManager.GetUnitPieceForPosition(previous);
                    if (!previousPiece.Equals(UnitPiece.UNKNOWN))
                    {
                        bool previousOwner = false;
                        if (GameManager.CurrentMode.Equals(GameMode.PlayerOne))
                        {
                            previousOwner = previousPiece.Owner.Equals(GameManager.PlayerOne);
                        }
                        else if (GameManager.CurrentMode.Equals(GameMode.PlayerTwo))
                        {
                            previousOwner = previousPiece.Owner.Equals(GameManager.PlayerTwo);
                        }

                        if (previousOwner)
                        {
                            // instigate attack, with previous piece as attacker and current piece as defender
                            GameManager.HandleBattle(previousPiece, previous, unit, position);
                            previous = BoardPosition.OFF_BOARD;
                            highlightCube.SetActive(false);
                            ClearValid();
                        }
                    }
                }
            }
            else if (selectable && !position.Equals(BoardPosition.OFF_BOARD) && !previous.Equals(BoardPosition.OFF_BOARD))
            {
                //We've selected a place not off the board, the previous position was not off the board either, but there is no piece occupying the space
                if(validPositions.Contains(position))
                {
                    //Move the piece
                    UnitManager.MovePiece(previous, position);
                    ClearValid();
                    highlightCube.SetActive(false);
                    action = true;
                }
            }
        }
        else if (Input.GetMouseButtonDown(1))
        {
            //Just clear selection
            previous = BoardPosition.OFF_BOARD;
            highlightCube.SetActive(false);
            ClearValid();
        }
    }
Пример #3
0
    private void HandleGame(RaycastHit[] hits, bool selectable, BoardPosition position, UnitPiece unit, Vector3 tileVector)
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (hits.Length == 0)
            {
                highlightCube.SetActive(false);
                previous = position;
            }
            else if (selectable && !unit.Equals(UnitPiece.UNKNOWN))
            {
                //We've selected a unit
                //Check if we're the owner
                bool owner = false;
                if (GameManager.CurrentMode.Equals(GameMode.PlayerOne))
                {
                    owner = unit.Owner.Equals(GameManager.PlayerOne);
                }
                else if (GameManager.CurrentMode.Equals(GameMode.PlayerTwo))
                {
                    owner = unit.Owner.Equals(GameManager.PlayerTwo);
                }

                if (owner)
                {
                    //If the previous position was off the board, this is our first selection
                    if (previous.Equals(BoardPosition.OFF_BOARD))
                    {
                        previous = position;
                        MoveHighlight(tileVector);

                        //Determine what the valid next positions are
                        ClearValid();
                        //Add current position, for deselection
                        validPositions.Add(position);
                        ValidateNextPosition(new BoardPosition(position.X - 1, position.Y));
                        ValidateNextPosition(new BoardPosition(position.X, position.Y - 1));
                        ValidateNextPosition(new BoardPosition(position.X + 1, position.Y));
                        ValidateNextPosition(new BoardPosition(position.X, position.Y + 1));
                        MoveValid();
                    }
                    else if (previous.Equals(position))
                    {
                        //We selected the same space, deselect
                        previous = BoardPosition.OFF_BOARD;
                        highlightCube.SetActive(false);
                        ClearValid();
                    }
                }
                else if (validPositions.Contains(position))
                {
                    //If our previous position contains a piece that we own, then we should do battle
                    UnitPiece previousPiece = UnitManager.GetUnitPieceForPosition(previous);
                    if (!previousPiece.Equals(UnitPiece.UNKNOWN))
                    {
                        bool previousOwner = false;
                        if (GameManager.CurrentMode.Equals(GameMode.PlayerOne))
                        {
                            previousOwner = previousPiece.Owner.Equals(GameManager.PlayerOne);
                        }
                        else if (GameManager.CurrentMode.Equals(GameMode.PlayerTwo))
                        {
                            previousOwner = previousPiece.Owner.Equals(GameManager.PlayerTwo);
                        }

                        if (previousOwner)
                        {
                            // instigate attack, with previous piece as attacker and current piece as defender
                            GameManager.HandleBattle(previousPiece, previous, unit, position);
                            previous = BoardPosition.OFF_BOARD;
                            highlightCube.SetActive(false);
                            ClearValid();
                        }
                    }
                }
            }
            else if (selectable && !position.Equals(BoardPosition.OFF_BOARD) && !previous.Equals(BoardPosition.OFF_BOARD))
            {
                //We've selected a place not off the board, the previous position was not off the board either, but there is no piece occupying the space
                if (validPositions.Contains(position))
                {
                    //Move the piece
                    UnitManager.MovePiece(previous, position);
                    ClearValid();
                    highlightCube.SetActive(false);
                    action = true;
                }
            }
        }
        else if (Input.GetMouseButtonDown(1))
        {
            //Just clear selection
            previous = BoardPosition.OFF_BOARD;
            highlightCube.SetActive(false);
            ClearValid();
        }
    }