private void GameExit(object sender, EventArgs e) { this._currentGame.GameExit -= GameExit; InputDialog dia = new InputDialog(); InputDialogViewModel diavm = new InputDialogViewModel(dia); dia.DataContext = diavm; diavm.CloseDialog += CloseDialog; dia.ShowDialog(); if (diavm.result == true) { String name = dia.Input.Text; if ((int)this._currentGame.P1.Score > (int)this._currentGame.P2.Score) { LeaderboardEntry board = new LeaderboardEntry(); board.UserName = name; board.GameType = GameTypes.TicTacToe; board.Date = DateTime.Now; board.GameSessionId = "session1"; board.Score = (int)this._currentGame.P1.Score; _store.AddLeaderboardEntryAsync(board); } else { LeaderboardEntry board = new LeaderboardEntry(); board.UserName = name; board.GameType = GameTypes.TicTacToe; board.Date = DateTime.Now; board.GameSessionId = "session1"; board.Score = (int)this._currentGame.P2.Score; _store.AddLeaderboardEntryAsync(board); } } this._currentGame.CloseWindow(); this._currentGame = null; _window.Show(); }
public static void GetAllTimeLeaders(IScoreStore store) { var entries = Mocks.Older.Concat(Mocks.Today).Concat(Mocks.Yesterday); foreach (var mock in entries) { Task.Run(() => store.AddLeaderboardEntryAsync(mock)).Wait(); } var leaders = Task.Run(() => store.GetLeaderboardAsync(GameTypes.TicTacToe, Scopes.AllTime)); leaders.Wait(); Assert.IsTrue(leaders.Result.ToList().SequenceEqual(entries.ToList().OrderByDescending(l => l.Score), new LeaderboardEntryCsvComparer())); }