public async Task StartGame()
        {
            playerEntry   = "";
            gameCheckGuid = await InternetButton.SubscribeToEventsWithPrefixAsync("SimonSays", GameHandler);

            //if (Device.OS == TargetPlatform.iOS || Device.OS == TargetPlatform.Android)
            if (Device.OS != TargetPlatform.Windows)
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    var notificator = DependencyService.Get <IToastNotificator>();
                    notificator.Notify(ToastNotificationType.Success,
                                       $"{InternetButton.Name} Says:", "Better bring your A game!!", TimeSpan.FromSeconds(1));
                });
            }

            var success = await InternetButton.CallFunctionAsync("startSimon");

            if (success == "Timed out.")
            {
                //if (Device.OS == TargetPlatform.iOS || Device.OS == TargetPlatform.Android)
                if (Device.OS != TargetPlatform.Windows)
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        var notificator = DependencyService.Get <IToastNotificator>();
                        notificator.Notify(ToastNotificationType.Success,
                                           $"{InternetButton.Name} Died", "But I'll come back to life!!", TimeSpan.FromSeconds(1));
                    });
                }
            }
            gameRunning = true;

            await Task.Delay(500);

            var simonParticle = await InternetButton.GetVariableAsync("simon");

            simonMoves = simonParticle.Result.ToString();

            Random rand = new Random();

            for (var i = 0; i < 10; i++)
            {
                gameId += rand.Next(0, 9);
            }
        }
Exemple #2
0
        async Task PerformAction()
        {
            if (!gameRunning)
            {
                //Start game
                gameRunning = true;
                OnPropertyChanged("ActionText");
                OnPropertyChanged("ActionColor");
                await StartGame();
            }
            else
            {
                var result = await InternetButton.CallFunctionAsync("buttonPress", playerEntry);

                if (Device.OS == TargetPlatform.iOS || Device.OS == TargetPlatform.Android)
                {
                    if (result == "1")
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            var notificator = DependencyService.Get <IToastNotificator>();
                            notificator.Notify(ToastNotificationType.Success,
                                               $"{InternetButton.Name} Says:", "You got that one right....", TimeSpan.FromSeconds(2));
                        });
                    }
                    else if (result == "-1")
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            var notificator = DependencyService.Get <IToastNotificator>();
                            notificator.Notify(ToastNotificationType.Warning,
                                               $"{InternetButton.Name} Says:", "Don't interrupt my masterpiece!!!", TimeSpan.FromSeconds(1));
                        });
                    }
                }

                ClearPlayerEntry();
            }
        }