Esempio n. 1
0
        /// <summary>
        /// Starts the multiplication game and starts the timer. displays the first question.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmdStartGameMultiplication(object sender, RoutedEventArgs e)
        {
            PlayGameViewModel pgw = (PlayGameViewModel)this.DataContext;

            pgw.StartTimer();
            pgw.DisplayQuestion();
        }
Esempio n. 2
0
        /// <summary>
        /// close button that brings the main window back to the screen
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmdCloseAdditionGame(object sender, RoutedEventArgs e)
        {
            PlayGameViewModel pgw = (PlayGameViewModel)this.DataContext;

            pgw.ResetTimer();
            this.Close();
            Application.Current.MainWindow.BringIntoView();
        }
Esempio n. 3
0
        public PlayGamePage(string gameId)
        {
            _gameId = gameId;
            InitializeComponent();

            _vm            = App.IOC.PlayGame;
            BindingContext = _vm;
        }
Esempio n. 4
0
        /// <summary>
        /// Check and display answer method. This method determines whether the game is over based on the question number the user is on. plays a sound if the answer is right
        /// or plays a sound if the answer is wrong. after the game is over pushes the data into the high scores window. resets the time and the current question number
        /// shows the high score window dialog. calls the check answer function to see if the answer is right or wrong and increment the appropriate variables. Shows a message
        /// box if the user made it to the top 10 highest scores or not. removes the bottom user from the list if more 10 or more and a new high score is added
        /// displays the next question.
        /// </summary>
        private void checkAndDisplayAnswer()
        {
            PlayGameViewModel       pgw  = (PlayGameViewModel)this.DataContext;
            QuestionResultViewModel qrvm = new QuestionResultViewModel(pgw.QuestionResults.Count + 1);



            this.product.Text = String.Empty;
            if (pgw.currentQuestionNumber >= pgw.maximumQuestionNumber)
            {
                pgw.QuestionResults.Add(qrvm);
                pgw.checkAnswer();


                SoundPlayer answerRight = new SoundPlayer("highScores.wav");
                answerRight.Play();
                EnterUserDataViewModel   eudv = ((MainWindowViewModel)Application.Current.MainWindow.DataContext).EnterUserDataVM;
                HighScoreWindowViewModel hsvw = ((MainWindowViewModel)Application.Current.MainWindow.DataContext).HighScoreWindowVM;
                pgw.StopTimer();
                HighScoresWindow hsw = new HighScoresWindow();
                hsw.DataContext = ((MainWindowViewModel)Application.Current.MainWindow.DataContext).HighScoreWindowVM;
                if (hsvw.HighScores.Count() >= 10 && pgw.QuestionResults.Count(x => x.IsCorrect == true) <= hsvw.HighScores.ToArray()[9].CorrectAnswers)
                {
                    MessageBox.Show("I am sorry, but you did not make it to the top 10 highest scores. Please click OK to advance to the High Score Screen.");
                }
                else
                {
                    if (hsvw.HighScores.Count() < 10)
                    {
                        hsvw.HighScoresAdd(eudv.TheCurrentUser.UserName, pgw.QuestionResults.Count(x => x.IsCorrect == true), pgw.QuestionResults.Count(x => x.IsCorrect == false), pgw.gameTime);
                        MessageBox.Show("Congratulations! You made it to the top 10 highest scores! Please click OK to view your score and compare it to the other top 10 players.");
                    }
                    else
                    {
                        hsvw.HighScores.Remove(hsvw.HighScores.ToArray()[9]);
                        hsvw.HighScoresAdd(eudv.TheCurrentUser.UserName, pgw.QuestionResults.Count(x => x.IsCorrect == true), pgw.QuestionResults.Count(x => x.IsCorrect == false), pgw.gameTime);
                        MessageBox.Show("Congratulations! You made it to the top 10 highest scores! Please click OK to view your score and compare it to the other top 10 players.");
                    }
                }
                pgw.ResetTimer();

                pgw.currentQuestionNumber = 0;
                pgw.Product = 0;
                pgw.QuestionResults.Clear();
                hsw.ShowDialog();
                this.Close();
                return;
            }
            pgw.QuestionResults.Add(qrvm);
            pgw.checkAnswer();
            pgw.DisplayQuestion();
        }
Esempio n. 5
0
        public ActionResult StartGame(PlayIndexViewModel model)
        {
            List <Player> players = new List <Player>();

            foreach (var playerName in model.Players)
            {
                players.Add(new Player(playerName));
            }

            PlayGameViewModel gameModel = new PlayGameViewModel(players);

            return(View("Game", gameModel));
        }
        /// <summary>
        /// The method that is ran when the user is choosing their game type. WHen the user chooses the game type and hits submit, this method
        /// brings the appropriate game window up.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmdSelectGameTypeSubmit_Click(object sender, RoutedEventArgs e)
        {
            MainWindow          mw   = (MainWindow)Application.Current.MainWindow;
            MainWindowViewModel mwvm = (MainWindowViewModel)mw.DataContext;
            PlayGameViewModel   pgw  = (((MainWindowViewModel)Application.Current.MainWindow.DataContext).PlayGameWindowVM);

            pgw.IsGameStarted = false;
            Window theWindow = null;

            if (this.cmbSelectedGame.SelectedValue == Enum.GetName(typeof(GameTypesEnum), GameTypesEnum.Addition))
            {
                theWindow = new AdditionGameWindow();
                mwvm.PlayGameWindowVM.DesiredGameType = GameTypesEnum.Addition;
            }
            else if (this.cmbSelectedGame.SelectedValue == Enum.GetName(typeof(GameTypesEnum), GameTypesEnum.Subtraction))
            {
                theWindow = new SubtractionGameWindow();
                mwvm.PlayGameWindowVM.DesiredGameType = GameTypesEnum.Subtraction;
            }
            else if (this.cmbSelectedGame.SelectedValue == Enum.GetName(typeof(GameTypesEnum), GameTypesEnum.Multiplication))
            {
                theWindow = new MultiplicationGameWindow();
                mwvm.PlayGameWindowVM.DesiredGameType = GameTypesEnum.Multiplication;
            }
            else if (this.cmbSelectedGame.SelectedValue == Enum.GetName(typeof(GameTypesEnum), GameTypesEnum.Division))
            {
                theWindow = new DivisionGameWindow();
                mwvm.PlayGameWindowVM.DesiredGameType = GameTypesEnum.Division;
            }
            if (theWindow == null)
            {
                return;
            }

            //Closes the window select game window and brings the appropriate game window into view.
            Button btn  = (Button)sender;
            Grid   grid = (Grid)btn.Parent;
            SelectGameTypeWindow sgw = (SelectGameTypeWindow)grid.Parent;

            theWindow.DataContext = mwvm.PlayGameWindowVM;
            sgw.Close();
            theWindow.ShowDialog();
            mw.Show();
            mw.BringIntoView();
        }
Esempio n. 7
0
        public ActionResult Play(int gameId)
        {
            var game = _db.Games.FirstOrDefault(g => g.Id == gameId);

            if (game == null)
            {
                return(RedirectToAction("Index"));
            }
            PlayGameViewModel data = new PlayGameViewModel
            {
                Game       = game,
                User       = CurrentUser,
                GameOrders = game.GameOrders.OrderByDescending(o => o.CreateTime).ToList()
            };

            ViewBag.IsLogin = CurrentUser != null;
            return(View(data));
        }
Esempio n. 8
0
        /// <summary>
        /// On closing the main window, pulls all data from the high scores window into a TXT file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            MainWindowViewModel      mwvm = (MainWindowViewModel)this.DataContext;
            PlayGameViewModel        pgw  = (((MainWindowViewModel)Application.Current.MainWindow.DataContext).PlayGameWindowVM);
            HighScoreWindowViewModel hsvw = ((MainWindowViewModel)Application.Current.MainWindow.DataContext).HighScoreWindowVM;

            using (System.IO.StreamWriter file = new System.IO.StreamWriter("HighScoresTest.txt"))
            {
                //foreach loop that finds all of the appropriate information from the high screen window and loads it into the txt file
                foreach (HighScoreViewModel highScore in hsvw.HighScores)
                {
                    string[] lines = { "User Name", "Correct Answers", "Incorrect Answers", "Time" };
                    file.WriteLine(highScore.UserName);
                    file.WriteLine(highScore.CorrectAnswers);
                    file.WriteLine(highScore.IncorrectAnswers);
                    file.WriteLine(string.Format("{0}:{1}:{2}", highScore.CompletionTime.Minutes, highScore.CompletionTime.Seconds, highScore.CompletionTime.Milliseconds));
                }
            }
        }
Esempio n. 9
0
 public play301Page(int game)
 {
     InitializeComponent();
     viewModel           = new PlayGameViewModel(game);
     this.BindingContext = viewModel;
 }
Esempio n. 10
0
        // GET: PlayGame
        public ActionResult Index()
        {
            PlayGameViewModel model = new PlayGameViewModel();

            return(View(model));
        }