public ActionResult Display(WordSearchIndexModel wordSearchIndexModel) { // ToDo - this should go in a service IRandomNumberService randomNumberService = new RandomNumberService(); IWordPlacementService wordPlacementService = new WordPlacementService(randomNumberService); var wordSearchGrid = new WordSearchGrid(wordSearchIndexModel.Rows, wordSearchIndexModel.Columns, wordPlacementService, randomNumberService); wordSearchIndexModel.Words .Where(w => !string.IsNullOrEmpty(w)) .ToList() .ForEach(a => wordSearchGrid.AddHiddenWord(a)); wordSearchGrid.FillEmptySpaces(); var wordSearchDisplayModel = new WordSearchDisplayModel(wordSearchIndexModel); var grid = wordSearchGrid.Grid; var hiddenWords = wordSearchGrid.HiddenWords; wordSearchDisplayModel.Grid = grid; wordSearchDisplayModel.HiddenWords = hiddenWords; return(View(wordSearchDisplayModel)); }
public void PlaceWordInGrid_ValidWordDownwards_Success() { IRandomNumberService randomNumberService = new RandomNumberService(); var wordPlacementService = new WordPlacementService(randomNumberService); var grid = new char[20, 20]; var hiddenWord = new HiddenWord() { Start = new GridLocation(10, 10), Word = "hello", Direction = DirectionFlagsEnum.Down }; var result = wordPlacementService.PlaceWordInGrid(grid, hiddenWord); Assert.True(result); Assert.Equal('h', grid[9, 9]); // grid id 0 based Assert.Equal('e', grid[10, 9]); Assert.Equal('l', grid[11, 9]); Assert.Equal('l', grid[12, 9]); Assert.Equal('o', grid[13, 9]); }
private void buttonCreateGrid_Click(object sender, EventArgs e) { IRandomNumberService randomNumberService = new RandomNumberService(); IWordPlacementService wordPlacementService = new WordPlacementService(randomNumberService); var wordSearchGrid = new WordSearchGrid(20, 20, wordPlacementService, randomNumberService); wordSearchGrid.AddHiddenWord("word"); wordSearchGrid.AddHiddenWord("search"); wordSearchGrid.AddHiddenWord("reallylongword"); wordSearchGrid.AddHiddenWord("anotherlongone"); wordSearchGrid.AddHiddenWord("today"); wordSearchGrid.AddHiddenWord("yesterday"); var grid = wordSearchGrid.Grid; var hiddenWords = wordSearchGrid.HiddenWords; var rows = grid.GetUpperBound(0); // 0 based var cols = grid.GetUpperBound(1); // wordSearchGrid.FillEmptySpaces(); labelGrid.Text = wordSearchGrid.ToString(); }
public void GetWordPlacement() { IRandomNumberService randomNumberService = new RandomNumberService(); var wordPlacementService = new WordPlacementService(randomNumberService); }