Пример #1
0
        public static MazeFactory Instance()
        {
            if (_instance == null)
            {
                _instance = new MazeFactory();
            }

            return(_instance);
        }
Пример #2
0
        static void Main(string[] args)
        {
            ConsoleColor org = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("Design Pattern Demos: Traditional Gang of Four Examples: Creational Design Patterns: Singleton");
            Console.WriteLine("https://github.com/JoyfulReaper\n");
            Console.ForegroundColor = org;

            Console.WriteLine("Creating Maze using MazeFactory singleton");
            MazeGame mazeGame = new MazeGame();
            var      maze     = mazeGame.CreateMaze(MazeFactory.Instance());
        }
Пример #3
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);

            r1.SetSide(Direction.North, factory.MakeWall());
            r1.SetSide(Direction.East, door);
            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, door);

            return(maze);
        }