Ejemplo n.º 1
0
        async Task InsertWinner(int winner)
        {
            var  winnerName = string.Empty;
            bool isDraw     = false;
            var  date       = DateTime.UtcNow;

            switch (winner)
            {
            case 0:
                isDraw = true;

                await UserDialogs.Instance.AlertAsync("Empate! Lo hemos guardado en historial. Presiona resetear para comenzar uno nuevo.", "Game over!");

                break;

            case 1:
                winnerName = Settings.Player1;
                await UserDialogs.Instance.AlertAsync($"{Settings.Player1} Ganó el juego! Lo hemos guardado en historial. Presiona resetear para comenzar uno nuevo.", $"{Settings.Player1} Ganó!");

                break;

            case 2:
                winnerName = Settings.Player2;
                await UserDialogs.Instance.AlertAsync($"{Settings.Player2} Ganó el juego! Lo hemos guardado en historial. Presiona resetear para comenzar uno nuevo.", $"{Settings.Player2} Ganó!");

                break;
            }

            Analytics.TrackEvent("GameFinished", new Dictionary <string, string>
            {
                ["Winner"] = winner == 1 ? "X" : winner == 2 ? "O" : "Draw",
                ["Moves"]  = Moves.ToString()
            });

            var game = new Game
            {
                Winner  = winnerName,
                Player1 = Settings.Player1,
                Player2 = Settings.Player2,
                DateUtc = date,
                IsDraw  = isDraw,
                Moves   = Moves
            };

            var progress = UserDialogs.Instance.Loading("Guardando juego...", maskType: MaskType.Gradient);

            try
            {
                IsBusy = true;
                await DependencyService.Get <AzureService>().Add(game);
            }
            catch
            {
            }
            finally
            {
                progress.Hide();
                IsBusy = false;
            }
        }
Ejemplo n.º 2
0
        async Task InsertWinner(int winner)
        {
            var  winnerName = string.Empty;
            bool isDraw     = false;
            var  date       = DateTime.UtcNow;

            switch (winner)
            {
            case 0:
                isDraw = true;

                await UserDialogs.Instance.AlertAsync("Game is a draw! Game has been recorded. Hit reset to start a new game.", "Draw!");

                break;

            case 1:
                winnerName = Settings.Player1;
                await UserDialogs.Instance.AlertAsync($"{Settings.Player1} won this game! Game has been recorded. Hit reset to start a new game.", $"{Settings.Player1} Wins!");

                break;

            case 2:
                winnerName = Settings.Player2;
                await UserDialogs.Instance.AlertAsync($"{Settings.Player2} won this game! Game has been recorded. Hit reset to start a new game.", $"{Settings.Player2} Wins!");

                break;
            }

            Analytics.TrackEvent("GameFinished", new Dictionary <string, string>
            {
                ["Winner"] = winner == 1 ? "X" : winner == 2 ? "O" : "Draw",
                ["Moves"]  = Moves.ToString()
            });

            var game = new Game
            {
                Winner  = winnerName,
                Player1 = Settings.Player1,
                Player2 = Settings.Player2,
                DateUtc = date,
                IsDraw  = isDraw,
                Moves   = Moves
            };

            var progress = UserDialogs.Instance.Loading("Saving game...", maskType: MaskType.Gradient);

            try
            {
                IsBusy = true;
                await DependencyService.Get <AzureService>().Add(game);
            }
            catch
            {
            }
            finally
            {
                progress.Hide();
                IsBusy = false;
            }
        }