// Actions single or double click methods private void ButtonEntryFocused(LetterCell letterCell, int clickCount) { _focusedLetterCell = letterCell; _currentPlacedWord.ColourizeSelectedWordCells(Colours.Forground); if (clickCount == 1) { if (letterCell.PlacedWordGroup.PlacedWord1 != null) { _currentPlacedWord = letterCell.PlacedWordGroup.PlacedWord1; letterCell.PlacedWordGroup.PlacedWord1.ColourizeSelectedWordCells(Colours.Highlight); letterCell.CellEntry.Focus(); _isPlacedWordSelected = true; } } else { if (letterCell.PlacedWordGroup.PlacedWord2 != null) { _currentPlacedWord = letterCell.PlacedWordGroup.PlacedWord2; letterCell.PlacedWordGroup.PlacedWord2.ColourizeSelectedWordCells(Colours.Highlight); letterCell.CellEntry.Focus(); _isPlacedWordSelected = true; } else { _isPlacedWordSelected = false; } } }
// InitializeVarialbes private void ResetVariables() { _currentPlacedWord = new PlacedWord(); _wordChecker = new WordChecker(); _focusedLetterCell = null; _score.Value = 0; _newGame = true; }
// Highlights word from definition selection private void HighlightSelectedWordFromDefinition(Definition definition) { _currentPlacedWord.ColourizeSelectedWordCells(Colours.Forground); definition.PlacedWord.ColourizeSelectedWordCells(Colours.Highlight); _currentPlacedWord = definition.PlacedWord; }
// Change definition font colour if word found public void StyleDefinition(ObservableCollection <Definition> definitions, PlacedWord foundWord) { // Remove items that whose definition.Phrase == ACROSS and DOWN var definitionsAcrossDownRemoved = definitions.Where(d => d.Phrase != "ACROSS").Where(d => d.Phrase != "DOWN"); var definition = definitionsAcrossDownRemoved.Where(d => d.Index == foundWord.DefinitionIndex) .Where(d => d.Direction == foundWord.Direction).ToArray(); if (definition.Length != 0) { definition[0].StrikeThrough = true; definition[0].FontColour = Colours.FoundWord; } }
// Returns a list of words that have been placed each time a character is entered into the board. // It considers the existing placed words and removes from calculation // Confirms the word is correct and adjusts colour to suit. Also used to count the score. public Tuple <List <PlacedWord>, PlacedWord> CheckWordOnCharUpdate(ObservableCollection <ObservableCollection <LetterCell> > displayBoard, List <PlacedWord> placedWords, List <PlacedWord> foundWords) { var remaingPlacedWords = placedWords.Where(w => !foundWords.Select(x => x.Word).Contains(w.Word)).ToList(); var solvedWord = new PlacedWord(); for (var i = 0; i < remaingPlacedWords.Count; i++) { if (remaingPlacedWords[i].Direction == WordDirection.Horizontal) { var startPos = remaingPlacedWords[i].StartPos; var correctLetterCount = 0; // Check all letters of a placedWord for (var j = startPos.Item1; j < startPos.Item1 + remaingPlacedWords[i].Word.Length; j++) { if (displayBoard[startPos.Item2][j].LetterIn == remaingPlacedWords[i].Word[j - startPos.Item1]) { correctLetterCount++; } } if (correctLetterCount == remaingPlacedWords[i].Word.Length) { for (var j = startPos.Item1; j < startPos.Item1 + remaingPlacedWords[i].Word.Length; j++) { FormatTextBox(displayBoard, startPos.Item2, j); } solvedWord = remaingPlacedWords[i]; foundWords.Add(solvedWord); } } else { var startPos = remaingPlacedWords[i].StartPos; var correctLetterCount = 0; for (var j = startPos.Item2; j < startPos.Item2 + remaingPlacedWords[i].Word.Length; j++) { if (displayBoard[j][startPos.Item1].LetterIn == remaingPlacedWords[i].Word[j - startPos.Item2]) { correctLetterCount++; } } if (correctLetterCount == remaingPlacedWords[i].Word.Length) { for (var j = startPos.Item2; j < startPos.Item2 + remaingPlacedWords[i].Word.Length; j++) { FormatTextBox(displayBoard, j, startPos.Item1); } solvedWord = remaingPlacedWords[i]; foundWords.Add(solvedWord); } } } return(new Tuple <List <PlacedWord>, PlacedWord>(foundWords, solvedWord)); }