/// <summary>
        /// Changes the ghost movement to chase.
        /// </summary>
        /// <param name="ghost">Instance of the ghost whose movement
        /// will be changed.</param>
        private void SwitchChaseMode(GameObject ghost)
        {
            MoveComponent moveComponent = ghost.GetComponent <MoveComponent>();

            switch (ghost.Name)
            {
            case "blinky":
                moveComponent.AddMovementBehaviour(
                    new BlinkyChaseBehaviour(
                        ghost,
                        ghost.GetComponent <MapComponent>(),
                        pacman.GetComponent <MapTransformComponent>(),
                        ghost.GetComponent <MapTransformComponent>(),
                        3));
                break;

            case "pinky":
                moveComponent.AddMovementBehaviour(
                    new PinkyChaseBehaviour(
                        pacmanMovementBehaviour,
                        ghost,
                        map,
                        pacman.GetComponent <MapTransformComponent>(),
                        ghost.GetComponent <MapTransformComponent>(),
                        3));
                break;

            case "inky":
                MapTransformComponent blinkyMapTransform =
                    ghosts.FirstOrDefault(g => g.Name == "blinky")?.
                    GetComponent <MapTransformComponent>();

                moveComponent.AddMovementBehaviour(
                    new InkyChaseBehaviour(
                        pacmanMovementBehaviour,
                        map,
                        pacman.GetComponent <MapTransformComponent>(),
                        blinkyMapTransform,
                        ghost,
                        ghost.GetComponent <MapTransformComponent>(),
                        3));
                break;

            case "clyde":
                moveComponent.AddMovementBehaviour(
                    new ClydeChaseBehaviour(
                        pacmanMovementBehaviour,
                        ghost,
                        map,
                        pacman.GetComponent <MapTransformComponent>(),
                        ghost.GetComponent <MapTransformComponent>(),
                        3));
                break;
            }
        }
Example #2
0
 /// <summary>
 /// Constructor, that creates a new instance of
 /// GhostTargetMovementBehaviour and initializes its fields.
 /// </summary>
 /// <param name="ghost">Instance of the ghost to be moved.</param>
 /// <param name="map">Map in which the gameobjects are placed.</param>
 /// <param name="mapTransform"><see cref="MapTransformComponent"/>
 /// for the ghost.</param>
 /// <param name="translateModifier">Value to be a compensation of the
 /// map stretch when printed.</param>
 protected GhostTargetMovementBehaviour(
     GameObject ghost,
     MapComponent map,
     MapTransformComponent mapTransform,
     int translateModifier = 1)
 {
     this.ghost             = ghost;
     ghostTransform         = ghost.GetComponent <TransformComponent>();
     this.mapTransform      = mapTransform;
     this.translateModifier = translateModifier;
     this.map = map;
 }
 /// <summary>
 /// Constructor, that creates a new instance of PacmanMovementBehaviour
 /// and initializes its fields.
 /// </summary>
 /// <param name="pacman">Instance of pacman.</param>
 /// <param name="mapTransform"><see cref="MapTransformComponent"/>
 /// of pacman.</param>
 /// <param name="translateModifier">Value to be a compensation of the
 /// map stretch when printed.</param>
 public PacmanMovementBehaviour(
     GameObject pacman,
     MapTransformComponent mapTransform,
     int translateModifier = 1)
 {
     keyReader         = pacman.GetComponent <KeyReaderComponent>();
     transform         = pacman.GetComponent <TransformComponent>();
     this.mapTransform = mapTransform;
     map = pacman.GetComponent <MapComponent>();
     this.translateModifier = translateModifier;
     previousDirection      = Direction.None;
 }
 /// <summary>
 /// Constructor, that creates a new instance of
 /// ScatterMovementBehaviour and initializes its fields.
 /// </summary>
 /// <param name="ghost">Instance of the ghost to be moved.</param>
 /// <param name="map">Map in which the gameobjects are placed.</param>
 /// <param name="targetMapTransform">
 /// <see cref="MapTransformComponent"/> for the target to
 /// be chased.</param>
 /// <param name="mapTransform"><see cref="MapTransformComponent"/>
 /// for the ghost.</param>
 /// <param name="translateModifier">Value to be a compensation of the
 /// map stretch when printed.</param>
 public ScatterMovementBehaviour(
     GameObject ghost,
     MapComponent map,
     MapTransformComponent targetMapTransform,
     MapTransformComponent mapTransform,
     int translateModifier = 1)
     : base(
         ghost,
         map,
         mapTransform,
         translateModifier)
 {
     this.targetMapTransform = targetMapTransform;
 }
Example #5
0
 /// <summary>
 /// Constructor, that creates a new instance of PinkyChaseBehaviour
 /// and initializes its fields.
 /// </summary>
 /// <param name="targetMovementBehaviour">Movement behaviour for
 /// the target.</param>
 /// <param name="ghost">Instance of the ghost to be moved.</param>
 /// <param name="map">Map in which the gameobjects are placed.</param>
 /// <param name="targetMapTransform">
 /// <see cref="MapTransformComponent"/> for the target to
 /// be chased.</param>
 /// <param name="mapTransform"><see cref="MapTransformComponent"/>
 /// for the ghost.</param>
 /// <param name="translateModifier">Value to be a compensation of the
 /// map stretch when printed.</param>
 public PinkyChaseBehaviour(
     PacmanMovementBehaviour targetMovementBehaviour,
     GameObject ghost,
     MapComponent map,
     MapTransformComponent targetMapTransform,
     MapTransformComponent mapTransform,
     int translateModifier = 1)
     : base(
         ghost,
         map,
         mapTransform,
         translateModifier)
 {
     this.targetMovementBehaviour = targetMovementBehaviour;
     this.targetMapTransform      = targetMapTransform;
 }
Example #6
0
 /// <summary>
 /// Constructor, that creates a new instance of
 /// FrightenedMovementBehaviour and initializes its fields.
 /// </summary>
 /// <param name="ghost">Instance of the ghost to be moved.</param>
 /// <param name="map">Map in which the gameobjects are placed.</param>
 /// <param name="targetMapTransform">
 /// <see cref="MapTransformComponent"/> for the target to
 /// be chased.</param>
 /// <param name="mapTransform"><see cref="MapTransformComponent"/>
 /// for the ghost.</param>
 /// <param name="random">Instance of a pseudo-random number
 /// generator.</param>
 /// <param name="translateModifier">Value to be a compensation of the
 /// map stretch when printed.</param>
 public FrightenedMovementBehaviour(
     GameObject ghost,
     MapComponent map,
     MapTransformComponent targetMapTransform,
     MapTransformComponent mapTransform,
     Random random,
     int translateModifier = 1)
     : base(
         ghost,
         map,
         mapTransform,
         translateModifier)
 {
     this.map    = map;
     this.random = random;
 }
        /// <summary>
        /// Changes the ghost movement to frightened.
        /// </summary>
        /// <param name="ghost">Instance of the ghost whose movement
        /// will be changed.</param>
        private void SwitchFrightenedMode(GameObject ghost)
        {
            MoveComponent moveComponent =
                ghost.GetComponent <MoveComponent>();

            MapTransformComponent ghostMapTransform =
                ghost.GetComponent <MapTransformComponent>();

            moveComponent.AddMovementBehaviour(
                new FrightenedMovementBehaviour(
                    ghost,
                    map,
                    new MapTransformComponent(
                        1, 1),
                    ghostMapTransform,
                    random,
                    3));
        }
Example #8
0
 /// <summary>
 /// Constructor, that creates a new instance of InkyChaseBehaviour
 /// and initializes its fields.
 /// </summary>
 /// <param name="targetMovementBehaviour">Movement behaviour for
 /// the target.</param>
 /// <param name="map">Map in which the gameobjects are placed.</param>
 /// <param name="targetMapTransform">
 /// <see cref="MapTransformComponent"/> for the target to
 /// be chased.</param>
 /// <param name="blinkyMapTransform">
 /// <see cref="MapTransformComponent"/> for the ghost Blinky.</param>
 /// <param name="inky">Instance of the ghost to be moved.</param>
 /// <param name="mapTransform"><see cref="MapTransformComponent"/>
 /// for the ghost.</param>
 /// <param name="translateModifier">Value to be a compensation of the
 /// map stretch when printed.</param>
 public InkyChaseBehaviour(
     PacmanMovementBehaviour targetMovementBehaviour,
     MapComponent map,
     MapTransformComponent targetMapTransform,
     MapTransformComponent blinkyMapTransform,
     GameObject inky,
     MapTransformComponent mapTransform,
     int translateModifier = 1)
     : base(
         inky,
         map,
         mapTransform,
         translateModifier)
 {
     this.targetMapTransform      = targetMapTransform;
     this.targetMovementBehaviour = targetMovementBehaviour;
     this.blinkyMapTransform      = blinkyMapTransform;
 }
        /// <summary>
        /// Inverts the direction to which the ghost is currently pointed.
        /// </summary>
        /// <param name="ghost">Instance of the ghost whose direction
        /// will be changed.</param>
        private void InvertGhostDirection(GameObject ghost)
        {
            MapTransformComponent tempMapTrans =
                ghost.GetComponent <MapTransformComponent>();

            switch (tempMapTrans.Direction)
            {
            case Direction.Down:
                tempMapTrans.Direction = Direction.Up;
                break;

            case Direction.Up:
                tempMapTrans.Direction = Direction.Down;
                break;

            case Direction.Left:
                tempMapTrans.Direction = Direction.Right;
                break;

            case Direction.Right:
                tempMapTrans.Direction = Direction.Left;
                break;
            }
        }