public void GridLineTestSetup() { DirOne = new GridLine(new Point(1,6),new Point(9,6)); DirTwo = new GridLine(new Point(1,1),new Point(6,6)); DirThree = new GridLine(new Point(1,2),new Point(1,6)); DirFour = new GridLine(new Point(4,6),new Point(2,8)); DirFive = new GridLine(new Point(8,3),new Point(0,3)); DirSix = new GridLine(new Point(9,7),new Point(2,0)); DirSeven = new GridLine(new Point(5,8),new Point(5,4)); DirEight = new GridLine(new Point(0,7),new Point(7,0)); MicroSlopeLine = new GridLine(new Point(1,0),new Point(40,1)); HalfSlopeLine = new GridLine(new Point(4,8),new Point(6,9)); SlightlyBelowOneSlopeLine = new GridLine(new Point(0,0),new Point(20,19)); SlightlyAboveOneSlopeLine = new GridLine(new Point(1,1),new Point(40,41)); TwoSlopeLine = new GridLine(new Point(3,5),new Point(4,7)); MegaSlopeLine = new GridLine(new Point(1,5),new Point(2,70)); }
/// <summary> /// Marks the word in the line represented by the two points. Valid lines can only be vertical, /// horizontal or diagonal and must be inside the grid. Point (0,0) represents the top-left cell /// of the grid. /// </summary> /// <returns> /// <c>True</c> if a word was found in the specified coordinates, <c>False</c> otherwise. /// </returns> /// <param name='start_point'> /// Start point of the word, this is where the first letter is located. /// </param> /// <param name='end_point'> /// End point of the word, this is where the last letter is located. /// </param> public bool MarkWord(Point start_point, Point end_point) { GridLine line = new GridLine(start_point,end_point); if (!ValidLine(line)) return false; string word_on_grid = GetStringFromGrid(line); WordLine word = new WordLine(line,word_on_grid); if (notfound_words.Contains(word.Word)) { Console.WriteLine("Word: "+word.Word); notfound_words.Remove(word.Word); found_words.Add(word.Word); for(int i=0; i<word.Word.Length; i++) { Point color_point = word.RealPosition.StartPoint + word.RealPosition.Direction*i; color_points.Add(color_point); } if (notfound_words.Count < 1) state = CLEARED; return true; } return false; }
public string MarkAndGetWord(Point start_point, Point end_point) { GridLine line = new GridLine(start_point,end_point); WordLine word = new WordLine(line,new string(GetWordFromGrid(line))); if (notfound_words.Contains(word.Word)) { notfound_words.Remove(word.Word); found_words.Add(word.Word); for(int i=0; i<word.Word.Length; i++) { Point color_point = word.RealPosition.StartPoint + word.RealPosition.Direction*i; color_points.Add(color_point); } if (notfound_words.Count < 1) state = CLEARED; return word.Word; } return null; }
/// <summary> /// Gets the word from the grid using the specified GridLine. /// </summary> /// <returns> /// The word from grid. /// </returns> /// <param name='line'> /// Line. /// </param> public char[] GetWordFromGrid(GridLine line) { int line_length = line.Length+1; char[] word = new char[line_length]; Point current_location = line.StartPoint; for (int i=0; i<line_length; i++) { word[i] = this.grid[current_location.X, current_location.Y]; current_location+=line.Direction; } return word; }
/// <summary> /// Gets the word as a string from the grid using the specified GridLine. /// </summary> /// <returns> /// The word from grid. /// </returns> /// <param name='line'> /// Line. /// </param> public string GetStringFromGrid(GridLine line) { return new string(GetWordFromGrid(line)); }
/// <summary> /// Confirms the movement, updating the real position using the virtual one. /// </summary> public void ConfirmMovement() { this.real_position = this.virtual_position; }
/// <summary> /// Initializes a new instance of the <see cref="WordSearch.WordLine"/> class. /// </summary> /// <param name='start_point'> /// Start_point. /// </param> /// <param name='direction'> /// Direction. /// </param> /// <param name='word'> /// Word. /// </param> public WordLine(Point start_point, Point direction, string word) { direction = direction.ToDirectionPoint(); real_position=new GridLine(start_point,start_point+new Point(word.Length*direction.X,word.Length*direction.Y)); virtual_position=real_position; this.word = word.ToUpper(); }
/// <summary> /// Initializes a new instance of the <see cref="WordSearch.WordLine"/> class. /// </summary> /// <param name='position'> /// The position in the xy-plane of this word. /// </param> /// <param name='word'> /// The word this object represents. /// </param> public WordLine(GridLine position, string word) { this.real_position = position; this.virtual_position = position; this.word = word.ToUpper(); }