Пример #1
0
        private async void Signe_Click(object sender, RoutedEventArgs e)
        {
            var  signe = ((Button)sender).Content;
            bool reponse;

            if (signe.Equals("+"))
            {
                reponse = ViewModel.IsOperateurCorrect(OperationEnum.Addition);
            }
            else if (signe.Equals("-"))
            {
                reponse = ViewModel.IsOperateurCorrect(OperationEnum.Soustraction);
            }
            else if (signe.Equals("x"))
            {
                reponse = ViewModel.IsOperateurCorrect(OperationEnum.Multiplication);
            }
            else
            {
                reponse = ViewModel.IsOperateurCorrect(OperationEnum.Division);
            }

            var img = reponse ? new BitmapImage(new Uri(@"ms-appx:///Rsc/img/right.png")) : new BitmapImage(new Uri(@"ms-appx:///Rsc/img/wrong.png"));

            var margin = (int)(GridAffichage.ActualHeight / 2);
            int marginInverse;

            int.TryParse("-" + margin, out marginInverse);
            ViewModel.MarginHaut = marginInverse +
                                   (int)OperationOldTextBlock.ActualHeight;
            ViewModel.MarginCentre = (int)(GridJeu.ActualHeight / 2);

            //animation pour le changement d'opération
            var operation = ViewModel.GenererOperation();

            OperationNewTextBlock.Text = operation;
            ImageResult.Source         = img;
            StoryboardChangeOperation.Begin();
            await Task.Delay(TimeSpan.FromMilliseconds(200));

            StoryboardChangeOperation.Stop();

            ImageOld.Source                = img;
            ImageResult.Source             = null;
            OperationOldTextBlock.Text     = OperationEnCoursTextBlock.Text;
            OperationEnCoursTextBlock.Text = operation;
            OperationNewTextBlock.Text     = "";

            //vérification si le jeu est fini
            if (ViewModel.IsJeuFini() && !_verrouiller)
            {
                _verrouiller = true;
                var res = await ViewModel.CalculResult();

                if (ContextAppli.ContextUtilisateur.ModeJeu.Equals(ModeOuvertureJeuEnum.ModeJeu))
                {
                    CompteAReboursGrid.Visibility = Visibility.Collapsed;
                    GridJeu.Visibility            = Visibility.Collapsed;
                    ScoreGrid.Visibility          = Visibility.Visible;
                    await Score.ChargerResultats(res);
                }

                if (ContextAppli.ContextUtilisateur.ModeJeu.Equals(ModeOuvertureJeuEnum.ModeEval))
                {
                    ContextAppli.ContextUtilisateur.ModeEval.AjouterResultat(res);
                    var exercice = await ContextAppli.ContextUtilisateur.ModeEval.ChangeExerciceEval();

                    //si prochain exercice on l'ouvre
                    if (exercice != null)
                    {
                        exercice.Difficulte = ViewModel.ExerciceEnCours.Difficulte;
                        ((Frame)Window.Current.Content).Navigate(exercice.Page, exercice);
                    }
                    //sinon affichage des stats
                    else
                    {
                        var resEvalFnal = await ContextAppli.ContextUtilisateur.ModeEval.GetResultats();

                        CompteAReboursGrid.Visibility = Visibility.Collapsed;
                        GridJeu.Visibility            = Visibility.Collapsed;
                        ScoreGrid.Visibility          = Visibility.Visible;
                        await Score.ChargerEval(resEvalFnal);
                    }
                }
            }
        }
Пример #2
0
        private async void Ok_Click(object sender, RoutedEventArgs e)
        {
            if (!String.IsNullOrEmpty(ResultatTextBox.Text))
            {
                ImageOld.Source = null;
                int monResultat;
                int.TryParse(ResultatTextBox.Text, out monResultat);

                //vérification du résultat
                var img = ViewModel.VerifierOperation(monResultat) ? new BitmapImage(new Uri(@"ms-appx:///Rsc/img/right.png")) : new BitmapImage(new Uri(@"ms-appx:///Rsc/img/wrong.png"));
                OperationEnCoursTextBlock.Text += ResultatTextBox.Text;
                ResultatTextBox.Text            = "";

                if (_isScreenKey)
                {
                    _isScreenKey = false;
                    ChangeSize();
                }


                var margin = (int)(GridAffichage.ActualHeight / 2);
                int marginInverse;
                int.TryParse("-" + margin, out marginInverse);
                ViewModel.MarginHaut = marginInverse +
                                       (int)OperationOldTextBlock.ActualHeight;
                ViewModel.MarginCentre = (int)(GridJeu.ActualHeight / 2);

                //animation pour le changement d'opération
                var operation = ViewModel.GenererOperation();
                OperationNewTextBlock.Text = operation;
                ImageResult.Source         = img;
                StoryboardChangeOperation.Begin();
                await Task.Delay(TimeSpan.FromMilliseconds(200));

                StoryboardChangeOperation.Stop();

                ImageOld.Source                = img;
                ImageResult.Source             = null;
                OperationOldTextBlock.Text     = OperationEnCoursTextBlock.Text;
                OperationEnCoursTextBlock.Text = operation;
                OperationNewTextBlock.Text     = "";

                //vérification si le jeu est fini
                if (ViewModel.IsJeuFini())
                {
                    var res = await ViewModel.CalculResult();

                    if (ContextAppli.ContextUtilisateur.ModeJeu.Equals(ModeOuvertureJeuEnum.ModeJeu))
                    {
                        CompteAReboursGrid.Visibility = Visibility.Collapsed;
                        GridJeu.Visibility            = Visibility.Collapsed;
                        ScoreGrid.Visibility          = Visibility.Visible;
                        await Score.ChargerResultats(res);
                    }

                    if (ContextAppli.ContextUtilisateur.ModeJeu.Equals(ModeOuvertureJeuEnum.ModeEval))
                    {
                        ContextAppli.ContextUtilisateur.ModeEval.AjouterResultat(res);
                        var exercice = await ContextAppli.ContextUtilisateur.ModeEval.ChangeExerciceEval();

                        //si prochain exercice on l'ouvre
                        if (exercice != null)
                        {
                            exercice.Difficulte = ViewModel.ExerciceEnCours.Difficulte;
                            ((Frame)Window.Current.Content).Navigate(exercice.Page, exercice);
                        }
                        //sinon affichage des stats
                        else
                        {
                            var resEvalFnal = await ContextAppli.ContextUtilisateur.ModeEval.GetResultats();

                            CompteAReboursGrid.Visibility = Visibility.Collapsed;
                            GridJeu.Visibility            = Visibility.Collapsed;
                            ScoreGrid.Visibility          = Visibility.Visible;
                            await Score.ChargerEval(resEvalFnal);
                        }
                    }
                }
            }
        }