Beispiel #1
0
    private void Flow(int x, int y, DirectionState dir, int val)
    {
        Debug.Log("Flow starting...");
        GameObject startObj = _grid[x, y];
        Tube       tube     = startObj.GetComponent <Tube>();

        // If no tube found in the start spot, game over
        if (tube == null)
        {
            GameOver();
            return;
        }
        // If the tube in the start spot is facing the wrong way, game over
        TubeSideData[] sides        = tube.GetSides();
        bool           inputCorrect = false;

        for (int i = 0; i < sides.Length; i++)
        {
            if (sides[i].Direction == dir && (sides[i].State == InputOutputState.Input || sides[i].State == InputOutputState.Both))
            {
                inputCorrect = true;
            }
        }
        if (!inputCorrect)
        {
            GameOver();
            return;
        }

        tube.FlowStart(dir, val, OperationState.None);
    }
Beispiel #2
0
    public override void FlowToNext()
    {
        bool done = false;

        foreach (TubeSideData flowOut in _sides)
        {
            if (!done && (flowOut.State == InputOutputState.Both || flowOut.State == InputOutputState.Output) && NotInputSide(flowOut.Direction))
            {
                //get next grid tile in the valid tile's direction.
                bool           valid  = false;
                DirectionState flowTo = DirectionState.West;
                byte           newX   = xCord;
                byte           newY   = yCord;
                Debug.Log(newY);

                switch (flowOut.Direction)
                {
                case DirectionState.North:
                    flowTo = DirectionState.South;
                    newY--;
                    break;

                case DirectionState.South:
                    flowTo = DirectionState.North;
                    newY++;
                    break;

                case DirectionState.East:
                    flowTo = DirectionState.West;
                    newX++;
                    break;

                case DirectionState.West:
                    flowTo = DirectionState.East;
                    newX--;
                    break;

                default:
                    Debug.Log("It's all on fire...");
                    break;
                }

                //Coordinate validation and validation of input flow.
                GameObject[,] grid = manager.GetGrid();
                Tube nextTube = null;
                if ((newX >= 0 && newX < grid.GetLength(0)) && (newY >= 0 && newY < grid.GetLength(1)))
                {
                    nextTube = grid[newX, newY].GetComponent <Tube>();
                    if (nextTube != null)
                    {
                        Debug.Log("Should be here.");
                        Debug.Log("Target: " + flowTo);
                        TubeSideData[] sides = nextTube.GetSides();
                        for (int i = 0; i < sides.Length; i++)
                        {
                            Debug.Log(sides[i].Direction);
                            Debug.Log(sides[i].State);
                            if (sides[i].Direction == flowTo && (sides[i].State != InputOutputState.Output && sides[i].State != InputOutputState.None))
                            {
                                valid = true;
                            }
                        }
                    }
                }


                //If there is no tile or correct input side, end the game as our player has failed us (yet again).
                if (valid == false)
                {
                    Debug.Log("Game sucks.");
                    if (manager.CheckWinState(xCord, yCord, flowOut.Direction, _outValue))
                    {
                        manager.GameWin();
                    }
                    else
                    {
                        manager.GameOver();
                    }
                }
                else
                {
                    //start the flow on that tile if a proper input/both side is connected. (Out=North, then In=South, etc.)
                    nextTube.FlowStart(flowTo, _outValue, _operation);
                    done = true;
                }
            }
        }
    }