Пример #1
0
    public SwapAction(Board board, Vector2Int p1, Vector2Int p2, SwapReason reasonForSwap = SwapReason.Collapse)
        : base(board)
    {
        this.p1 = p1;
        this.p2 = p2;

        this.tile1 = board.GetTile(p1.x, p1.y);
        this.tile2 = board.GetTile(p2.x, p2.y);

        this.swapReason = reasonForSwap;
        // change data
        var previousType1 = board.GetTileType(p1.x, p1.y);
        var previousType2 = board.GetTileType(p2.x, p2.y);

        board.SetTileType(p1.x, p1.y, previousType2);
        board.SetTileType(p2.x, p2.y, previousType1);

        board.SetTile(p2.x, p2.y, tile1);
        board.SetTile(p1.x, p1.y, tile2);

        if (tile1)
        {
            tile1.x = p2.x;
            tile1.y = p2.y;
        }
        if (tile2)
        {
            tile2.x = p1.x;
            tile2.y = p1.y;
        }
    }
Пример #2
0
 public SwapAction(Board board, Tile tile1, Tile tile2, SwapReason swapReason = SwapReason.Collapse) : this(board, tile1.boardPos, tile2.boardPos, swapReason)
 {
 }