コード例 #1
0
        public async Task <bool> AddCompletedGameAsync(CompletedGame game)
        {
            try
            {
                await initializedTask;

                await connection.InsertAsync(game);

                var stats = await connection.FindAsync <GameStatistic>(game.Board);

                stats = stats ?? new GameStatistic {
                    Board = game.Board
                };
                stats.PlayCount++;
                await connection.InsertOrReplaceAsync(stats);

                return(true);
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);

                return(false);
            }
        }
コード例 #2
0
        private async void OnMakeMove(string indexString)
        {
            if (State == GameState.GameOver)
            {
                return;
            }

            if (!int.TryParse(indexString, out var index))
            {
                return;
            }
            if (index < 0 || index >= Board.Length)
            {
                return;
            }

            if (Board[index] != Player.Nobody)
            {
                return;
            }

            Board[index] = CurrentPlayer;
            OnPropertyChanged(nameof(Board));

            var possible = DetectGameOver();

            if (possible != null)
            {
                // there was a winner or a tie
                Winner        = possible.Value.Winner;
                State         = GameState.GameOver;
                CurrentPlayer = Player.Nobody;

                // add the result to the board
                foreach (var pos in possible.Value.Positions)
                {
                    Board[pos] |= Player.IsWinner;
                }
                OnPropertyChanged(nameof(Board));

                // create the game object that we will use
                var game = CompletedGame.Create(Board, Winner);

                // upload this game to the server
                await database.AddCompletedGameAsync(game);

                // download the stats for this board
                BoardPlayCount = await database.GetGamePlayCountAsync(game.Board);
            }
            else
            {
                // we are still going
                State         = GameState.InProgress;
                CurrentPlayer = CurrentPlayer == Player.X
                                        ? Player.O
                                        : Player.X;
            }
        }
コード例 #3
0
        public async Task <bool> AddCompletedGameAsync(CompletedGame game)
        {
            // cache the game locally
            if (!await localDatabase.AddCompletedGameAsync(game))
            {
                return(false);
            }

            // make sure to upload all the cached games
            await UploadCachedGamesAsync();

            return(true);
        }
コード例 #4
0
        public async Task <bool> AddCompletedGameAsync(CompletedGame game)
        {
            try
            {
                await initializedTask;

                await client.CreateDocumentAsync(collection, game);

                return(true);
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);

                return(false);
            }
        }