Ejemplo n.º 1
0
        private async Task finish_fun(int answer)
        {
            if (answer == 2) // results
            {
                List <Number> results = new List <Number>();
                for (int i = 0; i < FlexL.Children.Count; i++)
                {
                    results.Add((Number)SwipeCardView.ItemsSource[i]);
                    LastNumber = (Number)SwipeCardView.ItemsSource[i];
                }
                BindingContext = new TinderPageViewModel(results);
                SwipeCardView.SupportedDraggingDirections = SwipeCardDirection.Left;
                SwipeCardView.SupportedSwipeDirections    = SwipeCardDirection.Left;

                nopeVisible = false;
            }
            else if (answer == 0) // play again
            {
                BindingContext = new TinderPageViewModel();
                MyAnimationView.PlayProgressSegment(0, 1);
                timer = sec15;
                stopwatch.Restart();
                FlexL.Children.Clear();
                finished    = false;
                nopeVisible = true;
                SwipeCardView.SupportedDraggingDirections = SupportedDraggingDirections;
                SwipeCardView.SupportedSwipeDirections    = SupportedSwipingDirections;
            }
            else if (answer == 1) // quit
            {
                await Navigation.PopAsync();

                finished = false;
            }
        }
Ejemplo n.º 2
0
        private async void OnSwiping(object sender, SwipedCardEventArgs e)
        {
            if (finished)
            {
                if (!nopeVisible)
                {
                    if (((Number)e.Item).Id == LastNumber.Id)
                    {
                        bool answer = await DisplayAlert("Next game?", "Play another game?", "Yes", "No");

                        if (answer)
                        {
                            await  finish_fun(0);
                        }
                        else
                        {
                            await finish_fun(1);
                        }
                    }
                }
                return;
            }
            uint timeout = 50;

            if ((e.Direction == SwipeCardDirection.Left && !((Number)e.Item).Prime)
                ||
                (e.Direction == SwipeCardDirection.Right && ((Number)e.Item).Prime))
            {
                ((Number)e.Item).Correct = true;


                ViewModel.ViewExtensions.CancelAnimation(MyStack);
                MyStack.ColorTo(Color.Green, Color.White, c => MyStack.BackgroundColor = c, 500);
                var v = new AnimationView();
                v.Animation     = "4964-check-mark-success-animation.json";
                v.IsPlaying     = true;
                v.WidthRequest  = 25;
                v.HeightRequest = 25;


                FlexL.Children.Add(v);

                timer = Math.Min(sec15, timer - stopwatch.Elapsed.TotalMilliseconds + 1000);
                var segment = (float)Math.Min(1, 1 - (timer) / sec15);
                MyAnimationView.PlayProgressSegment((float)segment, 1);
                stopwatch.Restart();
            }
            else if ((e.Direction == SwipeCardDirection.Left && ((Number)e.Item).Prime)
                     ||
                     (e.Direction == SwipeCardDirection.Right && !((Number)e.Item).Prime))
            {
                ((Number)e.Item).Correct = false;
                ViewModel.ViewExtensions.CancelAnimation(MyStack);
                MyStack.ColorTo(Color.Red, Color.White, c => MyStack.BackgroundColor = c, 500);
                await MyStack.TranslateTo(-15, 0, timeout);

                await MyStack.TranslateTo(15, 0, timeout);

                await MyStack.TranslateTo(-9, 0, timeout);

                await MyStack.TranslateTo(9, 0, timeout);

                await MyStack.TranslateTo(-5, 0, timeout);

                await MyStack.TranslateTo(5, 0, timeout);

                await MyStack.TranslateTo(-2, 0, timeout);

                await MyStack.TranslateTo(2, 0, timeout);

                MyStack.TranslationX = 0;

                var v = new AnimationView();
                v.Animation     = "4970-unapproved-cross.json";
                v.IsPlaying     = true;
                v.WidthRequest  = 25;
                v.HeightRequest = 25;

                timer = Math.Max(0, timer - stopwatch.Elapsed.TotalMilliseconds - 2000);
                var segment = (float)Math.Min(1, 1 - (timer) / sec15);
                MyAnimationView.PlayProgressSegment((float)segment, 1);
                stopwatch.Restart();


                FlexL.Children.Add(v);
            }
            else if (e.Direction == SwipeCardDirection.Up)
            {
                ViewModel.ViewExtensions.CancelAnimation(MyStack);
                MyStack.ColorTo(Color.Yellow, Color.White, c => MyStack.BackgroundColor = c, 500);

                var v = new AnimationView();
                v.Animation     = "4975-question-mark.json";
                v.IsPlaying     = true;
                v.WidthRequest  = 25;
                v.HeightRequest = 25;


                FlexL.Children.Add(v);
            }
        }