static void Main(string[] args) { var day = PuzzleFactory.GetPuzzle(21, "b"); day.ReadInput(); day.Solve(); day.DeliverResults(); }
/// <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); }
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); }
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; }
/// <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 }); } }
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); }
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(); } }
public void ReturnsHardPuzzle() { var puzzle = PuzzleFactory.GetPuzzle(Core.Enums.Difficulty.Hard); Assert.IsInstanceOfType(puzzle, typeof(HardPuzzle)); }
public void ReturnsMediumPuzzle() { var puzzle = PuzzleFactory.GetPuzzle(Core.Enums.Difficulty.Medium); Assert.IsInstanceOfType(puzzle, typeof(MediumPuzzle)); }
public void ReturnEmptyPuzzleByDefault() { var puzzle = PuzzleFactory.GetPuzzle(Core.Enums.Difficulty.Empty); Assert.IsInstanceOfType(puzzle, typeof(EmptyPuzzle)); }