public WordSearchPage(Defines.GameDifficulty level, double width, double height) { InitializeComponent(); Rows = 0; Columns = 0; InitalizeHeaderAndTiles(level, width, height); }
// put words in tiles private bool PlaceWordsInTiles(int maxWordLength, Defines.GameDifficulty difficulty, int totalWords) { bool bOK = true; try { // load words database var wordDb = new WordDatabase(); bOK = wordDb.LoadWordsDB(difficulty); Debug.Assert(bOK); if (!bOK) { return(false); } int count = 0; int tries = 0; var filterList = new List <string>(); while (count < totalWords && tries < Defines.MAX_RANDOM_TRIES) { string text; bOK = wordDb.GetNextRandomWord(maxWordLength, filterList, out text); Debug.Assert(bOK); if (bOK) { // create word object Word word = new Word(text); // select a random direction and position bOK = SelectRandomPose(ref word); Debug.Assert(bOK); if (bOK) { bOK = word.CalculateTilePositions(); Debug.Assert(bOK); if (bOK) { // found next word that fits ok filterList.Add(text); Debug.WriteLine($"PlaceWordsInTiles adding word {text}"); lock (WordsLock) { Words.Add(word); } count++; tries = 0; } } } tries++; } } catch (Exception ex) { Logger.Instance.Error($"PlaceWordsInTiles exception, {ex.Message}"); bOK = false; } return(bOK); }
public Word(string text) { TilePositions = null; Text = text; Row = 0; Column = 0; IsWordCompleted = false; IsWordHidden = false; WordDifficulty = Defines.GameDifficulty.easy; }
// Initialize tiles private bool InitalizeHeaderAndTiles(Defines.GameDifficulty level, double width, double height) { bool bOK = true; try { // Check if sound is on SoundSettingIsOn = Preferences.Get("soundOn", true); ScorePenaltyWarned = false; // Create word manager Manager = new WordManager(); Manager.DifficultyLevel = level; // set up WordManager delegate events Manager.GameCompletedCallback += OnGameCompletedCallbackAsync; Manager.WordCompletedCallback += OnWordCompletedCallbackAsync; // Databinding int secondsRemaining = Manager.GetStartSecondsRemaining(); int points = Manager.GetPointsPerLetter(); BindingContext = new WordSearchPageViewModel(Navigation, secondsRemaining, points, webViewHeader, webViewTiles); // Html callbacks webViewHeader.RegisterAction(HeaderJSCallback); webViewTiles.RegisterAction(TilesJSCallback); // Set sizes ScreenWidth = width; ScreenHeight = height; TilesScreenHeight = height - Defines.HEADER_HTML_HEIGHT; ViewModel.HtmlPageWidth = width; ViewModel.HtmlHeaderPageHeight = 100; double wordHeight = height - 100; ViewModel.HtmlTilePageHeight = wordHeight; Task.Run(() => { CalculateTiles(); LoadWordsTiles(); LoadWordsHeader(); }); // xamarin essentials screen lock if (!ScreenLock.IsActive) { ScreenLock.RequestActive(); } } catch (Exception ex) { Logger.Instance.Error($"InitalizeHeaderAndTiles exception, {ex.Message}"); bOK = false; } return(bOK); }
// Load words database into memory public bool LoadWordsDB(Defines.GameDifficulty difficulty) { bool bOK = false; try { bOK = Word.LoadRecords(difficulty, out List <Word> results); Debug.Assert(bOK); if (bOK) { WordList = new List <Word>(results); } } catch (Exception ex) { Logger.Instance.Error($"LoadWordsDB exception, {ex.Message}"); } return(bOK); }
// Load all records with a difficulty filter. public static bool LoadRecords(Defines.GameDifficulty difficulty, out List <Word> results) { results = null; bool bOK = true; try { using (var db = new DbContextWords()) { db.Database.EnsureCreated(); results = (from item in db.Words where item.WordDifficulty <= difficulty orderby item ascending select item).ToList(); } } catch (Exception ex) { Debug.WriteLine($"LoadRecords exception {ex.Message}"); bOK = false; } return(bOK); }