Esempio n. 1
0
    public void AddStates(Puzzle puzzle, PuzzleStateNode parent, PuzzleNode nodeA, PuzzleNode nodeB, bool forward)
    {
        PuzzleState   state = parent.state;
        PuzzleState   next;
        PuzzleElement e = elementNotNull;
        PuzzleElement n = nodeB.elementNotNull;

        foreach (PuzzleItem player in puzzle.GetItemsInNode <PuzzlePlayer> (state, nodeA))
        {
            // Walk
            if (e.CanWalk(puzzle, state, nodeA, nodeB, forward) && n.CanWalk(puzzle, state, nodeA, nodeB, forward))
            {
                next = parent.CloneAndAddChild("Go here", nodeB).state;
                player.SetNode(puzzle, next, nodeB);
            }

            // Take or push ball
            List <PuzzleBall> balls = puzzle.GetItemsInNode <PuzzleBall> (state, nodeA);
            if (balls.Count > 0)
            {
                PuzzleBall ball = balls[0];
                if (e.CanTakeBall(puzzle, state, nodeA, nodeB, forward) && n.CanTakeBall(puzzle, state, nodeA, nodeB, forward))
                {
                    next = parent.CloneAndAddChild("Bring ball here", nodeB).state;
                    player.SetNode(puzzle, next, nodeB);
                    ball.SetNode(puzzle, next, nodeB);
                }
                if (e.CanPushBall(puzzle, state, nodeA, nodeB, forward) && n.CanPushBall(puzzle, state, nodeA, nodeB, forward))
                {
                    next = parent.CloneAndAddChild("Push ball here", nodeB).state;
                    ball.SetNode(puzzle, next, nodeB);
                }
            }

            // Hit toggle at other end
            if (e.CanSee(puzzle, state, nodeA, nodeB, forward) && n.CanSee(puzzle, state, nodeA, nodeB, forward))
            {
                PuzzleToggle toggle = nodeB.element as PuzzleToggle;
                if (toggle != null)
                {
                    next = parent.CloneAndAddChild("Shoot toggle", nodeB).state;
                    nodeB.TriggerToggle(puzzle, next);
                }
            }
        }
    }
Esempio n. 2
0
    public void AddStates(Puzzle puzzle, PuzzleStateNode parent)
    {
        PuzzleState state = parent.state;
        PuzzleState next;

        if (puzzle.GetItemsInNode <PuzzlePlayer> (state, this).Count > 0)
        {
            // Activate toggle
            PuzzleToggle toggle = element as PuzzleToggle;
            if (toggle != null)
            {
                next = parent.CloneAndAddChild("Press toggle", this).state;
                TriggerToggle(puzzle, next);
            }
        }
    }