Example #1
0
    CheckConnectionResult CheckConnection(int x, int z)
    {
        CheckConnectionResult res    = new CheckConnectionResult();
        List <BlockModel>     blocks = res.blocks;
        BlockModel            block  = grid.Get(x, z);

        if (block == null)
        {
            return(res); // no block in the current position
        }
        blocks.Add(block);
        BlockWithDir next = new BlockWithDir(block, block.dir2);

        while ((next = GetNext(next)) != null)
        {
            if (block == next.Block)
            {
                break;
            }
            blocks.Add(next.Block);
        }
        if (next != null)
        {
            res.isLoop = true;
            return(res); // a loop is available
        }
        next = new BlockWithDir(block, block.dir1);
        while ((next = GetNext(next)) != null)
        {
            blocks.Add(next.Block);
        }
        return(res); // no loop available
    }
Example #2
0
    List <BlockModel> CheckConnection(Pos pos)
    {
        List <BlockModel> blocks = new List <BlockModel>();;
        BlockModel        block  = grid.Get(pos.x, pos.z);

        if (block == null)
        {
            return(blocks);
        }

        blocks.Add(block);
        BlockWithDir next = new BlockWithDir(block, block.dir2);

        while ((next = GetNext(next)) != null)
        {
            if (block == next.Block)
            {
                break;
            }
            blocks.Add(next.Block);
        }
        if (next != null)
        {
            return(blocks);
        }
        next = new BlockWithDir(block, block.dir1);
        while ((next = GetNext(next)) != null)
        {
            blocks.Add(next.Block);
        }
        return(blocks);
    }
Example #3
0
    BlockWithDir GetNext(BlockWithDir prev)
    {
        HexDirection dir   = prev.Dir;
        BlockModel   block = prev.Block;
        int          x     = block.x;
        int          z     = block.z;

        if (dir == HexDirection.E)
        {
            x += 1;
        }
        if (dir == HexDirection.W)
        {
            x -= 1;
        }
        if (dir == HexDirection.NE)
        {
            x += (z % 2);
            z += 1;
        }
        if (dir == HexDirection.NW)
        {
            x += (z % 2) - 1;
            z += 1;
        }
        if (dir == HexDirection.SE)
        {
            x += (z % 2);
            z -= 1;
        }
        if (dir == HexDirection.SW)
        {
            x += (z % 2) - 1;
            z -= 1;
        }
        BlockModel next = grid.Get(x, z);

        if (next == null)
        {
            return(null);
        }
        HexDirection opp = dir.Opposite();

        if (next.dir1 == opp)
        {
            return(new BlockWithDir(next, next.dir2));
        }
        if (next.dir2 == opp)
        {
            return(new BlockWithDir(next, next.dir1));
        }
        return(null);
    }
Example #4
0
    BlockWithDir GetNext(BlockWithDir prev)
    {
        HexDirection dir  = prev.Dir;
        Pos          pos  = GetNextPos(new Pos(prev.Block.x, prev.Block.z), dir);
        BlockModel   next = grid.Get(pos.x, pos.z);

        if (next == null)
        {
            return(null);
        }
        HexDirection opp = dir.Opposite();

        if (next.dir1 == opp)
        {
            return(new BlockWithDir(next, next.dir2));
        }
        if (next.dir2 == opp)
        {
            return(new BlockWithDir(next, next.dir1));
        }
        return(null);
    }