示例#1
0
        static void Main(string[] args)
        {
            var day = PuzzleFactory.GetPuzzle(21, "b");

            day.ReadInput();
            day.Solve();
            day.DeliverResults();
        }
示例#2
0
        /// <summary>
        /// This method maps a PuzzleEntity object to a Puzzle object.
        /// </summary>
        /// <param name="puzzleEntity">PuzzleEntity to be mapped.</param>
        /// <returns>Puzzle object</returns>
        public Puzzle MapPuzzleEntityToPuzzle(PuzzleEntity puzzleEntity)
        {
            var difficulty = (Difficulty)puzzleEntity.Difficulty;
            var puzzle     = PuzzleFactory.GetPuzzle(difficulty);

            puzzle.Id = puzzleEntity.Id;
            int[,] array;
            MapToArray(puzzleEntity.WorkingPuzzleArray, out array);
            puzzle.PuzzleArray = array;
            return(puzzle);
        }
示例#3
0
        public void MapPuzzleToPuzzleEntity()
        {
            var puzzle = PuzzleFactory.GetPuzzle(Core.Enums.Difficulty.Medium);

            Assert.IsInstanceOfType(puzzle, typeof(MediumPuzzle));
            puzzle.CreatePuzzle();
            Assert.IsNotNull(puzzle.PuzzleArray);
            var dataMapper   = new PuzzleMapper();
            var puzzleEntity = dataMapper.MapPuzzleToPuzzleEntity(puzzle);

            Assert.AreEqual(puzzle.Id, puzzleEntity.Id);
        }
示例#4
0
        public GameViewModel(IEventAggregator eventAggregator,
                             GameRepository gameRepository)
        {
            _gameRepository  = gameRepository;
            _eventAggregator = eventAggregator;

            New        = new Command(async() => await NewCommandAsync());
            Solve      = new Command(CanSolveCheck, async() => await SolveCommandAsync());
            Check      = new Command(CanSolveCheck, async() => await CheckPuzzleAsync());
            Save       = new Command(CanSave, async() => await SavePuzzleAsync());
            Load       = new Command(LoadCommand);
            Undo       = new Command(CanUndo, UndoCommand);
            puzzle     = PuzzleFactory.GetPuzzle(Difficulty);
            Difficulty = Difficulty.Empty;
        }
示例#5
0
        /// <summary>
        /// Load GameBoard object into viewmodel
        /// </summary>
        /// <param name="puzzleId">Determine which puzzle object to load (nullable will load fresh game)</param>
        /// <returns></returns>
        public async Task LoadPuzzle(int?puzzleId = null)
        {
            if (puzzleId.HasValue)
            {
                puzzle    = _gameRepository.GetPuzzleById(puzzleId.Value);
                GameBoard = new GameBoardWrapper(new GameBoard(puzzle.PuzzleArray));
            }
            else
            {
                puzzle = PuzzleFactory.GetPuzzle(Difficulty);
                await Task.Run(() => puzzle.CreatePuzzle());

                GameBoard = new GameBoardWrapper(new GameBoard(puzzle.PuzzleArray)
                {
                    State = ObjectState.Added
                });
            }
        }
示例#6
0
        public void ShouldSavePuzzle()
        {
            var gameRepo       = new GameRepository(new PuzzleMapper());
            var puzzleEntities = gameRepo.GetPuzzleList();

            Assert.IsNotNull(puzzleEntities);
            var originalPuzzleCount = puzzleEntities.Count;

            var puzzle = PuzzleFactory.GetPuzzle(Core.Enums.Difficulty.Medium);

            Assert.IsInstanceOfType(puzzle, typeof(MediumPuzzle));
            puzzle.CreatePuzzle();
            Assert.IsNotNull(puzzle.PuzzleArray);

            gameRepo.SaveGame(puzzle);
            puzzleEntities = gameRepo.GetPuzzleList();
            Assert.IsNotNull(puzzleEntities);
            Assert.AreNotEqual(originalPuzzleCount, puzzleEntities.Count);
        }
示例#7
0
        public void ShouldStorePuzzleEntityMappedFromPuzzle()
        {
            using (var context = new GameContext())
            {
                var puzzle = PuzzleFactory.GetPuzzle(Core.Enums.Difficulty.Medium);
                Assert.IsInstanceOfType(puzzle, typeof(MediumPuzzle));

                puzzle.CreatePuzzle();
                Assert.IsNotNull(puzzle.PuzzleArray);

                var dataMapper   = new PuzzleMapper();
                var puzzleEntity = dataMapper.MapPuzzleToPuzzleEntity(puzzle);
                puzzleEntity.Name = "test save";
                Assert.AreEqual(puzzle.Id, puzzleEntity.Id);

                context.PuzzleEntities.Add(puzzleEntity);
                context.SaveChanges();
            }
        }
示例#8
0
        public void ReturnsHardPuzzle()
        {
            var puzzle = PuzzleFactory.GetPuzzle(Core.Enums.Difficulty.Hard);

            Assert.IsInstanceOfType(puzzle, typeof(HardPuzzle));
        }
示例#9
0
        public void ReturnsMediumPuzzle()
        {
            var puzzle = PuzzleFactory.GetPuzzle(Core.Enums.Difficulty.Medium);

            Assert.IsInstanceOfType(puzzle, typeof(MediumPuzzle));
        }
示例#10
0
        public void ReturnEmptyPuzzleByDefault()
        {
            var puzzle = PuzzleFactory.GetPuzzle(Core.Enums.Difficulty.Empty);

            Assert.IsInstanceOfType(puzzle, typeof(EmptyPuzzle));
        }