Exemplo n.º 1
0
        static void Main(string[] args)
        {
            MazeFactory mazeFact = new MazeFactory(20, 32);

            MazeSolverFactory bfsSolverFact = new MazeSolverFactory(WayToSolve.BFS);
            MazeSolverFactory dfsSolverFact = new MazeSolverFactory(WayToSolve.BFS);

            WallBreakerFactory dfsWBreakerFact
                = new WallBreakerFactory(WallBreakerFactory.BreakingType.DFS);
            WallBreakerFactory randomPrimWBreakerFact
                = new WallBreakerFactory(WallBreakerFactory.BreakingType.Random);

            Console.WriteLine("Randomized DFS Generated Maze :");
            IMaze mazeDfs = mazeFact.GetMaze(dfsWBreakerFact);

            Console.WriteLine(mazeDfs.ToString());

            Console.WriteLine("\n\nRandomized DFS Maze Solution is :");
            mazeDfs.SolveMaze(new MazeSolverFactory(WayToSolve.DFS));
            Console.WriteLine(mazeDfs.SolutionToString());

            Console.WriteLine("\n\nRandomized Prim Generated Maze :");
            IMaze mazePrim = mazeFact.GetMaze(randomPrimWBreakerFact);

            Console.WriteLine(mazePrim.ToString());

            Console.WriteLine("\n\nRandomized Prim Maze Solution is :");
            mazePrim.SolveMaze(new MazeSolverFactory(WayToSolve.BFS));
            Console.WriteLine(mazePrim.SolutionToString());

            Console.ReadLine();
        }
Exemplo n.º 2
0
        public async Task BuildMaze_FromJson_MazeCreatedCorrectly()
        {
            Guid mazeId = Guid.NewGuid();
            Mock <IPonyAPIClient> mockPonyAPI = new Mock <IPonyAPIClient>();

            mockPonyAPI.Setup(p => p.GetMaze(mazeId)).ReturnsAsync(
                new HttpResponseMessage
            {
                StatusCode = System.Net.HttpStatusCode.OK,
                Content    = new StringContent(mazeJson, Encoding.UTF8, "application/json")
            });

            mazeFactory = new MazeFactory(mockPonyAPI.Object);

            Maze maze = await mazeFactory.FromID(mazeId);

            mockPonyAPI.Verify(p => p.GetMaze(mazeId), Times.Once);
            Assert.IsNotNull(maze);
            Assert.AreEqual(mazeId, maze.MazeId);
            Assert.AreEqual(15, maze.Width);
            Assert.AreEqual(15, maze.Height);
            Assert.AreEqual(15 * 15, maze.Tiles.Length);
            Assert.AreEqual(new Point(5, 4), maze.Pony.Position);
            Assert.AreEqual(new Point(10, 4), maze.Domokun.Position);
            Assert.AreEqual(new Point(14, 10), maze.EndPoint);
            Assert.AreEqual(new Point(0, 1), maze.Tiles[0, 0].AccessibleTiles.First());
            Assert.Contains(new Point(2, 0), maze.Tiles[3, 0].AccessibleTiles);
            Assert.Contains(new Point(4, 0), maze.Tiles[3, 0].AccessibleTiles);
            Assert.Contains(new Point(3, 1), maze.Tiles[3, 0].AccessibleTiles);
            Assert.Contains(new Point(0, 0), maze.Tiles[0, 1].AccessibleTiles);
            Assert.IsFalse(maze.Tiles[1, 0].AccessibleTiles.Contains(new Point(1, -1)));
            Assert.IsFalse(maze.Tiles[14, 10].AccessibleTiles.Contains(new Point(15, 10)));
        }
Exemplo n.º 3
0
        public async Task BuildMaze_New_ApiCalled()
        {
            Guid mazeId = Guid.NewGuid();
            Mock <IPonyAPIClient> mockPonyAPI = new Mock <IPonyAPIClient>();

            mazeFactory = new MazeFactory(mockPonyAPI.Object);
            int    width      = 15;
            int    height     = 15;
            int    difficulty = 5;
            string pony       = "PonyName";

            mockPonyAPI.Setup(p => p.CreateMaze(width, height, pony, difficulty)).ReturnsAsync(
                new HttpResponseMessage
            {
                StatusCode = System.Net.HttpStatusCode.OK,
                Content    = new StringContent("{\"maze_id\": \"" + mazeId + "\"}", Encoding.UTF8, "application/json")
            });
            mockPonyAPI.Setup(p => p.GetMaze(mazeId)).ReturnsAsync(
                new HttpResponseMessage
            {
                StatusCode = System.Net.HttpStatusCode.OK,
                Content    = new StringContent(mazeJson, Encoding.UTF8, "application/json")
            });

            Maze maze = await mazeFactory.Create(width, height, pony, difficulty);

            mockPonyAPI.Verify(p => p.CreateMaze(width, height, pony, difficulty), Times.Once);
            mockPonyAPI.Verify(p => p.GetMaze(mazeId), Times.Once);
            Assert.AreEqual(width, maze.Width);
            Assert.AreEqual(height, maze.Height);
            Assert.AreEqual(mazeId, maze.MazeId);
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates the maze.
        /// </summary>
        /// <param name="type">The type of algorithm to use to create the maze.</param>
        /// <returns>the created maze</returns>
        public static IMaze CreateMaze(int type)
        {
            WallBreakerFactory breaker = new WallBreakerFactory((WallBreakerFactory.BreakingType)type);
            MazeFactory        factory = new MazeFactory(int.Parse(AppSettings.Settings["rows"]), int.Parse(AppSettings.Settings["cols"]));

            return(factory.GetMaze(breaker));
        }
Exemplo n.º 6
0
        public Main()
        {
            MazeGame    game    = new MazeGame();
            MazeFactory factory = new MazeFactory();
            Maze        maze;

            maze = game.CreateMaze(factory); //s
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            MazeFactory mazeFactory;

            mazeFactory = MazeFactory.Instance();

            mazeFactory = MazeFactory.InstanceWithSubclasses("bombed");
            mazeFactory = MazeFactory.InstanceWithSubclasses("enchanted");
        }
        public MazeGame CreateSimpleMazeGame()
        {
            MazeGame game = new MazeGame();

            MazeFactory factory = new MazeFactory();

            game.CreateMaze(factory);

            return(game);
        }
        public void Abstract_Factory_Test()
        {
            var maze = MazeFactory.CreateMaze();
            var door = MazeFactory.CreateDoor();
            var room = MazeFactory.CreateRoom();
            var wall = MazeFactory.CreateWall();

            Assert.IsInstanceOfType(maze, typeof(ConcreteMaze));
            Assert.IsInstanceOfType(door, typeof(ConcreteDoor));
            Assert.IsInstanceOfType(room, typeof(ConcreteRoom));
            Assert.IsInstanceOfType(wall, typeof(ConcreteWall));
        }
        public void CreateMazeFactorySingleton()
        {
            MazeFactory.MazeFactoryType = typeof(EnchantedMazeFactory);
            MazeFactory mazeFactory1 = MazeFactory.Instance;

            MazeFactory.MazeFactoryType = typeof(BombedMazeFactory);
            MazeFactory mazeFactory2 = MazeFactory.Instance;

            // AreEqual - Check equal type and value
            Assert.AreEqual(mazeFactory1, mazeFactory2);
            // AreSame - Check references indicated the same object in memory.
            Assert.AreSame(mazeFactory1, mazeFactory2);
        }
Exemplo n.º 11
0
        public Maze CreateMaze(MazeFactory factory)
        {
            Maze maze = factory.MakeMaze();

            Room r1   = factory.MakeRoom(1);
            Room r2   = factory.MakeRoom(2);
            Door door = factory.MakeDoor(r1, r2);

            maze.AddRoom(r1);
            maze.AddRoom(r2);

            return(maze);
        }
Exemplo n.º 12
0
        public void AddElements(int value)
        {
            MazeFactory factoryObject = new MazeFactory();

            figureList.Clear();
            if (value == 1)
            {
                figureList = factoryObject.CreateMazeFromTextFile(@"E:\StandardFactory.txt");
            }
            else if (value == 2)
            {
                figureList = factoryObject.CreateMazeFromTextFile(@"E:\MagicFactory.txt");
            }
            CreatePlayer();
            DrawMap();
        }
Exemplo n.º 13
0
        public void CanCreateMazes()
        {
            // Arrange
            var factory = new MazeFactory();
            var game    = new MazeGame(factory);

            // Act
            var maze      = game.CreateMaze();
            var firstRoom = maze.GetRoom(1);
            var door      = firstRoom.GetSide(Direction.East);

            // Assert
            maze.Should().BeOfType <Maze>();
            firstRoom.Should().BeOfType <Room>();
            door.Should().BeOfType <Door>();
        }
Exemplo n.º 14
0
        public async Task BuildMaze_FromExistingID_ApiCalled()
        {
            Guid mazeId = Guid.NewGuid();
            Mock <IPonyAPIClient> mockPonyAPI = new Mock <IPonyAPIClient>();

            mazeFactory = new MazeFactory(mockPonyAPI.Object);
            mockPonyAPI.Setup(p => p.GetMaze(mazeId)).ReturnsAsync(
                new HttpResponseMessage
            {
                StatusCode = System.Net.HttpStatusCode.OK,
                Content    = new StringContent(mazeJson, Encoding.UTF8, "application/json")
            });

            Maze maze = await mazeFactory.FromID(mazeId);

            mockPonyAPI.Verify(p => p.GetMaze(mazeId), Times.Once);
            Assert.AreEqual(mazeId, maze.MazeId);
        }
Exemplo n.º 15
0
    public static MazeFactory GetInstance()
    {
        if (_instance == null)
        {
            string _mazeStyle = "Main.GetCurrentMazeStyle()";

            switch (_mazeStyle)
            {
            case "standart": _instance = new MazeFactory(); break;

            case "magic": _instance = new MagicMazeFactory(); break;

            default: _instance = new MazeFactory(); break;
            }
        }

        return(_instance);
    }
Exemplo n.º 16
0
        public Maze CreateMaze(MazeFactory mazeFactory)
        {
            //var maze = new Maze();
            //var room1 = new Room(1);
            //var room2 = new Room(2);
            //var door = new Door(room1, room2);

            //maze.AddRoom(room1);
            //maze.AddRoom(room2);

            //room1.SetSide(Direction.North, new Wall());
            //room1.SetSide(Direction.East, door);
            //room1.SetSide(Direction.South, new Wall());
            //room1.SetSide(Direction.West, new Wall());

            //room2.SetSide(Direction.North, new Wall());
            //room2.SetSide(Direction.East, new Wall());
            //room2.SetSide(Direction.South, new Wall());
            //room2.SetSide(Direction.West, door);

            // notice that the class names are no longer hard coded:

            var maze  = mazeFactory.MakeMaze();
            var room1 = mazeFactory.MakeRoom(1);
            var room2 = mazeFactory.MakeRoom(2);
            var door  = mazeFactory.MakeDoor(room1, room2);

            maze.AddRoom(room1);
            maze.AddRoom(room2);

            room1.SetSide(Direction.North, mazeFactory.MakeWall());
            room1.SetSide(Direction.East, door);
            room1.SetSide(Direction.South, mazeFactory.MakeWall());
            room1.SetSide(Direction.West, mazeFactory.MakeWall());

            room2.SetSide(Direction.North, mazeFactory.MakeWall());
            room2.SetSide(Direction.East, mazeFactory.MakeWall());
            room2.SetSide(Direction.South, mazeFactory.MakeWall());
            room2.SetSide(Direction.West, door);

            return(maze);
        }
Exemplo n.º 17
0
        public void Instance_BaseClassThenSubClass_OnlyBaseClassInstanceExists()
        {
            var mazeFactory = MazeFactory.CreateInstance(new MazeFactoryParameters()
            {
                Message = "base class 1"
            });

            mazeFactory.Should().BeOfType <MazeFactory>();
            mazeFactory.Should().NotBeOfType <EnhancedMazeFactory>();
            mazeFactory.Should().NotBeOfType <BombedMazeFactory>();
            mazeFactory.Message.Should().Be("base class 1");

            var bombedMazeFactory = BombedMazeFactory.CreateInstance(new MazeFactoryParameters()
            {
                Message = "bombed"
            });

            bombedMazeFactory.Should().Be(mazeFactory);    //reference equality !!!
            bombedMazeFactory.Message.Should().Be("base class 1");
        }
Exemplo n.º 18
0
        public void Instance_BaseClassFewTimes_OnlyOneExists()
        {
            var mazeFactory = MazeFactory.CreateInstance(new MazeFactoryParameters()
            {
                Message = "base class 1"
            });

            mazeFactory.Should().BeOfType <MazeFactory>();
            mazeFactory.Should().NotBeOfType <EnhancedMazeFactory>();
            mazeFactory.Should().NotBeOfType <BombedMazeFactory>();
            mazeFactory.Message.Should().Be("base class 1");

            var anotherMazeFactory = MazeFactory.CreateInstance(new MazeFactoryParameters()
            {
                Message = "another one"
            });

            anotherMazeFactory.Should().Be(mazeFactory);    //reference equality
            anotherMazeFactory.Message.Should().Be("base class 1");
        }
Exemplo n.º 19
0
        public Maze CreateMaze(MazeFactory factoryParam)
        {
            factory = factoryParam;
            var aMaze = factory.MakeMaze();
            var r1 = factory.MakeRoom(1);
            var r2 = factory.MakeRoom(2);
            var theDoor = factory.MakeDoor(r1, r2);
            aMaze.AddRoom(r1);
            aMaze.AddRoom(r2);
            r1.SetSide(Direction.North, factory.MakeWall());
            r1.SetSide(Direction.East, theDoor);
            r1.SetSide(Direction.South, factory.MakeWall());
            r1.SetSide(Direction.West, factory.MakeWall());

            r1.SetSide(Direction.North, factory.MakeWall());
            r1.SetSide(Direction.West, theDoor);
            r1.SetSide(Direction.South, factory.MakeWall());
            r1.SetSide(Direction.East, factory.MakeWall());
            return aMaze;
        }
Exemplo n.º 20
0
        public void CreateMaze(MazeFactory factory)
        {
            var maze    = factory.MakeMaze();
            var r1      = factory.MakeRoom(1);
            var r2      = factory.MakeRoom(2);
            var theDoor = factory.MakeDoor(r1, r2);


            r1.SetSide(EnumDirection.North, factory.MakeWall());
            r1.SetSide(EnumDirection.East, theDoor);
            r1.SetSide(EnumDirection.South, factory.MakeWall());
            r1.SetSide(EnumDirection.West, factory.MakeWall());

            r2.SetSide(EnumDirection.North, factory.MakeWall());
            r2.SetSide(EnumDirection.East, factory.MakeWall());
            r2.SetSide(EnumDirection.South, factory.MakeWall());
            r2.SetSide(EnumDirection.West, theDoor);

            maze.AddRoom(r1);
            maze.AddRoom(r2);
        }
Exemplo n.º 21
0
        public Maze CreateMaze(MazeFactory factory)
        {
            var maze    = factory.MakeMaze();
            var room1   = factory.MakeRoom(1);
            var room2   = factory.MakeRoom(2);
            var theDoor = factory.MakeDoor(room1, room2);

            room1.SetSide(Direction.North, factory.MakeWall());
            room1.SetSide(Direction.East, theDoor);
            room1.SetSide(Direction.South, factory.MakeWall());
            room1.SetSide(Direction.West, factory.MakeWall());

            room2.SetSide(Direction.North, factory.MakeWall());
            room2.SetSide(Direction.East, factory.MakeWall());
            room2.SetSide(Direction.South, factory.MakeWall());
            room2.SetSide(Direction.West, theDoor);

            maze.AddRoom(room1);
            maze.AddRoom(room2);

            return(maze);
        }
Exemplo n.º 22
0
        public Maze CreateMazeAbstractFactory(MazeFactory factory)
        {
            Maze aMaze   = factory.MakeMaze();
            Room r1      = factory.MakeRoom(1);
            Room r2      = factory.MakeRoom(2);
            Door theDoor = factory.MakeDoor(r1, r2);

            aMaze.AddRoom(r1);
            aMaze.AddRoom(r2);

            r1.SetSide(Direction.North, factory.MakeWall());
            r1.SetSide(Direction.East, theDoor);
            r1.SetSide(Direction.South, factory.MakeWall());
            r1.SetSide(Direction.West, factory.MakeWall());

            r2.SetSide(Direction.North, factory.MakeWall());
            r2.SetSide(Direction.East, factory.MakeWall());
            r2.SetSide(Direction.South, factory.MakeWall());
            r2.SetSide(Direction.West, theDoor);

            return(aMaze);
        }
Exemplo n.º 23
0
        public Maze CreateMaze(MazeFactory mazeFactory)
        {
            Maze maze = mazeFactory.MakeMaze();
            Room r1   = mazeFactory.MakeRoom(1);
            Room r2   = mazeFactory.MakeRoom(2);
            Door door = mazeFactory.MakeDoor(r1, r2);

            maze.AddRoom(r1);
            maze.AddRoom(r2);

            r1.SetSide(Direction.North, new Wall());
            r1.SetSide(Direction.East, door);
            r1.SetSide(Direction.South, new Wall());
            r1.SetSide(Direction.West, new Wall());

            r2.SetSide(Direction.North, new Wall());
            r2.SetSide(Direction.East, new Wall());
            r2.SetSide(Direction.South, new Wall());
            r2.SetSide(Direction.West, door);

            return(maze);
        }
        private Maze CreateMaze(MazeFactory factory)
        {
            Maze aMaze = factory.MakeMaze();
            Room r1 = factory.MakeRoom(1);
            Room r2 = factory.MakeRoom(2);
            Door theDoor = factory.MakeDoor(r1, r2);

            aMaze.AddRoom(r1);
            aMaze.AddRoom(r2);

            r1.SetSide(Direction.North, factory.MakeWall());
            r1.SetSide(Direction.South, theDoor);
            r1.SetSide(Direction.East, factory.MakeWall());
            r1.SetSide(Direction.West, factory.MakeWall());

            r2.SetSide(Direction.North, factory.MakeWall());
            r2.SetSide(Direction.South, factory.MakeWall());
            r2.SetSide(Direction.East, factory.MakeWall());
            r2.SetSide(Direction.West, theDoor);

            return aMaze;
        }
Exemplo n.º 25
0
        public Maze CreateMaze(MazeFactory mazeFactory)
        {
            Maze maze  = mazeFactory.MakeMaze();
            Room room1 = mazeFactory.MakeRoom(1);
            Room room2 = mazeFactory.MakeRoom(2);
            Door door  = mazeFactory.MakeDoor(room1, room2);

            maze.AddRoom(room1);
            maze.AddRoom(room2);

            room1.SetSide(Composition.Sides.North, mazeFactory.MakeWall());
            room1.SetSide(Composition.Sides.East, door);
            room1.SetSide(Composition.Sides.South, mazeFactory.MakeWall());
            room1.SetSide(Composition.Sides.West, mazeFactory.MakeWall());


            room2.SetSide(Composition.Sides.North, mazeFactory.MakeWall());
            room2.SetSide(Composition.Sides.East, mazeFactory.MakeWall());
            room2.SetSide(Composition.Sides.South, mazeFactory.MakeWall());
            room2.SetSide(Composition.Sides.West, door);
            return(maze);
        }
Exemplo n.º 26
0
        public void AbstractFactoryTest()
        {
            // Arrange
            IMazeFactory factory          = new MazeFactory();
            IMazeFactory enchantedFactory = new EnchantedMazeFactory();

            // Act
            var  game = new MazeGame();
            Maze maze = game.CreateMaze(factory);
            Maze mazeWithEnchantedRooms = game.CreateMaze(enchantedFactory);

            // Assert
            foreach (Room room in maze.Rooms)
            {
                Assert.IsInstanceOfType(room, typeof(Room));
                Assert.IsNotInstanceOfType(room, typeof(EnchantedRoom));
            }

            foreach (Room room in mazeWithEnchantedRooms.Rooms)
            {
                Assert.IsInstanceOfType(room, typeof(EnchantedRoom));
            }
        }
Exemplo n.º 27
0
        public void Descend()
        {
            depth += 1;

            if (maze != null)
            {
                maze.OnChange -= new Maze.ChangeHandler(passalongHandler);
            }
            maze           = MazeFactory.MakeMaze(30, 30, depth);
            maze.OnChange += new Maze.ChangeHandler(passalongHandler);

            if (walker != null)
            {
                walker.OnChange -= new MazeWalker.ChangeHandler(passalongHandler);
            }
            walker           = new MazeWalker(maze[random.Next(maze.Width), random.Next(maze.Height)]);
            walker.OnChange += new MazeWalker.ChangeHandler(passalongHandler);

            if (this.OnChange != null)
            {
                this.OnChange(this);
            }
        }
Exemplo n.º 28
0
        public void GetShortestPath_NoMonster_PathIsShortest()
        {
            MazeFactory factory = new MazeFactory(Mock.Of <IPonyAPIClient>());
            Maze        maze    = factory.FromJson(mazeJson);

            maze.Domokun.Position = new Point(-1, -1);
            solver = new MazePathfinder();


            Path path = solver.Solve(maze);

            Path expectedPath = new Path {
                Source = maze.Pony.Position, Destination = maze.EndPoint
            };

            expectedPath.Steps = new List <Point>
            {
                new Point(4, 4),
                new Point(4, 3),
                new Point(4, 2),
                new Point(5, 2),
                new Point(6, 2),
                new Point(6, 1),
                new Point(5, 1),
                new Point(4, 1),
                new Point(4, 0),
                new Point(3, 0),
                new Point(3, 1),
            };

            Assert.AreEqual(maze.MazeId, path.MazeId);
            Assert.AreEqual(expectedPath.Steps, path.Steps.Take(11));
            Assert.AreEqual(81, path.Length);
            Assert.AreEqual(maze.Pony.Position, path.Source);
            Assert.AreEqual(maze.EndPoint, path.Destination);
            Assert.AreEqual(maze.EndPoint, path.Steps.Last());
        }
Exemplo n.º 29
0
 public StandardMazeBuilder(MazeFactory factory)
 {
     _factory = factory;
 }
Exemplo n.º 30
0
 public Maze CreateGame(MazeFactory factory)
 {
     return(factory.MakeMaze());
 }
Exemplo n.º 31
0
 public MazeFactory Instanse()
 {
     return factory ?? (factory = new MazeFactory());
 }
Exemplo n.º 32
0
 public void TestInitialize()
 {
     _mf = new MazeFactory();
 }