Example #1
0
    // Start is called before the first frame update
    void Start()
    {
        int siblingIndex = transform.GetSiblingIndex();

        for (int i = 0; i < PuzzleBlocks.Length; i++)
        {
            PipePuzzleBlock block = PuzzleBlocks[i].GetComponent <PipePuzzleBlock>();
            block.RelatedPuzzle = this;
            Blocks[i % 4, (int)Mathf.Floor(i / 4)] = block;
        }

        Blocks[0, 0].SetType(BlockType.Start);
        Blocks[3, 3].SetType(BlockType.End);

        foreach (PipePuzzleBlock block in Empty)
        {
            block.SetType(BlockType.Empty);
        }

        foreach (PipePuzzleBlock block in AlwaysEmpty)
        {
            block.SetType(BlockType.AlwaysEmpty);
        }

        int originalSeed = Random.seed;

        for (int i = 0; i < 2; i++)
        {
            Random.seed = originalSeed + siblingIndex + i;
            PossibleObstacles[Random.Range(0, PossibleObstacles.Length)].SetType(BlockType.Obstacle);
        }
        Random.seed = originalSeed;
    }
Example #2
0
    public void DetachPipe()
    {
        if (AttachedBlock)
        {
            AttachedBlock.DetachPipe();
        }

        AttachedBlock  = null;
        Placed         = false;
        rb.isKinematic = false;
    }
 public void FillSafely(PipePuzzleBlock block, Side side, Side neighbourSide, int neighbourBlockIndex)
 {
     if (block.IsSideAccessible (side)) {
         PipePuzzleBlock neighbourBlock = blocks [neighbourBlockIndex];
         if (!water [neighbourBlockIndex]) {
             if (neighbourBlock.IsSideAccessible (neighbourSide)) {
                 FillPipeRecursively (neighbourBlock);
             }
         }
     }
 }
 public void FillSafely(PipePuzzleBlock block, Side side, Side neighbourSide, int neighbourBlockIndex)
 {
     if (block.IsSideAccessible(side))
     {
         PipePuzzleBlock neighbourBlock = blocks [neighbourBlockIndex];
         if (!water [neighbourBlockIndex])
         {
             if (neighbourBlock.IsSideAccessible(neighbourSide))
             {
                 FillPipeRecursively(neighbourBlock);
             }
         }
     }
 }
    public void FillPipeRecursively(PipePuzzleBlock block)
    {
        int i = block.myI;
        int j = block.myJ;

        int index = j * size + i;
        water [index] = true;
        block.renderer.material.color = Color.blue;

        FillSafely (block, Side.Up, Side.Bottom, (j - 1) * size + i);
        FillSafely (block, Side.Bottom, Side.Up, (j + 1) * size + i);
        FillSafely (block, Side.Right, Side.Left, j * size + i + 1);
        FillSafely (block, Side.Left, Side.Right, j * size + i - 1);
    }
    public void FillPipeRecursively(PipePuzzleBlock block)
    {
        int i = block.myI;
        int j = block.myJ;

        int index = j * size + i;

        water [index] = true;
        block.renderer.material.color = Color.blue;

        FillSafely(block, Side.Up, Side.Bottom, (j - 1) * size + i);
        FillSafely(block, Side.Bottom, Side.Up, (j + 1) * size + i);
        FillSafely(block, Side.Right, Side.Left, j * size + i + 1);
        FillSafely(block, Side.Left, Side.Right, j * size + i - 1);
    }
Example #7
0
    public void CheckCompletion()
    {
        Side previousExit = Side.Down;
        bool keepChecking = true;
        bool win          = false;

        int[] lastCell = new int[] { 0, 0 };
        while (keepChecking)
        {
            int[] nextCell = GetNextCell(lastCell, previousExit);

            if (nextCell[0] == 3 && nextCell[1] == 3)
            {
                win          = true;
                keepChecking = false;
                break;
            }
            PipePuzzleBlock block    = Blocks[nextCell[0], nextCell[1]];
            Side            required = PipePuzzleBlock.GetOpposite(previousExit);
            bool            match    = block.Sides.IndexOf(required) > -1;
            if (match)
            {
                previousExit = block.Sides.Find(item => item != required);
                lastCell     = nextCell;
                keepChecking = true;
            }
            else
            {
                keepChecking = false;
            }
        }
        if (win)
        {
            foreach (PipePuzzleBlock block in Blocks)
            {
                if (block.PipeObject)
                {
                    block.PipeObject.GetComponent <BoxCollider>().enabled = false;
                }
            }
            redLight.GetComponent <MeshRenderer>().material = greenMat;
            Solved();
        }
    }
Example #8
0
 public void PlacePipe(PipePuzzleBlock block)
 {
     AttachedBlock  = block;
     Placed         = true;
     rb.isKinematic = true;
 }