Esempio n. 1
0
 /// <summary>
 /// Evenement d'arret du jeu en cours
 /// Enregistre le score et lance la fenetre de défi
 /// </summary>
 /// <param name="idUser"></param>
 /// <param name="idGame"></param>
 /// <param name="idDefi"></param>
 /// <param name="points"></param>
 void GamePanel_EndOfGameEvent(int idUser, int idGame, int idDefi, int points)
 {
     Datas.Score s = new Datas.Score()
     {
         idGame = idGame, idUser = idUser, value = points
     };
     Bdd.DbAccess.AddToScores(s);
     Bdd.DbAccess.SaveChanges();
     if (idDefi != -1)
     {
         if (s != null)
         {
             Datas.Dual d = (from i in Bdd.DbAccess.Duals where i.ID == idDefi select i).FirstOrDefault();
             if (d != null)
             {
                 d.idScoreChallenged = s.ID;
                 Bdd.DbAccess.SaveChanges();
                 int idChallenger    = d.idChallenger;
                 int scoreChallenger = (int)(from i in Bdd.DbAccess.Scores where d.idScoreChallenger == i.ID select i.value).FirstOrDefault();
                 if (s.value >= scoreChallenger)
                 {
                     d.winner = App.user.ID;
                 }
                 else
                 {
                     d.winner = idChallenger;
                 }
                 Bdd.DbAccess.SaveChanges();
             }
         }
     }
     this.contentGrid.Children.Remove(this.currentUIElement);
     this.currentUIElement = new ChallengeResults(idUser, idGame, idDefi, s.ID);
     this.contentGrid.Children.Add(this.currentUIElement);
 }
        /// <summary>
        /// Lance le jeu du défi selectionné
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Cb_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            ChallengeButton s = sender as ChallengeButton;

            if (s.Tag != null)
            {
                Datas.Dual d    = s.Tag as Datas.Dual;
                Datas.Game game = (from i in Bdd.DbAccess.Games where d.idGame == i.ID select i).FirstOrDefault();
                try
                {
                    if (game.className == "QuestionaryControl")
                    {
                        int id = (int)game.idQuestionary;
                        App.mainWindow.LaunchGame(new QuestionaryControl(App.user.ID, game.ID, d.ID, id));
                    }
                    else
                    {
                        Type   game1 = Type.GetType("EducationAll.Games." + game.className);
                        object o     = Activator.CreateInstance(game1, App.user.ID, game.ID, d.ID);
                        App.mainWindow.LaunchGame(o as IGame);
                    }
                }
                catch (Exception)
                {
                    ErrorWindow wd = new ErrorWindow(false);
                    wd.Owner = App.mainWindow;
                    wd.ShowDialog();
                }
            }
        }
        public ChallengeResults(int idUser, int idGame, int idDefi, int idScore)
        {
            InitializeComponent();
            this.idGame  = idGame;
            this.idUser  = idUser;
            this.idScore = idScore;
            if (idDefi == -1)//il n'y a pas de défi donc on redirige directement vers la liste d'amis pour prochain défi
            {
                this.Bcontinue_Click(null, null);
                return;
            }
            try
            {
                this.dual = (from i in Bdd.DbAccess.Duals where i.ID == idDefi select i).FirstOrDefault();
            }
            catch (Exception)
            {
                this.Error();
                return;
            }
            if (this.dual == null)
            {
                this.Error();
                return;
            }
            this.points            = (int)(from i in Bdd.DbAccess.Scores where i.ID == idScore select i.value).FirstOrDefault();;
            this.lGameName.Content = (from i in Bdd.DbAccess.Games where i.ID == idGame select i.name).FirstOrDefault();
            string nameWinner = (from i in Bdd.DbAccess.Users where i.ID == this.dual.winner select i.username).FirstOrDefault();
            string nameLoser;

            if (this.dual.idChallenged == this.dual.winner)
            {
                nameLoser = (from i in Bdd.DbAccess.Users where i.ID == this.dual.idChallenger select i.username).FirstOrDefault();
            }
            else
            {
                nameLoser = (from i in Bdd.DbAccess.Users where i.ID == this.dual.idChallenged select i.username).FirstOrDefault();
            }
            int pointsChallenger;

            int.TryParse(((from i in Bdd.DbAccess.Scores where i.ID == this.dual.idScoreChallenger select i.value).FirstOrDefault()).ToString(), out pointsChallenger);
            this.lResultWin.Content = nameWinner + " gagne !";
            if (this.dual.winner == idUser && pointsChallenger != points)
            {
                this.lResult.Content = "Félicitations !";
            }
            else if (this.dual.winner != idUser && pointsChallenger != points)
            {
                this.lResult.Content = "Dommage !";
            }
            else if (pointsChallenger == points)
            {
                this.lResult.Content    = "Bien joué !";
                this.lResultWin.Content = "Egalité";
            }
            this.Display();
        }
Esempio n. 4
0
        void Bt_Click(object sender, RoutedEventArgs e)
        {
            Button b = sender as Button;

            Datas.Dual d = new Datas.Dual();
            d.idChallenger      = this.idUser;
            d.idChallenged      = (int)b.Tag;
            d.idGame            = this.idGame;
            d.idScoreChallenger = this.idScore;
            d.date = DateTime.Now;
            Bdd.DbAccess.AddToDuals(d);
            Bdd.DbAccess.SaveChanges();
            this.EndOfNewChallenge();
        }