예제 #1
0
        public void StartStrategy(IAlgorythm algorythm, IPacMan pacMan, IMaze maze, IGhost ghost, Position start)
        {
            algorythm.From.X = ghost._position.X;
            algorythm.From.Y = ghost._position.Y;
            algorythm.To.X   = start.X;
            algorythm.To.Y   = start.Y;

            algorythm.Execute();
            List <Location> route = algorythm.ResultPath;

            foreach (var step in route.ToList())
            {
                if (ghost._position.X + 1 == step.X)
                {
                    ghost.direction = SidesToMove.Right;
                }

                if (ghost._position.X - 1 == step.X)
                {
                    ghost.direction = SidesToMove.Left;
                }

                if (ghost._position.Y - 1 == step.Y)
                {
                    ghost.direction = SidesToMove.Up;
                }

                if (ghost._position.Y + 1 == step.Y)
                {
                    ghost.direction = SidesToMove.Down;
                }
            }
        }
예제 #2
0
 public Handler(IGameStats gameStats, IGameSoundPlayer gameSoundPlayer, IPacMan pacman, IMediator mediator)
 {
     _gameStats       = gameStats;
     _gameSoundPlayer = gameSoundPlayer;
     _pacman          = pacman;
     _mediator        = mediator;
 }
예제 #3
0
 public Blinky(IGameStats gameStats, IMediator mediator, IMaze maze, IPacMan pacman, IHumanInterfaceParser input) : base(
         gameStats,
         mediator,
         input,
         pacman,
         GhostNickname.Blinky,
         maze,
예제 #4
0
    public Fruit(IMediator mediator, IPacMan pacman)
    {
        _mediator = mediator;
        _pacman   = pacman;

        reset();
    }
예제 #5
0
        public void StartStrategy(IAlgorythm algorythm, IPacMan pacMan, IMaze maze, IGhost ghost, Position start)
        {
            algorythm.From.X = ghost._position.X;
            algorythm.From.Y = ghost._position.Y;
            algorythm.To.X   = maze.BottomRightCorner.X;
            algorythm.To.Y   = maze.BottomRightCorner.Y;
            algorythm.Execute();
            List <Location> rightCornerBottom = algorythm.ResultPath;

            foreach (var i in rightCornerBottom)
            {
                if (ghost._position.X + 1 == i.X)
                {
                    ghost.direction = SidesToMove.Right;
                }

                else if (ghost._position.X - 1 == i.X)
                {
                    ghost.direction = SidesToMove.Left;
                }

                else if (ghost._position.Y - 1 == i.Y)
                {
                    ghost.direction = SidesToMove.Up;
                }

                else if (ghost._position.Y + 1 == i.Y)
                {
                    ghost.direction = SidesToMove.Down;
                }
            }
        }
예제 #6
0
 public Handler(IMediator mediator, IGame game, IGameSoundPlayer gameSoundPlayer, IPacMan pacman, IGhostCollection ghostCollection)
 {
     _mediator        = mediator;
     _game            = game;
     _gameSoundPlayer = gameSoundPlayer;
     _pacman          = pacman;
     _ghostCollection = ghostCollection;
 }
예제 #7
0
 public PacManDyingAct(IMediator mediator, IGhostCollection ghostCollection, IGameSoundPlayer gameSoundPlayer, IPacMan pacman, IMaze maze)
 {
     _mediator        = mediator;
     _ghostCollection = ghostCollection;
     _gameSoundPlayer = gameSoundPlayer;
     _pacman          = pacman;
     _maze            = maze;
 }
예제 #8
0
 public LevelFinishedAct(IMediator mediator, IGhostCollection ghostCollection, IPacMan pacman, IMaze maze)
 {
     _mediator        = mediator;
     _ghostCollection = ghostCollection;
     _pacman          = pacman;
     _maze            = maze;
     _step            = 0;
 }
예제 #9
0
 public Collision(Pinky pinky, Blinky blinky, Inky inky, Clyde clyde, IPacMan pacMan, GUI gui)
 {
     this.gui = gui;
     pacman   = pacMan;
     ghosts.Add(pinky);
     ghosts.Add(inky);
     ghosts.Add(blinky);
     ghosts.Add(clyde);
 }
예제 #10
0
        public void StartStrategy(IAlgorythm algorythm, IPacMan pacMan, IMaze maze, IGhost ghost, Position Start)
        {
            algorythm.From.X = ghost._position.X;
            algorythm.From.Y = ghost._position.Y;
            if (pacMan.direction == SidesToMove.Down)
            {
                algorythm.To.X = pacMan._position.X + 2;
                algorythm.To.Y = pacMan._position.Y - 2;
            }
            if (pacMan.direction == SidesToMove.Up)
            {
                algorythm.To.X = pacMan._position.X + 2;
                algorythm.To.Y = pacMan._position.Y + 2;
            }
            if (pacMan.direction == SidesToMove.Left)
            {
                algorythm.To.X = pacMan._position.X - 2;
                algorythm.To.Y = pacMan._position.Y - 2;
            }
            if (pacMan.direction == SidesToMove.Right)
            {
                algorythm.To.X = pacMan._position.X + 2;
                algorythm.To.Y = pacMan._position.Y - 2;
            }


            algorythm.Execute();
            List <Location> dir = algorythm.ResultPath;

            foreach (var i in dir.ToList())
            {
                if (i != null)
                {
                    if (ghost._position.X + 1 == i.X)
                    {
                        ghost.direction = SidesToMove.Right;
                    }

                    else if (ghost._position.X - 1 == i.X)
                    {
                        ghost.direction = SidesToMove.Left;
                    }

                    else if (ghost._position.Y - 1 == i.Y)
                    {
                        ghost.direction = SidesToMove.Up;
                    }

                    else if (ghost._position.Y + 1 == i.Y)
                    {
                        ghost.direction = SidesToMove.Down;
                    }
                }
            }
        }
예제 #11
0
 public Pinky(IGameStats gameStats, IMediator mediator, IMaze maze, IPacMan pacman, IHumanInterfaceParser input) : base(
         gameStats,
         mediator,
         input,
         pacman,
         GhostNickname.Pinky, maze, Tile.FromCell(15.5f, 11f), GameComponents.Direction.Down)
 {
     _maze       = maze;
     _pacman     = pacman;
     HouseOffset = 0;
 }
예제 #12
0
 public DemoPlayerIntroAct(IMediator mediator,
                           IGame game,
                           IGhostCollection ghostCollection,
                           IPacMan pacman,
                           IMaze maze)
 {
     _mediator        = mediator;
     _game            = game;
     _ghostCollection = ghostCollection;
     _pacman          = pacman;
     _maze            = maze;
 }
예제 #13
0
        public Clyde(IGameStats gameStats, IMediator mediator, IMaze maze, IPacMan pacman, IHumanInterfaceParser input) :
            base(
                gameStats,
                mediator,
                input,
                pacman,
                GhostNickname.Clyde, maze, new Vector2(11.5f, 12), GameComponents.Directions.Up)
        {
            _maze   = maze;
            _pacman = pacman;

            HouseOffset = 1;
        }
예제 #14
0
        public Inky(IGameStats gameStats, IMediator mediator, IMaze maze, IPacMan pacman, IHumanInterfaceParser input) :
            base(
                gameStats,
                mediator,
                input,
                pacman,
                GhostNickname.Inky, maze, Tile.FromCell(15.5f, 11), GameComponents.Directions.Up)
        {
            _mediator   = mediator;
            _maze       = maze;
            _pacman     = pacman;
            HouseOffset = -1;

            _getBlinkyRequest = new GetBlinkyRequest();
        }
예제 #15
0
 public Blinky(IGameStats gameStats, IMediator mediator, IMaze maze, IPacMan pacman, IHumanInterfaceParser input) :
     base(
         gameStats,
         mediator,
         input,
         pacman,
         GhostNickname.Blinky,
         maze,
         new Vector2(13.5f, 11),
         GameComponents.Directions.Left)
 {
     _pacman        = pacman;
     HouseOffset    = 0;
     _scatterTarget = new ValueTask <CellIndex>(new CellIndex(25, 0));
 }
예제 #16
0
 public PlayerIntroAct(IMediator mediator,
                       IGhostCollection ghostCollection,
                       IGameStats gameStats,
                       IGameSoundPlayer gameSoundPlayer,
                       IPacMan pacman,
                       IMaze maze,
                       IGame game)
 {
     _mediator        = mediator;
     _ghostCollection = ghostCollection;
     _gameStats       = gameStats;
     _gameSoundPlayer = gameSoundPlayer;
     _pacman          = pacman;
     _maze            = maze;
     _game            = game;
 }
예제 #17
0
 public Game(
     IMediator mediator,
     IFruit fruit,
     IStatusPanel statusPanel,
     IScorePanel scorePanel,
     IGameSoundPlayer gameSoundPlayer,
     IHumanInterfaceParser input,
     IPacMan pacman)
 {
     _mediator        = mediator;
     _fruit           = fruit;
     _statusPanel     = statusPanel;
     _scorePanel      = scorePanel;
     _gameSoundPlayer = gameSoundPlayer;
     _input           = input;
     _pacman          = pacman;
 }
예제 #18
0
 public DemoAct(
     IMediator mediator,
     IFruit fruit,
     IMaze maze,
     IPacMan pacman,
     IGhostCollection ghostCollection,
     IHumanInterfaceParser input,
     IGameStats gameStats)
 {
     _mediator        = mediator;
     _fruit           = fruit;
     _maze            = maze;
     _pacman          = pacman;
     _ghostCollection = ghostCollection;
     _input           = input;
     _gameStats       = gameStats;
 }
예제 #19
0
 public Handler(IGhostCollection ghostCollection,
                IFruit fruit,
                IMaze maze,
                IPacMan pacman,
                IGame game,
                IActs acts,
                IGameStats gameStats,
                IHaveTheMazeCanvases mazeCanvases)
 {
     _mazeCanvases    = mazeCanvases;
     _ghostCollection = ghostCollection;
     _fruit           = fruit;
     _maze            = maze;
     _pacman          = pacman;
     _game            = game;
     _acts            = acts;
     _gameStats       = gameStats;
 }
예제 #20
0
 protected Ghost(
     IGameStats gameStats,
     IMediator mediator,
     IHumanInterfaceParser input,
     IPacMan pacman,
     GhostNickname nickName,
     IMaze maze,
     Vector2 startingPoint,
     Direction startingDirection) : base(nickName, startingDirection)
 {
     _gameStats         = gameStats;
     _mediator          = mediator;
     _input             = input;
     _maze              = maze;
     _pacman            = pacman;
     _startingPoint     = startingPoint;
     _startingDirection = startingDirection;
     Tile = new();
 }
예제 #21
0
 public GameAct(
     ICoinBox coinBox,
     IMediator mediator,
     IHumanInterfaceParser input,
     IGameSoundPlayer gameSoundPlayer,
     IGameStats gameStats,
     IGhostCollection ghostCollection,
     IMaze maze,
     IPacMan pacman,
     IFruit fruit)
 {
     _coinBox         = coinBox;
     _mediator        = mediator;
     _input           = input;
     _gameSoundPlayer = gameSoundPlayer;
     _gameStats       = gameStats;
     _ghostCollection = ghostCollection;
     _maze            = maze;
     _pacman          = pacman;
     _fruit           = fruit;
 }
예제 #22
0
        // =============================================

        void OnCreatePacMan(int x, int y)
        {
            Vector2 position = PositionManager.GetPosition(x, y);

            _pacMan = CharactersFactory.CreatePacMan(_gameObjectsParent, position);
        }
예제 #23
0
 public AStar(IGhost ghost, IPacMan pacMan, IMaze map)
 {
     this.ghost  = ghost;
     this.pacMan = pacMan;
     this.map    = map;
 }
예제 #24
0
        public void StartStrategy(IAlgorythm algorythm, IPacMan pacMan, IMaze maze, IGhost ghost, Position start)
        {
            Random random = new Random();
            string dir    = random.Next(1, 4).ToString();

            if (maze.Map[ghost._position.Y - 1, ghost._position.X] == maze.Wall && maze.Map[ghost._position.Y, ghost._position.X - 1] == maze.Wall)
            {
                if (ghost.prevDirection == SidesToMove.Up)
                {
                    dir = "1";
                }
                if (ghost.prevDirection == SidesToMove.Left)
                {
                    dir = "4";
                }
            }

            if (maze.Map[ghost._position.Y + 1, ghost._position.X] == maze.Wall && maze.Map[ghost._position.Y, ghost._position.X - 1] == maze.Wall)
            {
                if (ghost.prevDirection == SidesToMove.Down)
                {
                    dir = "1";
                }
                if (ghost.prevDirection == SidesToMove.Left)
                {
                    dir = "3";
                }
            }

            if (maze.Map[ghost._position.Y - 1, ghost._position.X] == maze.Wall && maze.Map[ghost._position.Y, ghost._position.X + 1] == maze.Wall)
            {
                if (ghost.prevDirection == SidesToMove.Up)
                {
                    dir = "2";
                }

                if (ghost.prevDirection == SidesToMove.Right)
                {
                    dir = "4";
                }
            }

            if (maze.Map[ghost._position.Y + 1, ghost._position.X] == maze.Wall && maze.Map[ghost._position.Y, ghost._position.X + 1] == maze.Wall)
            {
                if (ghost.prevDirection == SidesToMove.Down)
                {
                    dir = "2";
                }
                if (ghost.prevDirection == SidesToMove.Right)
                {
                    dir = "3";
                }
            }


            if (maze.Map[ghost._position.Y - 1, ghost._position.X] != maze.Wall && maze.Map[ghost._position.Y, ghost._position.X + 1] != maze.Wall && maze.Map[ghost._position.Y, ghost._position.X - 1] != maze.Wall)
            {
                if (ghost.prevDirection == SidesToMove.Left)
                {
                    dir = "3";
                }
                if (ghost.prevDirection == SidesToMove.Right)
                {
                    dir = "4";
                }
            }
            if (maze.Map[ghost._position.Y - 1, ghost._position.X] != maze.Wall && maze.Map[ghost._position.Y + 1, ghost._position.X] != maze.Wall && maze.Map[ghost._position.Y, ghost._position.X - 1] != maze.Wall)
            {
                if (ghost.prevDirection == SidesToMove.Right)
                {
                    dir = "4";
                }
                if (ghost.prevDirection == SidesToMove.Down)
                {
                    dir = "2";
                }
            }

            if (maze.Map[ghost._position.Y, ghost._position.X + 1] != maze.Wall && maze.Map[ghost._position.Y + 1, ghost._position.X] != maze.Wall && maze.Map[ghost._position.Y, ghost._position.X - 1] != maze.Wall)
            {
                if (ghost.prevDirection == SidesToMove.Up)
                {
                    dir = "1";
                }
            }

            switch (dir)
            {
            case "1":
                if (maze.Map[ghost._position.Y, ghost._position.X + 1] != maze.Wall)
                {
                    if (ghost.prevDirection != SidesToMove.Left)
                    {
                        ghost.direction = SidesToMove.Right;
                    }
                }
                break;

            case "2":
                if (maze.Map[ghost._position.Y, ghost._position.X - 1] != maze.Wall)
                {
                    if (ghost.prevDirection != SidesToMove.Right)
                    {
                        ghost.direction = SidesToMove.Left;
                    }
                }
                break;

            case "3":
                if (maze.Map[ghost._position.Y - 1, ghost._position.X] != maze.Wall)
                {
                    if (ghost.prevDirection != SidesToMove.Down)
                    {
                        ghost.direction = SidesToMove.Up;
                    }
                }
                break;

            case "4":
                if (maze.Map[ghost._position.Y + 1, ghost._position.X] != maze.Wall)
                {
                    if (ghost.prevDirection != SidesToMove.Up)
                    {
                        ghost.direction = SidesToMove.Down;
                    }
                }
                break;
            }
        }
예제 #25
0
        public void Execute(IGhost ghost, IPacMan pacMan, IMaze map)
        {
            if (pacMan.Position.X != target.X || pacMan.Position.Y != target.Y)
            {
                ResultPath.Clear();
                current = null;
                openList.Clear();
                closedList.Clear();
                g = 0;

                target.X = pacMan.Position.X;
                target.Y = pacMan.Position.Y;
                start.X  = ghost.Position.X;
                start.Y  = ghost.Position.Y;
            }

            openList.Add(start);

            while (openList.Count > 0)
            {
                var lowest = openList.Min(l => l.F);
                current = openList.First(l => l.F == lowest);
                closedList.Add(current);
                openList.Remove(current);
                if (closedList.FirstOrDefault(l => l.X == target.X && l.Y == target.Y) != null)
                {
                    break;
                }
                var adjacentSquares
                    = GetWalkableAdjacentSquares(current.X, current.Y, map.Map);
                g++;

                foreach (var adjacentSquare in adjacentSquares)
                {
                    if (closedList.FirstOrDefault(l => l.X == adjacentSquare.X &&
                                                  l.Y == adjacentSquare.Y) != null)
                    {
                        continue;
                    }

                    if (openList.FirstOrDefault(l => l.X == adjacentSquare.X &&
                                                l.Y == adjacentSquare.Y) == null)
                    {
                        adjacentSquare.G      = g;
                        adjacentSquare.H      = ComputeHScore(adjacentSquare.X, adjacentSquare.Y, target.X, target.Y);
                        adjacentSquare.F      = adjacentSquare.G + adjacentSquare.H;
                        adjacentSquare.Parent = current;
                        openList.Insert(0, adjacentSquare);
                    }
                    else
                    {
                        if (g + adjacentSquare.H < adjacentSquare.F)
                        {
                            adjacentSquare.G      = g;
                            adjacentSquare.F      = adjacentSquare.G + adjacentSquare.H;
                            adjacentSquare.Parent = current;
                        }
                    }
                }
            }


            while (current != null)
            {
                if (pacMan.Position.X == target.X || pacMan.Position.Y == target.Y)
                {
                    ResultPath.Add(current);
                    current = current.Parent;
                }
                else
                {
                    break;
                }
            }

            ResultPath.Reverse();
        }