Example #1
0
        private void AddNeighborsToWallTiles()
        {
            for (int i = 0; i < myTiles.Length; i++)
            {
                for (int j = 0; j < myTiles[i].Length; j++)
                {
                    WallTile current = myTiles[i][j] as WallTile;

                    if (current != null)
                    {
                        if (WallAt(i - 1, j) && ((myTiles[i - 1][j] as WallTile).Broken == false))
                        {
                            current.AddNeighbor(WallTileNeighbors.North);
                        }

                        if (WallAt(i, j - 1) && ((myTiles[i][j - 1] as WallTile).Broken == false))
                        {
                            current.AddNeighbor(WallTileNeighbors.West);
                        }

                        if (WallAt(i + 1, j) && ((myTiles[i + 1][j] as WallTile).Broken == false))
                        {
                            current.AddNeighbor(WallTileNeighbors.South);
                        }

                        if (WallAt(i, j + 1) && ((myTiles[i][j + 1] as WallTile).Broken == false))
                        {
                            current.AddNeighbor(WallTileNeighbors.East);
                        }
                    }
                }
            }
        }
Example #2
0
        public static void Main(string[] args)
        {
            var playerInput = new PlayerInput();

            var wallTile        = new WallTile();
            var emptyTile       = new EmptyTile();
            var pelletTile      = new PelletTile();
            var tileTypeFactory = new TileTypeFactory(wallTile, emptyTile, pelletTile);

            var ghostTile      = new GhostTile();
            var ghostBehaviour = new RandomGhostBehaviour(ghostTile);

            var pacmanTile      = new PacmanTile();
            var pacmanBehaviour = new PacmanBehaviour(pacmanTile);

            var fileReader        = new FileReader();
            var mazeFactory       = new MazeFactory(fileReader, tileTypeFactory);
            var gameSettingLoader = new GameSettingLoader(fileReader);

            var gameLogicValidator = new GameLogicValidator();
            var gameEngine         = new GameEngine(gameLogicValidator);

            var display       = new Display();
            var spriteFactory = new SpriteFactory();
            var levelFactory  = new LevelFactory(tileTypeFactory, display, spriteFactory, gameLogicValidator, gameEngine, playerInput, pacmanBehaviour, ghostBehaviour);

            var game = new Game(levelFactory, gameSettingLoader, display, mazeFactory, playerInput);

            game.PlayGame();
        }
Example #3
0
        private void RemoveBrokenNeighborsFromWallTiles()
        {
            for (int i = 0; i < myTiles.Length; i++)
            {
                for (int j = 0; j < myTiles[i].Length; j++)
                {
                    WallTile current = myTiles[i][j] as WallTile;

                    if (current != null)
                    {
                        RemoveAdjacentBrokenNeighbors(i, j, current);
                    }
                }
            }
        }
Example #4
0
        private void RemoveAdjacentBrokenNeighbors(int aRow, int aColumn, WallTile aWallTile)
        {
            if (WallAt(aRow - 1, aColumn) && ((myTiles[aRow - 1][aColumn] as WallTile).Broken == true))
            {
                aWallTile.RemoveNeighbor(WallTileNeighbors.North);
            }

            if (WallAt(aRow, aColumn - 1) && ((myTiles[aRow][aColumn - 1] as WallTile).Broken == true))
            {
                aWallTile.RemoveNeighbor(WallTileNeighbors.West);
            }

            if (WallAt(aRow + 1, aColumn) && ((myTiles[aRow + 1][aColumn] as WallTile).Broken == true))
            {
                aWallTile.RemoveNeighbor(WallTileNeighbors.South);
            }

            if (WallAt(aRow, aColumn + 1) && ((myTiles[aRow][aColumn + 1] as WallTile).Broken == true))
            {
                aWallTile.RemoveNeighbor(WallTileNeighbors.East);
            }
        }
Example #5
0
        private void InitializeBoard(List <string> aStrings)
        {
            myTiles = new Tile[aStrings.Count][];
            TeleportTile[] teleportTiles = new TeleportTile[10];

            for (int i = 0; i < aStrings.Count; i++)
            {
                myTiles[i] = new Tile[aStrings[i].Length];

                for (int j = 0; j < aStrings[i].Length; j++)
                {
                    BlankTile current;
                    switch (aStrings[i][j])
                    {
                    case 'w':
                        myTiles[i][j] = new WallTile(j, i);
                        break;

                    case ' ':
                        myTiles[i][j] = new BlankTile(j, i);
                        break;

                    case 'm':
                        myTiles[i][j] = new MapBorderTile(j, i);
                        break;

                    case '0':
                    case '1':
                    case '2':
                    case '3':
                    case '4':
                    case '5':
                    case '6':
                    case '7':
                    case '8':
                    case '9':
                        int serialnumber = int.Parse(aStrings[i][j].ToString());
                        myTiles[i][j] = new TeleportTile(j, i);

                        if (teleportTiles[serialnumber] != null)
                        {
                            teleportTiles[serialnumber].Link(myTiles[i][j] as TeleportTile);
                        }
                        else
                        {
                            teleportTiles[serialnumber] = myTiles[i][j] as TeleportTile;
                        }

                        break;

                    case 'f':
                        myTiles[i][j] = new BlankTile(j, i);
                        current       = myTiles[i][j] as BlankTile;
                        current.AddItem(myItemFactory.GetItem(ItemType.Pellet, myTiles[i][j].Position));
                        break;

                    case 'c':
                        myTiles[i][j] = new BlankTile(j, i);
                        current       = myTiles[i][j] as BlankTile;
                        current.AddItem(myItemFactory.GetItem(ItemType.Cherry, myTiles[i][j].Position));
                        break;

                    case 'k':
                        myTiles[i][j] = new BlankTile(j, i);
                        current       = myTiles[i][j] as BlankTile;
                        current.AddItem(myItemFactory.GetItem(ItemType.Key, myTiles[i][j].Position));
                        break;

                    case 'p':
                        myTiles[i][j] = new BlankTile(j, i);
                        Player.SetSpawnPosition(myTiles[i][j].Position);
                        break;

                    case 'r':
                        myTiles[i][j] = new BlankTile(j, i);
                        myGhosts.Add(myGhostFactory.GetGhost(GhostType.Red, Player, this, myTiles[i][j].Position));
                        myGhosts[myGhosts.Count - 1].SetSpawnPosition(myTiles[i][j].Position);
                        break;

                    case 'v':
                        myTiles[i][j] = new BlankTile(j, i);
                        myGhosts.Add(myGhostFactory.GetGhost(GhostType.Violet, Player, this, myTiles[i][j].Position));
                        myGhosts[myGhosts.Count - 1].SetSpawnPosition(myTiles[i][j].Position);
                        break;

                    case 'b':
                        myTiles[i][j] = new BlankTile(j, i);
                        myGhosts.Add(myGhostFactory.GetGhost(GhostType.Blue, Player, this, myTiles[i][j].Position));
                        myGhosts[myGhosts.Count - 1].SetSpawnPosition(myTiles[i][j].Position);
                        break;

                    case 'o':
                        myTiles[i][j] = new BlankTile(j, i);
                        myGhosts.Add(myGhostFactory.GetGhost(GhostType.Orange, Player, this, myTiles[i][j].Position));
                        myGhosts[myGhosts.Count - 1].SetSpawnPosition(myTiles[i][j].Position);
                        break;
                    }
                }
            }
        }