Example #1
0
        private int[] NextCellCoords(Direction direction, IPacman being)
        {
            var newPacmanRow = being.Row;
            var newPacmanCol = being.Column;

            switch (direction)
            {
            case Direction.Down:
                newPacmanRow++;
                break;

            case Direction.Up:
                newPacmanRow--;
                break;

            case Direction.Left:
                newPacmanCol--;
                break;

            case Direction.Right:
                newPacmanCol++;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(new[] { newPacmanRow, newPacmanCol });
        }
Example #2
0
 public Scene(IWindow window, ISceneHeader sceneHeader, IPacman pacman, IGhost[] ghosts)
 {
     this.Window      = window;
     this.SceneHeader = sceneHeader;
     this.Pacman      = pacman;
     this.Ghosts      = ghosts;
 }
Example #3
0
 public Enemy(int row, int cell, int pacmanCatchPause, IMaze maze, IPacman pacman, IPursueAlgo pursueAlgo) : base(row, cell, maze)
 {
     Pacman                  = pacman ?? throw new ArgumentNullException("Pacman");
     PursueAlgo              = pursueAlgo ?? throw new ArgumentNullException("PursueAlgo");
     _pacmanCatchPause       = pacmanCatchPause;
     Pacman.PacmenStepEvent += new PacmenStep(PacmanSteps);
     Pacman.PacmenCatch     += new EventHandler(PacmanCatch);
     worker                  = new BackgroundWorker();
     worker.DoWork          += EnemiesStoped;
 }
Example #4
0
        public void EnemyService_PacmanNull_ArgumentNullException()
        {
            IPacman pacman = null;

            try
            {
                EnemyService = new EnemyService(Count, Maze.Object, pacman, TimeService);
            }
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual("Pacman", ex.ParamName);
            }
        }
Example #5
0
 public Board(IPacman pacman, int totalRows, int totalCols)
 {
     Pacman = pacman;
     Ghost  = new Ghost(Direction.Up);
     if (totalRows < 1 || totalCols < 1)
     {
         throw new ArgumentException(Constants.Constants.ExceptionForRowsAndCols);
     }
     _totalRows = totalRows;
     _totalCols = totalCols;
     Cells      = new ICell[totalRows, totalCols];
     SetUpCells();
 }
Example #6
0
        private Vector GetRandomEnemyPos(IPacman pacman, IMaze maze, double dontNear)
        {
            int    index;
            bool   finded = false;
            Vector pos    = new Vector();

            while (!finded)
            {
                index = random.Next(0, maze.Paths.Count());                                                     //random path index
                var ramdomPos = maze.Paths.ElementAt(index);
                if ((Math.Abs(pacman.Row - ramdomPos.Row) + Math.Abs(pacman.Cell - ramdomPos.Cell)) > dontNear) //but not near the pacman
                {
                    finded = true;
                    pos.X  = ramdomPos.Row;
                    pos.Y  = ramdomPos.Cell;
                }
            }
            return(pos);
        }
Example #7
0
        public EnemyService(int countEnemies, IMaze maze, IPacman pacman, TimeService timeService)
        {
            if (countEnemies < 1)
            {
                throw new ArgumentException("Count Enemies can't be less 1");
            }
            maze        = maze ?? throw new ArgumentNullException("Maze");
            pacman      = pacman ?? throw new ArgumentNullException("Pacman");
            timeService = timeService ?? throw new ArgumentNullException("TimeService");

            ListEnemies = new List <IEnemy>();

            for (int i = 0; i < countEnemies; i++)
            {
                var pos   = GetRandomEnemyPos(pacman, maze, (maze.Height + maze.Width) / 2);
                var enemy = LayerService.Container.Resolve <IEnemy>(
                    new NamedParameter(GameConstants.NamedParameterRow, pos.X),
                    new NamedParameter(GameConstants.NamedParameterCell, pos.Y),
                    new NamedParameter(GameConstants.NamedParameterPacmanCatchPause, GameConstants.PacmanCatchPause)
                    );
                timeService.StepEvent += new TimeService.TimeToStep(enemy.Step);
                ListEnemies.Add(enemy);
            }
        }
        public void PrintBoard(ICell[,] cells, IPacman pacman, int level, int lives)
        {
            Console.Clear();
            Console.Write($"{Constants.Level} {level}   |   ");
            Console.Write($"{Constants.Lives} {lives} \n");

            var stringBuilder = new StringBuilder();

            for (var row = 0; row < cells.GetLength(0); row++)
            {
                for (var col = 0; col < cells.GetLength(1); col++)
                {
                    var state = cells[row, col].State;
                    switch (state)
                    {
                    case State.Empty:
                        stringBuilder.Append(Constants.EmptyCell);
                        break;

                    case State.Food:
                        stringBuilder.Append(Constants.FoodCell);
                        break;

                    case State.Wall:
                        stringBuilder.Append(Constants.Wall);
                        break;

                    case State.Pacman:
                        switch (pacman.Direction)
                        {
                        case Direction.Up:
                            stringBuilder.Append(Constants.PacmanUp);
                            break;

                        case Direction.Down:
                            stringBuilder.Append(Constants.PacmanDown);
                            break;

                        case Direction.Left:
                            stringBuilder.Append(Constants.PacmanLeft);
                            break;

                        case Direction.Right:
                            stringBuilder.Append(Constants.PacmanRight);
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }

                        break;

                    case State.Ghost:
                        stringBuilder.Append(Constants.Ghost);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }

                stringBuilder.Append(Constants.NewLine);
            }

            Console.WriteLine(stringBuilder.ToString());
        }
Example #9
0
        public bool CanTheyMoveThisDirection(Direction direction, IPacman being)
        {
            var coord = NextCellCoords(direction, being);

            return(Cells[coord[0], coord[1]].State != State.Wall);
        }
Example #10
0
        public void InitializeCharacters()
        {
            switch (GameMode)
            {
                case GameModeType.Cheat:
                    Pacman = CreateCheatPacman();
                    break;
                default:
                    Pacman = CreateCommonPacman();
                    break;
            }

            Enemies = new List<Enemy>()
            {
               CreateEnemy(new Point(220, 203), new Point(220, 203), Color.FromArgb(255, 0, 0), Direction.Left),
               CreateEnemy(new Point(205, 203), new Point(205, 203), Color.FromArgb(255, 184, 71), Direction.Right)
            };

            Pellets = new Pellet();
            GameLevel = new GameLevel();
            GenerateCharacters();
        }