Exemplo n.º 1
0
    private void Deselect()
    {
        TileField field;
        var       coor   = new Coordinates(m_HighlightedTile);
        var       fields = _fieldProvider.GetField();

        field = fields[coor.up];
        if (field?.IsHighlighting == true)
        {
            field.OnDeselect();
        }

        field = fields[coor.right];
        if (field?.IsHighlighting == true)
        {
            field.OnDeselect();
        }

        field = fields[coor.down];
        if (field?.IsHighlighting == true)
        {
            field.OnDeselect();
        }

        field = fields[coor.left];
        if (field?.IsHighlighting == true)
        {
            field.OnDeselect();
        }

        m_HighlightedTile = null;
    }
Exemplo n.º 2
0
    //TODO: BUG, CHANGE ALGORITHM
    private bool HasVerticalWall(TileField currentField)
    {
        var fields = _fieldProvider.GetField();

        for (int i = 0; i < 5; i++)
        {
            int positiveIndex = currentField.Coordinates.x + i;
            if (positiveIndex <= 4)
            {
                if (!(currentField.Piece.type == fields[positiveIndex, currentField.Coordinates.y].Piece?.type))
                {
                    return(false);
                }
            }

            int negativeIndex = currentField.Coordinates.x - i;
            if (negativeIndex >= 0)
            {
                if (!(currentField.Piece.type == fields[negativeIndex, currentField.Coordinates.y].Piece?.type))
                {
                    return(false);
                }
            }
        }

        return(true);
    }
Exemplo n.º 3
0
    int ICaptureVerifier.VerifyCapture(TileField currentField, Movement movement)
    {
        var kills       = 0;
        var fields      = _fieldProvider.GetField();
        var coordinates = new Coordinates(currentField);

        Coordinates[] coordsToVerify = { coordinates.up, coordinates.right, coordinates.down, coordinates.left };

        for (int i = 0; i < coordsToVerify.Length; i++)
        {
            //Verifying the piece adjacent to the currentField
            //[farTile][inBetweenTile][currentTile]
            var farCoordinates = coordsToVerify[i];
            var inBetweenTile  = fields[coordsToVerify[i]];

            if (currentField.Coordinates.x > coordsToVerify[i].x)
            {
                farCoordinates.x--;
            }
            else if (currentField.Coordinates.x < coordsToVerify[i].x)
            {
                farCoordinates.x++;
            }
            else if (currentField.Coordinates.y < coordsToVerify[i].y)
            {
                farCoordinates.y++;
            }
            else if (currentField.Coordinates.y > coordsToVerify[i].y)
            {
                farCoordinates.y--;
            }

            var farTile = fields[farCoordinates];

            //Verifying the adjacent tile is an enemy
            if (inBetweenTile != null &&
                inBetweenTile.Piece != null &&
                inBetweenTile.Piece.type != currentField.Piece.type)
            {
                //Veryfying if the far tile is an ally
                if (farTile != null &&
                    farTile.Piece != null &&
                    farTile.Piece.type == currentField.Piece.type)
                {
                    //if the inBetweenPiece is on the middle, it can't be captured
                    if (inBetweenTile.Coordinates.x != 2 ||
                        inBetweenTile.Coordinates.y != 2)
                    {
                        inBetweenTile.Capture();
                        kills++;
                    }
                }
            }
        }

        return(kills);
    }
Exemplo n.º 4
0
    void IMovementValidator.Deselect()
    {
        if (_selectedField == null)
        {
            return;
        }

        TileField field;
        var       coor   = new Coordinates(_selectedField);
        var       fields = _fieldProvider.GetField();

        foreach (var dir in coor.cardinal4)
        {
            field = fields[dir];
            if (field != null && field.IsSelected)
            {
                field.OnDeselect();
            }
        }

        _selectedField = null;
    }