Exemple #1
0
        //public void Execute(Ghost aGhost)
        //{
        //    if (aGhost.Player.PowerUp == PowerUpType.GhostEater)
        //    {
        //        aGhost.ChangeState(new SScared());
        //    }

        //    if (aGhost.CollisionWithPlayer())
        //    {
        //        aGhost.Player.GotEaten();
        //    }
        //}

        public void Execute(Ghost aGhost)
        {
            if (aGhost.CollisionWithPlayer())
            {
                aGhost.Player.GotEaten();
            }

            aGhost.FrameYIndex = aGhost.DEFAULT_FRAME_Y_INDEX;
            switch (aGhost.Direction)
            {
            case Direction.Up:
                aGhost.FrameXIndex = aGhost.FrameXIndex != 4 ? 4 : 5;
                break;

            case Direction.Left:
                aGhost.FrameXIndex = aGhost.FrameXIndex != 2 ? 2 : 3;
                break;

            case Direction.Down:
                aGhost.FrameXIndex = aGhost.FrameXIndex != 6 ? 6 : 7;
                break;

            case Direction.Right:
                aGhost.FrameXIndex = aGhost.FrameXIndex != 0 ? 0 : 1;
                break;
            }
        }
Exemple #2
0
        public BinaryDecisionTree(Ghost aGhost)
        {
            ///               Not Dead
            ///              /         \
            ///            No           Yes
            ///           /               \
            ///     Is in spawn?      Pacman powered up?
            ///      /     \               /         \
            ///     No      Yes           No          Yes
            ///     /         \           /             \
            /// [SDead]    [SAlive]  [SAlive]     Collides with pacman?
            ///                                        /      \
            ///                                       No      Yes
            ///                                       /         \
            ///                                  [SScared]     [SDead]

            myRoot = new BranchNode(() => aGhost.CurrentBehaviour is SDead == false,
                                    new BranchNode(() => aGhost.Position == aGhost.SpawnPosition,
                                                   new LeafNode(new SDead()),
                                                   new LeafNode(new SAlive())),

                                    new BranchNode(() => aGhost.Player.PowerUp == PowerUpType.GhostEater,
                                                   new LeafNode(new SAlive()),
                                                   new BranchNode(() => aGhost.CollisionWithPlayer(),
                                                                  new LeafNode(new SScared()),
                                                                  new LeafNode(new SDead()))));
        }