//This handles the Entity database setup. private async void InitialiseScore() { var dbFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); var fileName = "scores.db"; dbFullPath = System.IO.Path.Combine(dbFolder, fileName); try { using (var db = new ScoreContext(dbFullPath)) { await db.Database.MigrateAsync(); await db.SaveChangesAsync(); } DrawScores(); } catch (Exception ex) { Log.Info("Hangman", ex.ToString()); Toast.MakeText(this, ex.ToString(), ToastLength.Long).Show(); } }
// this one redraws the Score board private void DrawScores() { string[] scores; using (var db = new ScoreContext(dbFullPath)) { scores = db.Scores.Select(a => $"{a.Word} - {a.Value}").ToArray(); scoreView.Adapter = new ArrayAdapter <String>(this, Android.Resource.Layout.SimpleListItem1, scores); } }
// This builds the lambda (which is basically the game loop) for all the key presses. private void InitialiseImage() { foreach (var button in Buttons) { button.Value.Click += async(sender, ea) => { Game.Guess(button.Key); Draw(); button.Value.Enabled = false; var state = Game.CheckState(); if (state == Game.State.WIN) { Draw(); using (var db = new ScoreContext(dbFullPath)) { db.Scores.Add(new Score() { Word = Game.Answer, Value = Game.Score() }); await db.SaveChangesAsync(); } WinDialog(); DrawScores(); Game.NewGame(); } else if (state == Game.State.LOSS) { LoseDialog(Game.Answer); Game.NewGame(); Draw(); } else { Draw(); } }; } }