Exemplo n.º 1
0
 public void SetOrReset()
 {
     mazeGame = new MazeGame();
     MazeFactorySingleton.ResetForNUnit();
     mazeFactory = null;
     maze        = null;
 }
        public static MazeFactorySingleton Instance(string mazeStyle)
        {
            if (_instance == null)
            {
                if (mazeStyle == "bombed")
                {
                    _instance = new BombedMazeFactory();
                }
                else if (mazeStyle == "enchanted")
                {
                    _instance = new EnchantedMazeFactory();
                }
                else
                {
                    _instance = new MazeFactorySingleton();
                }
            }

            return(_instance);
        }
Exemplo n.º 3
0
        public Maze CreateMaze(MazeFactorySingleton mazeFactory)
        {
            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);
        }
 // defeats the purpose of a singleton, but needed in order to test in nunuit
 public static void ResetForNUnit()
 {
     _instance = null;
 }
Exemplo n.º 5
0
 public void Setup()
 {
     SetOrReset();
     mazeFactory = MazeFactorySingleton.Instance("");
     maze        = mazeGame.CreateMaze(mazeFactory);
 }
Exemplo n.º 6
0
 public void ShouldAllowOnlyASingleInstanceOfMazeFactory()
 {
     mazeFactory = MazeFactorySingleton.Instance("bombed");
     Assert.AreEqual("Singleton.MazeFactorySingleton", MazeFactorySingleton.GetInstanceType());
 }
Exemplo n.º 7
0
 public void Setup()
 {
     SetOrReset();
     mazeFactory = MazeFactorySingleton.Instance("");
 }