/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.</param> async protected override void OnNavigatedTo(NavigationEventArgs e) { Global.Logger = await TextBlockLogger.Create(Log, ScrollLog); Game.NewGame(asciipaint => Table.Text = asciipaint); Table.Focus(Windows.UI.Xaml.FocusState.Programmatic); while (true) { var game = Game.Instance(); bool killed = await game.Play(); if (!killed) { //should await a keypress instead of 10 seconds await Task.Delay(10000); Game.NewGame(asciipaint => Table.Text = asciipaint); } } }
async void GameTable_KeyDown(object sender, KeyRoutedEventArgs e) { Game.Instance().Input(e.Key); if (e.Key == Windows.System.VirtualKey.S) { var localFolder = ApplicationData.Current.LocalFolder; //wipe the file? var file = await localFolder.CreateFileAsync("dominoes.json", CreationCollisionOption.ReplaceExisting); Game.Save(file.OpenStreamForWriteAsync().Result); Global.Logger.Comment("Saved game to " + file.Path); } if (e.Key == Windows.System.VirtualKey.L) { var localFolder = ApplicationData.Current.LocalFolder; var file = await localFolder.GetFileAsync("dominoes.json"); Game.Load(file.OpenStreamForReadAsync().Result, asciipaint => Table.Text = asciipaint); Global.Logger.Comment("Loaded game from " + file.Path); } }
public static void Save(System.IO.Stream stream) { serializer.WriteObject(stream, Game.Instance()); }