Exemplo n.º 1
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="controller">Game Controller</param>
 public Model(IController controller)
 {
     this.controller    = controller;
     this.Storage       = new Storage();
     this.AlgorithmFac  = new AlgorithmFactory <Position>();
     this.mazeGenerator = new DFSMazeGenerator();
 }
Exemplo n.º 2
0
 /// <summary>
 /// test to the Maze Generator
 /// </summary>
 /// <param name="mg">Maze Generator</param>
 private static void testMazeGenerator(IMazeGenerator mg)
 {
     Console.WriteLine("**************************************");
     Console.WriteLine("*Testing algorithm time: ");
     try
     {
         Console.WriteLine(mg.measureAlgorithmTime(10, 10, 10));
         Console.WriteLine();
     }
     catch (NotSupportedException e)
     {
         Console.WriteLine(e.Message);
     }
     try
     {
         Maze     maze  = mg.generate(10, 10, 10);
         Position start = maze.getStartPosition();
         Console.Write("*Start Position: ");
         start.print();
         Console.Write("*Goal Position: ");
         maze.getGoalPosition().print();
         Console.WriteLine();
         maze.printMapKeys();
         maze.print();
     }
     catch (NotSupportedException e)
     {
         Console.WriteLine(e.Message);
     }
     Console.WriteLine();
     Console.WriteLine("**************************************");
     Console.WriteLine();
     Console.WriteLine("Press any key to continue");
     Console.ReadKey();
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 public MultiPlayerModel()
 {
     this.StartedMazes     = new Dictionary <string, Maze>();
     this.GameRooms        = new Dictionary <string, GameRoom>();
     this.mazeGenerator    = new DFSMazeGenerator();
     this.AlgorithmFactory = new AlgorithmFactory <Position>();
 }
Exemplo n.º 4
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            maze = new MazeGenerator(Convert.ToInt32(txtHeight.Text), Convert.ToInt32(txtHeight.Text));

            ToggleButtonState(false);

            new Thread(delegate()
            {
                using (maze)
                {
                    maze.Generate();

                    gameController = new MazeGameController(maze.Nodes);

                    picVisual.Invoke((MethodInvoker) delegate()
                    {
                        var currentMaze = viewer.Visualize(gameController.State.Nodes, gameController.State.PlayerPos);

                        picVisual.Image = currentMaze;

                        ToggleButtonState(true);
                    });

                    lblWin.Invoke((MethodInvoker) delegate()
                    {
                        this.lblWin.Visible = gameController.IsWin();
                    });
                }
            })
            {
                IsBackground = true
            }.Start();
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 public SinglePlayerModel()
 {
     //Initialize members.
     this.GenerateMazes    = new Dictionary <string, Maze>();
     this.SolvedMazes      = new Dictionary <string, Solution <Position> >();
     this.mazeGenerator    = new DFSMazeGenerator();
     this.AlgorithmFactory = new AlgorithmFactory <Position>();
 }
        public void Init()
        {
            maze      = new Maze(mazeWidth, mazeHeight);
            rng       = new Random(1001);
            generator = new PrimsAlgorithm(rng);
            generator.Generate(maze);

            solver = new RecursiveSolver(maze);
        }
Exemplo n.º 7
0
 public MazeController(
     IMazeGenerator mazeGenerator,
     IMazePainter painter,
     IMazeGraphicRepository mazeGraphicRepository)
 {
     this.mazeGenerator         = mazeGenerator;
     this.mazeGraphicRepository = mazeGraphicRepository;
     this.painter = painter;
 }
Exemplo n.º 8
0
        private static void testMaze3dGenerator(IMazeGenerator generator)
        {
            int[] size3D = { 3, 13, 17 }; // (z,y,x)
            Console.WriteLine(generator.geasureAlgorithmTime(size3D));
            AMaze     maze  = generator.generate(size3D);
            APosition start = maze.getStartPosition();

            start.print();
            maze.getGoalPosition().print();
            maze.print();
        }
Exemplo n.º 9
0
        private static void testMaze3dGenerator(IMazeGenerator mg)
        {
            Console.WriteLine(mg.measureAlgorithmTime(20, 14, 3));
            Maze     maze  = mg.generate(20, 14, 3);
            Position start = maze.getStartPosition();

            Console.WriteLine("The Start Position:");
            start.print();
            Console.WriteLine("The Goal Position:");
            maze.getGoalPosition().print();
            maze.print();
        }
Exemplo n.º 10
0
        private static void CreateAndShowMaze(IMazeGenerator generator)
        {
            var textMaze = generator.GetTextMaze(true);

            Console.WriteLine(textMaze);

            var graphicMaze = generator.GetGraphicalMaze(true);

            graphicMaze.Save("maze.png");
            Process p = new Process();

            p.StartInfo.FileName = "maze.png";
            p.Start();
        }
Exemplo n.º 11
0
 public Maze(int x, int y)
 {
     if (SecondMazeGenerator == false)
     {
         MazeGenerator = new FirstMazeGenerator();
         Cells         = MazeGenerator.GenerateNewMaze(17, 19, x, y);
     }
     else
     {
         MazeGenerator = new SecondMazeGenerator();
         Cells         = MazeGenerator.GenerateNewMaze(17, 19, x, y);
     }
     SecondMazeGenerator = !SecondMazeGenerator;
     GenerateNew         = false;
 }
Exemplo n.º 12
0
        private static void CreateAndShowMaze(IMazeGenerator generator)
        {
            generator.GenerateMaze();

            string textMaze = generator.GetTextMaze(true);

            Console.WriteLine(textMaze);

            Bitmap graphicMaze = generator.GetGraphicalMaze(true);

            graphicMaze.Save("maze.png", ImageFormat.Png);
            Process p = new Process();

            p.StartInfo.UseShellExecute = true;
            p.StartInfo.FileName        = "maze.png";
            p.Start();
        }
Exemplo n.º 13
0
        private HommMapGenerator(
            IMazeGenerator mazeGenerator,
            ITerrainGenerator terrainGenerator,
            params ISpawner[] entitiesGenerators)
        {
            if (mazeGenerator == null)
            {
                throw new InvalidOperationException("should select one IMazeGenerator");
            }

            if (terrainGenerator == null)
            {
                throw new InvalidOperationException("should select one ITerrainGenerator");
            }

            this.mazeGenerator      = mazeGenerator;
            this.terrainGenerator   = terrainGenerator;
            this.entitiesGenerators = entitiesGenerators;
        }
Exemplo n.º 14
0
        private static void CreateAndShowMaze(IMazeGenerator generator)
        {
            generator.GenerateMaze();

            var textMaze = generator.GetTextMaze(true);

            Console.WriteLine(textMaze);

            var graphicMaze = generator.GetGraphicalMaze(true);

            graphicMaze.Save("maze.png");

            // This code is Windows-only
            // Comment out the following if building on macOS or Linux
            // The "maze.png" file can be located in the output
            // folder: [solutionlocation]/DrawMaze/bin/Debug/netcore3.1/
            Process p = new Process();

            p.StartInfo.UseShellExecute = true;
            p.StartInfo.FileName        = "maze.png";
            p.Start();
        }
Exemplo n.º 15
0
        void CreateMazeButtonClick(object sender, EventArgs e)
        {
            try
            {
                int generationAlgoComboboxIndex = mazeGenerationAlgoCombobox.SelectedIndex;
                if (generationAlgoComboboxIndex >= 0)
                {
                    IMazeGenerator selectedGenerator =
                        MazeGeneratorsFactory.Instance.Create(
                            generatorsComboboxValues.ValueByIndex(generationAlgoComboboxIndex));

                    ClearClusters();

                    Stopwatch methodTime = Stopwatch.StartNew();

                    maze = selectedGenerator.Generate(
                        mazeRowsTrackbar.Value,
                        mazeColumnsTrackbar.Value);

                    ShowMaze();

                    methodTime.Stop();
                    DebugConsole.Instance.Info(
                        string.Format("Лабиринт ({0} x {1}) создан и нарисован за {2} мс",
                                      maze.RowCount, maze.ColCount, methodTime.ElapsedMilliseconds));
                }
                else
                {
                    MessageBox.Show("Не выбран алгоритм генерации лабиринта");
                }
            }
            catch (MazeException ex)
            {
                DebugConsole.Instance.Error(
                    string.Format("При создании лабиринта произошла ошибка: {0}",
                                  ex.ToString()));
            }
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            // OPTION #1: Manual Composition
            //IMazeGenerator generator =
            //    new ConsoleLoggingDecorator(
            //        new MazeGenerator(
            //            new ColorGrid(15, 15),
            //            new BinaryTree()));


            // OPTION #2: Ninject
            IKernel Container = new StandardKernel();

            Container.Bind <Grid>().ToMethod(c => new ColorGrid(15, 15));
            Container.Bind <IMazeAlgorithm>().To <Sidewinder>();
            Container.Bind <IMazeGenerator>().To <ConsoleLoggingDecorator>()
            .WithConstructorArgument <IMazeGenerator>(Container.Get <MazeGenerator>());
            IMazeGenerator generator = Container.Get <IMazeGenerator>();


            CreateAndShowMaze(generator);
            Console.ReadLine();
        }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            // Ninject DI Container
            IKernel Container = new StandardKernel();

            Container.Bind <Grid>().ToMethod(c => new ColorGrid(15, 15));
            Container.Bind <IMazeAlgorithm>().To <Sidewinder>();
            Container.Bind <IMazeGenerator>().To <ConsoleLoggingDecorator>()
            .WithConstructorArgument <IMazeGenerator>(Container.Get <MazeGenerator>());

            IMazeGenerator generator = Container.Get <IMazeGenerator>();

            //// Manual object wiring
            //IMazeGenerator generator =
            //    new ConsoleLoggingDecorator(
            //        new MazeGenerator(
            //            new ColoredGrid(15, 15),
            //            new Sidewinder()));

            CreateAndShowMaze(generator);

            Console.ReadLine();
        }
Exemplo n.º 18
0
 /// <summary>
 /// Initializes a new instance of the<see cref="Maze"/> class.
 /// Sets a position of the maze by input.
 /// </summary>
 /// <param name="generator">Maze Generator algorithm.</param>
 /// <param name="leftOffset">New left coordinate.</param>
 /// <param name="topOffset">New top coordinate.</param>
 public Maze(IMazeGenerator generator, int leftOffset, int topOffset)
 {
     this.strategy        = generator;
     this.TopLeftPosition = new MatrixCoordinates(leftOffset, topOffset);
 }
Exemplo n.º 19
0
 private void SetMazeStruct(IMazeGenerator generator, int size)
 {
     mazeStruct = new MazeStruct(generator.GenerateMazeCells(size));
 }
Exemplo n.º 20
0
 public Maze(IMazeGenerator generator, int size)
 {
     InitMaze();
     SetMazeStruct(generator, size);
 }
Exemplo n.º 21
0
 public void SetGenerator(IMazeGenerator mazeGen)
 {
     _mazeGen = mazeGen;
 }
Exemplo n.º 22
0
 private Maze()
 {
     _displayer = new DefaultMazeDisplay();
     _mazeGen = new DefaultMazeGenerator();
 }
Exemplo n.º 23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MazeManager"/> class.
 /// </summary>
 public MazeManager()
 {
     mazeGen       = new DFSMazeGenerator();
     mazes         = new Dictionary <string, Maze>();
     solutionCache = new Dictionary <string, MazeSolution>();
 }
Exemplo n.º 24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MultiModel"/> class.
 /// </summary>
 /// <param name="handler">The handler.</param>
 public MultiModel(IGameEventHandler handler)
 {
     mazeGen     = new DFSMazeGenerator();
     gameManager = new GameManager.GameManager(new ListGameContainer(), handler);
 }
Exemplo n.º 25
0
 internal BuilderOnSelectEntities(
     IMazeGenerator mazeGenerator, ITerrainGenerator terrainGenerator)
 {
     this.mazeGenerator    = mazeGenerator;
     this.terrainGenerator = terrainGenerator;
 }
Exemplo n.º 26
0
 public static BuilderOnSelectTerrain From(IMazeGenerator mazeGenerator)
 {
     return(new BuilderOnSelectTerrain(mazeGenerator));
 }
Exemplo n.º 27
0
 internal BuilderOnSelectTerrain(IMazeGenerator mazeGenerator)
 {
     this.mazeGenerator = mazeGenerator;
 }
Exemplo n.º 28
0
 public static Map Generate(IMazeGenerator gen)
 {
     Map map = new Map(gen.width, gen.height);
     gen.Generate(ref map.tiles, 1, 1);
     return map;
 }
 public MazeGeneratorTest()
 {
     _testee = new MazeGenerator();
 }
Exemplo n.º 30
0
 /// <summary>
 /// Initializes a new instance of the<see cref="Maze"/> class.
 /// </summary>
 /// <param name="generator">Maze Generator algorithm.</param>
 public Maze(IMazeGenerator generator)
     : this(generator, DefaultTopOffset, DefaultLeftOffset)
 {
 }
Exemplo n.º 31
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Maze4"/> class.
 /// </summary>
 /// <param name="generator">The generator.</param>
 /// <remarks></remarks>
 public Maze4(IMazeGenerator generator)
 {
     Contract.Requires(generator != null);
     _generator = generator;
 }
Exemplo n.º 32
0
        public static void GenerateCompletely(this IMazeGenerator generator)
        {
            var runner = new JustGenerateRunner(generator);

            runner.GenerateCompletely();
        }
 /// <summary>
 /// Generates the maze.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="rows">The rows.</param>
 /// <param name="cols">The cols.</param>
 /// <returns>
 /// The maze by the properties.
 /// </returns>
 public MultiplayerModel()
 {
     generator = new DFSMazeGenerator();
 }
Exemplo n.º 34
0
 /// <summary>
 /// Constructor for the MazeGameGenerator.
 /// </summary>
 /// <param name="generator">
 /// The generator we will use.
 /// </param>
 public MazeGameGenerator(IMazeGenerator generator)
 {
     this.generator = generator;
 }
Exemplo n.º 35
0
 /// <summary>
 /// Sets the generator.
 /// </summary>
 /// <param name="generator">The generator.</param>
 /// <remarks></remarks>
 public void SetGenerator(IMazeGenerator generator)
 {
     Contract.Requires(generator != null);
     MazeGenerator = generator;
 }