private void FindAllWords(StringBuilder curword, int i, int j) { curword.Append(LetterGrid[i, j].ASCIIChar); if (curword.Length < 15) { if (curword.Length >= 3) { if (EngLetterScoring.IsWord(curword)) { Word w = new Word(CurWordList); if (!WordsFromLetter.Contains(w)) { WordsFromLetter.Add(w); } } } if (EngLetterScoring.PartialExists(curword.ToString())) { if (i > 0) { if (j > 0) { FindAllWords(curword, i - 1, j - 1); } FindAllWords(curword, i - 1, j); if (j < WSGameState.gridsize - 1) { FindAllWords(curword, i - 1, j + 1); } } if (j > 0) { FindAllWords(curword, i, j - 1); } if (j < WSGameState.gridsize - 1) { FindAllWords(curword, i, j + 1); } if (i < WSGameState.gridsize - 1) { if (j > 0) { FindAllWords(curword, i + 1, j - 1); } FindAllWords(curword, i + 1, j); if (j < WSGameState.gridsize - 1) { FindAllWords(curword, i + 1, j + 1); } } } } curword.Remove(curword.Length - 1, 1); // one by one add each letter. If there is no match, then stop that branch }
internal static void SubmitWord() { string s = GetCurrentWord().ToLower(); if (EngLetterScoring.IsWord(s)) { ScoreStats ss = RecordWordScore(); RemoveWordAndReplaceTiles(); Deselect(null); boardScript.ResetSubmitButton(); bool gameOver = ProcessLetters(); if (gameOver) { RemoveGameBoard(); //SaveStats(); Resume = false; boardScript.EndGanme(); //ResetSavedGame(); } else { if (ss.MannaScore > 0) { //ScoreFlash.Foreground = WordWarLogic.GetFortuneColor(WordWarLogic.ScoreWord()); //ScoreFlash.Text = "Manna +" + ss.MannaScore; //await BeginAsync(ScoreMotionSmall); } if (ss.bonus > 0) { //ScoreFlash.Foreground = WordWarLogic.GetFortuneColor(WordWarLogic.ScoreWord()); //ScoreFlash.Text = "Bonus +" + ss.bonus; //await BeginAsync(ScoreMotionSmall); } if (ss.si != null) { boardScript.ShowMsg("Nice word, you've earned a " + ss.si.FriendlyName + " spell."); } TurnOver(); if (CheckNextLevel(totalScore)) { boardScript.LevelSound(); string levelmsg = "Welcom to Level " + CurrentLevel.ToString() + "\n\n"; if (Spells.HasSpells()) { levelmsg += "You have new spells"; } boardScript.ShowMsg(levelmsg); } boardScript.ScoreWordSound(); } } else { Deselect(null); //CurrentWord.Text = "Not a known word. Try again"; } }
public static void LetterClick(int i, int j) { LetterProp lp = LetterPropGrid[i, j]; //LetterTipPopup.IsOpen = false; if (NextSpell != null) { SpellInfo.SpellOut so = CastSpell(NextSpell, lp); if (so.si == null && so.worked) { if (freeSpell) { Spells.RemoveFoundSpell(NextSpell); } else { ChangeManna(-NextSpell.MannaPoints); } } NextSpell = so.si; } else { if (SelLetterList.Count >= 0) { //string curword = GetCurrentWord().ToLower(); // Check if button is adject to the last if (!(IsLetterAdjacentToLastButton(lp) && !SelLetterList.Contains(lp))) { // Deselect except for the one you just clicked. if (!Deselect(lp)) { lp.SelectorObject = boardScript.SelectLet(lp.I, lp.J); //lp.SetSelected(true); } } else { //lp.SetSelected(true); lp.SelectorObject = boardScript.SelectLet(lp.I, lp.J); } SelLetterList.Add(lp); boardScript.SetCurrentWord(GetCurrentWord() + "\n" + GetWordTally()); // add if for > 3 letters //CurrentWord.Text = GetWordTally(); // if it's a word, update color to green if (SelLetterList.Count > 2 && EngLetterScoring.IsWord(GetCurrentWord())) { boardScript.IndicateGoodWord(true); // if it's a word, remember it. AddToTryList(); } else { boardScript.IndicateGoodWord(false); } } } }
private void FindAllWords(int i, int j, LetterProp lp) { if (CurrentWordFind.Exists(key => (key.i == i && key.j == j))) { return; } CurrentWordFind.Add(new WordElement(i, j, LetterGrid[i, j].letter)); CurWordList.Add(LetterGrid[i, j]); if (CurrentWordFind.Count < 20) { string _curword = CurrentWordString(); if (CurrentWordFind.Count >= 3) { if (EngLetterScoring.IsWord(_curword) && CurrentWordFind.Exists(key => key.i == lp.I && key.j == lp.J)) { Word w = new Word(CurWordList); if (!WordsFromLetter.Contains(w)) { WordsFromLetter.Add(w); } } } if (EngLetterScoring.PartialExists(_curword)) { if (i > 0) { if (j > 0) { FindAllWords(i - 1, j - 1, lp); } FindAllWords(i - 1, j, lp); if (j < WSGameState.gridsize - 1) { FindAllWords(i - 1, j + 1, lp); } } if (j > 0) { FindAllWords(i, j - 1, lp); } if (j < WSGameState.gridsize - 1) { FindAllWords(i, j + 1, lp); } if (i < WSGameState.gridsize - 1) { if (j > 0) { FindAllWords(i + 1, j - 1, lp); } FindAllWords(i + 1, j, lp); if (j < WSGameState.gridsize - 1) { FindAllWords(i + 1, j + 1, lp); } } } } CurrentWordFind.RemoveAt(CurrentWordFind.Count - 1); CurWordList.RemoveAt(CurWordList.Count - 1); }
public bool FindAnyWord(int i, int j) { bool ret = false; if (LetterGridUsed[i, j]) { return(false); } LetterGridUsed[i, j] = true; curword[curwordoff++] = LetterGridByte[i, j]; //Debug.WriteLine(i.ToString() + " " + j.ToString() + " " + CurrentWordString()); if (curwordoff <= 15) { string _curword = new string(curword, 0, curwordoff); if (EngLetterScoring.PartialExists(_curword)) { if (curwordoff >= 3) { if (EngLetterScoring.IsWord(_curword)) { ret = true; } } if (i > 0) { if (j > 0) { if (!ret && FindAnyWord(i - 1, j - 1)) { ret = true; } } if (!ret && FindAnyWord(i - 1, j)) { ret = true; } if (j < WSGameState.gridsize - 1) { if (!ret && FindAnyWord(i - 1, j + 1)) { ret = true; } } } if (j > 0) { if (!ret && FindAnyWord(i, j - 1)) { ret = true; } } if (j < WSGameState.gridsize - 1) { if (!ret && FindAnyWord(i, j + 1)) { ret = true; } } if (i < WSGameState.gridsize - 1) { if (j > 0) { if (!ret && FindAnyWord(i + 1, j - 1)) { ret = true; } } if (!ret && FindAnyWord(i + 1, j)) { ret = true; } if (j < WSGameState.gridsize - 1) { if (!ret && FindAnyWord(i + 1, j + 1)) { ret = true; } } } } } curword[curwordoff] = '\0'; curwordoff--; LetterGridUsed[i, j] = false; return(ret); }
// a z // t z public bool FindAnyWord2(int i, int j) { bool ret = false; if (CurrentWordFind.Exists(key => (key.i == i && key.j == j))) { return(false); } CurrentWordFind.Add(new WordElement(i, j, LetterGrid[i, j].letter)); //Debug.WriteLine(i.ToString() + " " + j.ToString() + " " + CurrentWordString()); if (CurrentWordFind.Count < 15) { string curword = CurrentWordString(); if (EngLetterScoring.PartialExists(curword)) { if (CurrentWordFind.Count >= 3) { if (EngLetterScoring.IsWord(curword)) { ret = true; } } if (i > 0) { if (j > 0) { if (!ret && FindAnyWord(i - 1, j - 1)) { ret = true; } } if (!ret && FindAnyWord(i - 1, j)) { ret = true; } if (j < WSGameState.gridsize - 1) { if (!ret && FindAnyWord(i - 1, j + 1)) { ret = true; } } } if (j > 0) { if (!ret && FindAnyWord(i, j - 1)) { ret = true; } } if (j < WSGameState.gridsize - 1) { if (!ret && FindAnyWord(i, j + 1)) { ret = true; } } if (i < WSGameState.gridsize - 1) { if (j > 0) { if (!ret && FindAnyWord(i + 1, j - 1)) { ret = true; } } if (!ret && FindAnyWord(i + 1, j)) { ret = true; } if (j < WSGameState.gridsize - 1) { if (!ret && FindAnyWord(i + 1, j + 1)) { ret = true; } } } } } CurrentWordFind.RemoveAt(CurrentWordFind.Count - 1); return(ret); }