private void MazeGenerator_CanReadTextMaze()
        {
            // Arrange
            const string stringMaze = "xxxxxx";

            // Act
            var maze = _testee.Generate(stringMaze).GetMaze();

            // Assert
            for (int column = 0; column < stringMaze.Length; column++)
            {
                maze.Field[0, column].Should().Be(MazeTile.Wall);
            }
        }
Ejemplo n.º 2
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();
        }
        public void Init()
        {
            maze      = new Maze(mazeWidth, mazeHeight);
            rng       = new Random(1001);
            generator = new PrimsAlgorithm(rng);
            generator.Generate(maze);

            solver = new RecursiveSolver(maze);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="width">width of the maze to create</param>
 /// <param name="height">height of the maze to create</param>
 /// <param name="mice">number of mice to create</param>
 /// <param name="randomNumberGenerator">function for generating random numbers</param>
 /// <param name="mazeGenerator">instance to generate the maze</param>
 /// <param name="mouseGenerator">factory for the mice</param>
 public Game(int width, int height, int mice, RandomNumberGenerator randomNumberGenerator, IMazeGenerator mazeGenerator, MouseGenerator mouseGenerator)
 {
     mazeGenerator.Initialize(randomNumberGenerator);
     maze        = mazeGenerator.Generate(width, height);
     targetField = new Position(randomNumberGenerator(0, width), randomNumberGenerator(0, height));
     for (int i = 0; i < mice; ++i)
     {
         this.mice.Add(new GameViewAgent(randomNumberGenerator, mouseGenerator(), maze));
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Generates the specified maze by the request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        /// <exception cref="System.InvalidOperationException"></exception>
        public Maze GenerateMaze(GenerateRequest request)
        {
            // if there is a maze with this name
            if (mazes.ContainsKey(request.MazeName))
            {
                throw new InvalidOperationException(string.Format("Maze with the name \"{0}\" already exists!", request.MazeName));
            }
            Maze m = mazeGen.Generate(request.Rows, request.Columns);

            m.Name = request.MazeName;
            mazes[request.MazeName] = m;
            return(m);
        }
 /// <summary>
 /// Starts the specified host.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="rows">The rows.</param>
 /// <param name="cols">The cols.</param>
 /// <returns></returns>
 public Maze Start(string name, int rows, int cols)
 {
     if (!mpDB.ContainsKey(name))
     {
         Maze maze = generator.Generate(rows, cols);
         maze.Name = name;
         mpDB.Add(name, new MultiPlayerInfoPackage());
         mpDB[name].Maze      = maze;
         mpDB[name].IsStarted = false;
         return(maze);
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates the game for the start command
        /// for a multiplyer game.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <exception cref="System.InvalidOperationException">A game already exists in that name!
        /// or
        /// You are already in other game!</exception>
        public void CreateGame(StartRequest request)
        {
            // if there is already a game in this name
            if (gameManager.ContainsGame(request.MazeDetails.MazeName))
            {
                throw new InvalidOperationException("A game already exists in that name!");
            }

            // if the client is already in other game
            if (gameManager.ContainsGame(request.Client))
            {
                throw new InvalidOperationException("You are already in other game!");
            }

            Maze m = mazeGen.Generate(request.MazeDetails.Rows, request.MazeDetails.Columns);

            m.Name = request.MazeDetails.MazeName;
            MazeGame game = new MazeGame(m);

            gameManager.AddGame(game);
            game.AddPlayer(request.Client);
        }
Ejemplo n.º 8
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()));
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Generate a maze based on the IMazeGenerator that we got in
 /// the constructor.
 /// </summary>
 /// <param name="name">
 /// The name of the maze.
 /// </param>
 /// <param name="rows">
 /// The number of rows.
 /// </param>
 /// <param name="cols">
 /// The number of columns.
 /// </param>
 /// <returns>
 /// Returns the MazeGame that was created.
 /// </returns>
 public ISearchGame GenerateSearchGame(string name, int rows, int cols)
 {
     return(new MazeGame(name, generator.Generate(rows, cols)));
 }
Ejemplo n.º 10
0
 public static Map Generate(IMazeGenerator gen)
 {
     Map map = new Map(gen.width, gen.height);
     gen.Generate(ref map.tiles, 1, 1);
     return map;
 }