public IActionResult Highscore(string puzzleName)
        {
            var mapper = new PuzzleMapper();
            PuzzleHighscoreViewModel vm;
            int puzzleId = -1;

            using (_context) {
                PuzzleDto puzzle = _context.Puzzles.First(x => x.Name == puzzleName);
                vm = new PuzzleHighscoreViewModel()
                {
                    Name = puzzle.Name, Highscores = new List <HighscoreViewModel>()
                };
                puzzleId = (int)puzzle.Id;
            }

            PuzzleReply reply = _hiscoreClient.GetPuzzleHighscore(new PuzzleRequest()
            {
                PuzzleId = puzzleId
            });

            foreach (PuzzleHighscore item in reply.Highscores.OrderBy(x => x.SecondsToComplete))
            {
                vm.Highscores.Add(new HighscoreViewModel {
                    PlayerName        = item.AttemptName,
                    SecondsToComplete = item.SecondsToComplete
                });
            }

            return(View(vm));
        }
예제 #2
0
 public PuzzleViewModel Map(PuzzleDto source)
 {
     return(new PuzzleViewModel {
         Name = source.Name,
         Difficulty = source.Difficulty.ToString(),
     });
 }
        public IActionResult Create(PuzzleViewModel vm)
        {
            var       mapper = new PuzzleMapper();
            PuzzleDto entity = mapper.Map(vm);

            using (_context) {
                _context.Puzzles.Add(entity);
                _context.SaveChanges();
            }
            return(RedirectToAction("index"));
        }
예제 #4
0
        private PuzzleDto GenerateNewPuzzle(int levelNumber)
        {
            var levelData = _levelDataRepository.GetLevel(levelNumber);

            var numberOfShapes = levelData.Shapes.Length;

            var numberOfMoves = numberOfShapes + Math.Min((int)(((double)levelNumber / 15) * numberOfShapes), 2 * numberOfShapes);
            var puzzle        = new PuzzleDto()
            {
                LevelTemplate = levelData,
                Deformations  = GetDeformationSequence(numberOfShapes).Take(numberOfMoves).ToList(),
            };

            return(puzzle);
        }
예제 #5
0
        public async Task PreviouslySolvedPuzzlesRequest_Should_Send_A_List_With_One_SudokuPuzzle()
        {
            SolveSudokuRequest solveSudokuRequest = new SolveSudokuRequest
            {
                Data = new SudokuPuzzleState
                {
                    PuzzleAsString = "034007008080065000000300070200000700710040096005000001050002000000170060600900430"
                },
                EventName = "sudokuSolvePuzzleRequest"
            };
            string jsonSolve = JsonConvert.SerializeObject(solveSudokuRequest);

            byte[]        messageBufferSolve  = Encoding.Default.GetBytes(jsonSolve);
            WebSocketMock webSocketMockSolver = new WebSocketMock();

            _httpHandler.AddResponse(GetDefaultSavePuzzle());
            await _puzzleHandler.ReceiveAsync(webSocketMockSolver, messageBufferSolve);

            PreMessage previouslySolvedPuzzlesRequest = new PreMessage
            {
                EventName = "previouslySolvedPuzzlesRequest"
            };
            string json = JsonConvert.SerializeObject(previouslySolvedPuzzlesRequest);

            byte[]        messageBuffer = Encoding.Default.GetBytes(json);
            WebSocketMock webSocketMock = new WebSocketMock();
            PuzzleDto     puzzleDto     = new PuzzleDto
            {
                OriginalPuzzle = "034007008080065000000300070200000700710040096005000001050002000000170060600900430",
                PuzzleId       = 1,
                PuzzleType     = "Sudoku",
                SolvedPuzzle   = "534297618187465329962381574246819753718543296395726841459632187823174965671958432"
            };

            _httpHandler.AddResponse(GetPreviouslySolvedPuzzles(new List <PuzzleDto> {
                puzzleDto
            }));

            await _puzzleHandler.ReceiveAsync(webSocketMock, messageBuffer);

            (_, ArraySegment <byte> arraySegment) = webSocketMock.SentMessages.First();
            string responseJson = Encoding.Default.GetString(arraySegment);
            PreviouslySolvedPuzzlesResponse sudokuGeneratePuzzleResponse = JsonConvert.DeserializeObject <PreviouslySolvedPuzzlesResponse>(responseJson);

            Assert.IsTrue(sudokuGeneratePuzzleResponse.Success);
            Assert.IsTrue(sudokuGeneratePuzzleResponse.Data.Puzzles.Count(puzzle => puzzle.PuzzleType.Equals("Sudoku")) == 1);
        }
예제 #6
0
        public static Puzzle CreateFromPuzzleData(PuzzleDto puzzleData, PuzzleCreationContext context)
        {
            var shapes = new List <Shape>();

            foreach (var shapeData in puzzleData.LevelTemplate.Shapes)
            {
                var shape = Shape.Create(shapeData.TilePositions, new Vector2(shapeData.OffsetX, shapeData.OffsetY), context.Storyboard, context.TileModel, context.Palette, -100);
                shapes.Add(shape);
            }

            AdjustInitialPositionsToCentreShape(shapes);
            AssignExplodedPositions(shapes, context.LayoutSize);

            var deformations = puzzleData.Deformations.Select(
                deformation => new ShapeDeformation()
            {
                Shape       = shapes[deformation.ShapeIndex],
                Deformation = GetDeformationClassFromDto(deformation.Transformation),
            }).ToList();

            return(new Puzzle(context.Storyboard, shapes, deformations));
        }
예제 #7
0
 public async Task SavePuzzle(PuzzleDto puzzleDto)
 {
     await _restServiceConnector.PostAsync <HalRootObject <PuzzleDtoHal>, PuzzleDto>("/puzzles/savePuzzle", puzzleDto);
 }