public void AddNameToGrid(LetterCheck lett, List <char> aNameCharList, Dictionary <char, int> points, string aName) { if (lett.IsVertical == true) { var startX = lett.ExistingLetterRow - lett.IterationsLeftOrAbove; var startY = lett.ExistingLetterColumn; foreach (var c in aNameCharList) { Grid[startX, startY] = c; Coordinate co = new Coordinate(startX, startY); lett.AllCoordinatesOfLettersInName.Add(co, c); startX = startX + 1; } Score = Score + points[lett.Letter] + Config.PointsPerWord; //caluclate the score lett.Added = true; } if (lett.IsHorizontal) { var startX = lett.ExistingLetterRow; var startY = lett.ExistingLetterColumn - lett.IterationsLeftOrAbove; foreach (var c in aNameCharList) { Grid[startX, startY] = c; Coordinate co = new Coordinate(startX, startY); lett.AllCoordinatesOfLettersInName.Add(co, c); startY = startY + 1; } Score = Score + points[lett.Letter] + Config.PointsPerWord; //caluclate the score lett.Added = true; } }
public LetterCheck GetCoordinates(LetterCheck lett, LastWordEntered entry, Coordinate cords) { Dictionary <Coordinate, char> coordsinExistingLetter = entry.LetterCords; //get the coords of the letter in the existing word so we know where to start lett.ExistingLetterRow = cords.Row; lett.ExistingLetterColumn = cords.Column; CoordsPointer coordsP = new CoordsPointer(cords); TestTheLetter(coordsP, lett); return(lett); }
public LetterCheck CheckLetters(List <char> letterList, char letterInExistingWord, LastWordEntered entry, string testName, string aName, Coordinate cords) { foreach (var letter in letterList) { lett = new LetterCheck(letterList.IndexOf(letter), letterList.Count, letter); if (lett.Letter == letterInExistingWord) { GetCoordinates(lett, entry, cords); if (lett.Valid == false) { continue; } else { return(lett); } } } return(lett); }
public LetterCheck TestTheLetter(CoordsPointer c, LetterCheck lett) { //check the grid for empty tiles and space for the word if (lett.IterationsLeftOrAbove == 0) //check if the intersecting letter in the word to be added is at the start { //check if word to be inserted is a horizontal word, also lets you know if the existing word in the grid is vertical if (c.RightOfLetter < Grid.GetUpperBound(1) && Grid[lett.ExistingLetterRow, c.RightOfLetter] == '\0' && Grid[lett.ExistingLetterRow, c.LeftOfLetter] == '\0') { for (int x = 0; x < lett.IterationsRightOrBelow + 1; x++) //add an extra move to the left for white space around the letter { if (Grid[lett.ExistingLetterRow, c.RightOfLetter] == '\0' && Grid[c.AboveLetter, c.RightOfLetter] == '\0' && Grid[c.BelowLetter, c.RightOfLetter] == '\0') { lett.Valid = true; lett.IsHorizontal = true; c.RightOfLetter++; //goin right so plus the index by 1 continue; } else { lett.Valid = false; return(lett); } } return(lett); } //check if word to be inserted is a vertical word, also lets you know if the existing word in the grid is horizontal if (lett.ExistingLetterColumn < Grid.GetUpperBound(1) && Grid[c.BelowLetter, lett.ExistingLetterColumn] == '\0' && Grid[c.AboveLetter, lett.ExistingLetterColumn] == '\0') { for (int x = 0; x < lett.IterationsRightOrBelow + 1; x++) //add an extra move to the left for white space around the letter { if (Grid[c.BelowLetter, lett.ExistingLetterColumn] == '\0' && Grid[c.BelowLetter, c.LeftOfLetter] == '\0' && Grid[c.BelowLetter, c.RightOfLetter] == '\0') { lett.Valid = true; lett.IsVertical = true; c.BelowLetter++; //goin down so plus the index by 1 continue; } else { lett.Valid = false; return(lett); } } return(lett); } } //check if word to be inserted is a horizontal word, also lets you know if the existing word in the grid is vertical if (c.RightOfLetter < Grid.GetUpperBound(1) && Grid[lett.ExistingLetterRow, c.LeftOfLetter] == '\0' && Grid[lett.ExistingLetterRow, c.RightOfLetter] == '\0') { //check right of letter the letter for (int x = 0; x < lett.IterationsRightOrBelow + 1; x++) //add an extra move to the left for white space around the letter { if (Grid[lett.ExistingLetterRow, c.RightOfLetter] == '\0' && Grid[c.AboveLetter, c.RightOfLetter] == '\0' && Grid[c.BelowLetter, c.RightOfLetter] == '\0') { lett.Valid = true; lett.IsHorizontal = true; c.RightOfLetter++; //goin right so plus the index by 1 continue; } else { lett.Valid = false; return(lett); } } //check left of letter for (int x = 0; x < lett.IterationsLeftOrAbove + 1; x++) //add an extra move to the left for white space around the letter { if (Grid[lett.ExistingLetterRow, c.LeftOfLetter] == '\0' && Grid[c.AboveLetter, c.LeftOfLetter] == '\0' && Grid[c.BelowLetter, c.LeftOfLetter] == '\0') { lett.Valid = true; lett.IsHorizontal = true; c.LeftOfLetter--; //goin left so minus the index by 1 continue; } else { lett.Valid = false; return(lett); } } } //check if word to be inserted is a vertical word, also lets you know if the existing word in the grid is horizontal else if (lett.ExistingLetterColumn < Grid.GetUpperBound(1) && Grid[c.AboveLetter, lett.ExistingLetterColumn] == '\0' && Grid[c.BelowLetter, lett.ExistingLetterColumn] == '\0') { //check below of the letter for (int x = 0; x < lett.IterationsRightOrBelow + 1; x++) //add an extra move to the left for white space around the letter { if (Grid[c.BelowLetter, lett.ExistingLetterColumn] == '\0' && Grid[c.BelowLetter, c.LeftOfLetter] == '\0' && Grid[c.BelowLetter, c.RightOfLetter] == '\0') { lett.Valid = true; lett.IsVertical = true; c.BelowLetter++; //goin down so plus the index by 1 continue; } else { lett.Valid = false; return(lett); } } //check above of the letter for (int x = 0; x < lett.IterationsLeftOrAbove + 1; x++) //add an extra move to the left for white space around the letter { if (Grid[c.AboveLetter, lett.ExistingLetterColumn] == '\0' && Grid[c.AboveLetter, c.LeftOfLetter] == '\0' && Grid[c.AboveLetter, c.RightOfLetter] == '\0') { lett.Valid = true; lett.IsVertical = true; c.AboveLetter--; //goin up so minus the index by 1 continue; } else { lett.Valid = false; return(lett); } } } return(lett); }