public HttpResponseMessage CreateNewMaze(MazeInitModel model)
        {
            Guid mazeId = Guid.Empty;

            if (ModelState.IsValid)
            {
                try
                {
                    var maze = new Maze(model);
                    mazeId = MemoryCacher.AddMazeInCache(maze);
                }
                catch (Exception ex)
                {
                    throw CreateResponseException(HttpStatusCode.InternalServerError, ex.Message);
                }

                return(Request.CreateResponse(HttpStatusCode.OK, mazeId.ToString()));
            }
            else
            {
                var message = string.Join(" | ", ModelState.Values
                                          .SelectMany(v => v.Errors)
                                          .Select(e => e.ErrorMessage));
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, message));
            }
        }
        public Maze(MazeInitModel model)
        {
            _playerName = model.PlayerName;
            _difficulty = (int)model.Difficulty;

            _width  = model.MazeWidth;
            _height = model.MazeHeight;
            _cells  = new CellState[_width * _height];
            for (var x = 0; x < _height; x++)
            {
                for (var y = 0; y < _width; y++)
                {
                    _cells[(x * _width) + y] = CellState.Initial;
                }
            }
            _rng = new Random();

            MazeHelper.VisitCell(this, _rng.Next(_width * _height), _rng);
        }
Esempio n. 3
0
        public void Init()
        {
            controller               = new MazeController();
            controller.Request       = new HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();

            mazeIds = new List <Guid>();

            allPossibleMoves = new List <string> {
                DIRECTION_STAY, DIRECTION_NORTH, DIRECTION_SOUTH, DIRECTION_EAST, DIRECTION_WEST
            };

            difficultiesModels = new List <MazeInitModel>();

            MazeInitModel initModel = new MazeInitModel()
            {
                Difficulty = DifficultiesEnum.Difficulty.Godlike,
                MazeHeight = 15,
                MazeWidth  = 20,
                PlayerName = "Fluttershy"
            };

            difficultiesModels.Add(initModel);
            initModel = new MazeInitModel()
            {
                Difficulty = DifficultiesEnum.Difficulty.Masochistic,
                MazeHeight = 15,
                MazeWidth  = 20,
                PlayerName = "Fluttershy"
            };
            difficultiesModels.Add(initModel);
            initModel = new MazeInitModel()
            {
                Difficulty = DifficultiesEnum.Difficulty.Tourist,
                MazeHeight = 15,
                MazeWidth  = 20,
                PlayerName = "Fluttershy"
            };
            difficultiesModels.Add(initModel);
        }