/// <summary> /// IsWordPlacementValid /// Given a hidden word, check that it can fit into the grid given its length /// and starting position within the grid /// </summary> /// <param name="grid"></param> /// <param name="hiddenWord"></param> /// <returns></returns> public static bool IsWordPlacementValid(char[,] grid, HiddenWord hiddenWord) { if (hiddenWord != null) { var gridLocation = new GridLocation(hiddenWord.Start); foreach (var letter in hiddenWord.Word) { if (!CanLetterBePlaced(letter, gridLocation, grid)) { return(false); } gridLocation = GridLocation.GetNextLetterGridLocation(gridLocation, hiddenWord.Direction); } } return(true); }
/// <summary> /// PlaceWordInGrid /// Places the given word in the grid /// </summary> /// <param name="grid"></param> /// <param name="hiddenWord"></param> /// <returns></returns> public bool PlaceWordInGrid(char[,] grid, HiddenWord hiddenWord) { var placed = false; if (placed = PlacementValidator.IsWordPlacementValid(grid, hiddenWord)) { var gridLocation = new GridLocation(hiddenWord.Start); foreach (var letter in hiddenWord.Word) { grid[gridLocation.Row - 1, gridLocation.Column - 1] = letter; gridLocation = GridLocation.GetNextLetterGridLocation(gridLocation, hiddenWord.Direction); } // return true; } return(placed); }