Advertisement
nemory

MainPage.cs

Aug 16th, 2012
665
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 29.44 KB | None | 0 0
  1. private String resultToShare = "";
  2.         private String lastTrailers = "";
  3.         private String lastSongs = "";
  4.  
  5.         private Boolean isImagesFinished = false;
  6.         private Boolean isTrailersFinished = false;
  7.         private Boolean isSongsFinished = false;
  8.  
  9.         private Boolean hasStarted_Images = false;
  10.         private Boolean hasStarted_Trailers = false;
  11.         private Boolean hasStarted_Songs = false;
  12.  
  13.         private int corrected_Images = 0;
  14.         private int corrected_Trailers = 0;
  15.         private int corrected_Songs = 0;
  16.  
  17.         private int totalTimeElapsed_Images = 0;
  18.         private int totalTimeElapsed_Trailers = 0;
  19.         private int totalTimeElapsed_Songs = 0;
  20.  
  21.         private int seconds_Images = 0;
  22.         private int seconds_Trailers = 0;
  23.         private int seconds_Songs = 0;
  24.  
  25.         private int totalQuestions_Images = 0;
  26.         private int totalQuestions_Trailers = 0;
  27.         private int totalQuestions_Songs = 0;
  28.        
  29.  
  30.         private List<Question> questions_Images = new List<Question>();
  31.         private Question currentQuestion_Images = new Question();
  32.  
  33.         private List<Question> questions_Trailers = new List<Question>();
  34.         private Question currentQuestion_Trailers = new Question();
  35.  
  36.         private List<Question> questions_Songs = new List<Question>();
  37.         private Question currentQuestion_Songs = new Question();
  38.  
  39.         private System.Windows.Threading.DispatcherTimer timer_Images;
  40.         private System.Windows.Threading.DispatcherTimer timer_Trailers;
  41.         private System.Windows.Threading.DispatcherTimer timer_Songs;
  42.  
  43.         private SoundEffect correctSound, wrongSound;
  44.  
  45.         MessagePrompt gameFinished;
  46.  
  47.         public PivotPage()
  48.         {
  49.             InitializeComponent();
  50.  
  51.             FrameworkDispatcher.Update();
  52.  
  53.             this.LoadSound("correct.wav", out correctSound);
  54.             this.LoadSound("wrong.wav", out wrongSound);
  55.  
  56.             this.initialize_Images();
  57.             this.initialize_Trailers();
  58.             this.initialize_Songs();
  59.             this.startImages();
  60.         }
  61.  
  62.         void messagePromptImages_Completed(object sender, PopUpEventArgs<String, PopUpResult> e)
  63.         {
  64.             seconds_Images = 0;
  65.             if (questions_Images.Count > 0)
  66.             {
  67.                 questions_Images.RemoveAt(0);
  68.                 if (questions_Images.Count > 0)
  69.                 {
  70.                     this.nextQuestion_Images();
  71.                     timer_Images.Start();
  72.                 }
  73.                 else
  74.                 {
  75.                     this.stopImages();
  76.                 }
  77.             }
  78.             else
  79.             {
  80.                 this.stopImages();
  81.             }
  82.         }
  83.  
  84.         void messagePromptSongs_Completed(object sender, PopUpEventArgs<String, PopUpResult> e)
  85.         {
  86.             if (questions_Songs.Count > 0)
  87.             {
  88.                 seconds_Songs = 0;
  89.                 questions_Songs.RemoveAt(0);
  90.                 if (questions_Songs.Count > 0)
  91.                 {
  92.                     this.nextQuestion_Songs();
  93.                     timer_Songs.Start();
  94.                 }
  95.                 else
  96.                 {
  97.                     this.stopSongs();
  98.                 }
  99.             }
  100.             else
  101.             {
  102.                 this.stopSongs();
  103.             }
  104.         }
  105.  
  106.         void messagePromptTrailers_Completed(object sender, PopUpEventArgs<String, PopUpResult> e)
  107.         {
  108.             seconds_Trailers = 0;
  109.             if (questions_Trailers.Count > 0)
  110.             {
  111.                 questions_Trailers.RemoveAt(0);
  112.                 if (questions_Trailers.Count > 0)
  113.                 {
  114.                     this.nextQuestion_Trailers();
  115.                     timer_Trailers.Start();
  116.                 }
  117.                 else
  118.                 {
  119.                     this.stopTrailers();
  120.                 }
  121.             }
  122.             else
  123.             {
  124.                 this.stopTrailers();
  125.             }
  126.         }
  127.  
  128.         void showGameFinished_Completed(object sender, PopUpEventArgs<String, PopUpResult> e)
  129.         {
  130.             gameFinished.Hide();
  131.             this.restart();
  132.         }
  133.  
  134.         private void btnShare_Click(object sender, RoutedEventArgs e)
  135.         {
  136.             ShareStatusTask shareStatusTask = new ShareStatusTask();
  137.             shareStatusTask.Status = "Windows Phone Facebook Integration Development Test.";
  138.             shareStatusTask.Show();
  139.         }
  140.  
  141.         private void btnRetry_Click(object sender, RoutedEventArgs e)
  142.         {
  143.             gameFinished.Hide();
  144.             this.restart();
  145.         }
  146.  
  147.         private void showGameFinished()
  148.         {
  149.             int totalScore = (corrected_Images + corrected_Songs + corrected_Trailers);
  150.             int totalQuestions = totalQuestions_Images + totalQuestions_Songs + totalQuestions_Trailers;
  151.             int totalSecondsElapsed = (totalTimeElapsed_Images + totalTimeElapsed_Trailers + totalTimeElapsed_Songs);
  152.             gameFinished = new MessagePrompt();
  153.             gameFinished.Title = "Game Finished";
  154.             gameFinished.Message = "Game Finished with a total score of: " + totalScore + "/" + totalQuestions + " and a total of " + totalSecondsElapsed + " seconds of elapsed time.\n\nClick Share Results if you want to share your results to your friends and click the Retry if you want to play again.";
  155.             resultToShare = "I finished the playing BundledFun with a total score of: " + totalScore + "/" + totalQuestions + " and a total of " + totalSecondsElapsed + " seconds of elapsed time.";
  156.             Button btnShare = new Button() { Content = "Share Results" };
  157.             btnShare.Click += new RoutedEventHandler(btnShare_Click);
  158.             Button btnRetry = new Button() { Content = "Retry" };
  159.             btnRetry.Click += new RoutedEventHandler(btnRetry_Click);
  160.             gameFinished.ActionPopUpButtons.Add(btnShare);
  161.             gameFinished.ActionPopUpButtons.Add(btnRetry);
  162.             gameFinished.Show();
  163.         }
  164.  
  165.         private void restart()
  166.         {
  167.             lastTrailers = "";
  168.             lastSongs = "";
  169.  
  170.             isImagesFinished = false;
  171.             isTrailersFinished = false;
  172.             isSongsFinished = false;
  173.  
  174.             hasStarted_Images = false;
  175.             hasStarted_Trailers = false;
  176.             hasStarted_Songs = false;
  177.  
  178.             corrected_Images = 0;
  179.             corrected_Trailers = 0;
  180.             corrected_Songs = 0;
  181.  
  182.             totalTimeElapsed_Images = 0;
  183.             totalTimeElapsed_Trailers = 0;
  184.             totalTimeElapsed_Songs = 0;
  185.  
  186.             seconds_Images = 0;
  187.             seconds_Trailers = 0;
  188.             seconds_Songs = 0;
  189.  
  190.             totalQuestions_Images = 0;
  191.             totalQuestions_Trailers = 0;
  192.             totalQuestions_Songs = 0;
  193.  
  194.             txtCorrectImages.Text = "";
  195.             txtCorrectSongs.Text = "";
  196.             txtCorrectTrailers.Text = "";
  197.             txtQuestionImages.Text = "";
  198.             txtQuestionSongs.Text = "";
  199.             txtQuestionTrailers.Text = "";
  200.             txtTimerImages.Text = "";
  201.             txtTimerSongs.Text = "";
  202.             txtTimerTrailers.Text = "";
  203.  
  204.             btnAImages.IsEnabled = true;
  205.             btnBImages.IsEnabled = true;
  206.             btnCImages.IsEnabled = true;
  207.  
  208.             btnATrailers.IsEnabled = true;
  209.             btnBTrailers.IsEnabled = true;
  210.             btnCTrailers.IsEnabled = true;
  211.  
  212.             btnASongs.IsEnabled = true;
  213.             btnBSongs.IsEnabled = true;
  214.             btnCSongs.IsEnabled = true;
  215.  
  216.             media.Stop();
  217.  
  218.             timer_Images.Stop();
  219.             timer_Trailers.Stop();
  220.             timer_Songs.Stop();
  221.  
  222.             questions_Images = new List<Question>();
  223.             currentQuestion_Images = new Question();
  224.  
  225.             questions_Trailers = new List<Question>();
  226.             currentQuestion_Trailers = new Question();
  227.  
  228.             questions_Songs = new List<Question>();
  229.             currentQuestion_Songs = new Question();
  230.  
  231.             this.initialize_Images();
  232.             this.initialize_Trailers();
  233.             this.initialize_Songs();
  234.  
  235.             pivot.SelectedIndex = 0;
  236.  
  237.             this.startImages();
  238.         }
  239.  
  240.         private List<E> ShuffleList<E>(List<E> inputList)
  241.         {
  242.             List<E> randomList = new List<E>();
  243.  
  244.             Random r = new Random();
  245.             int randomIndex = 0;
  246.             while (inputList.Count > 0)
  247.             {
  248.                 randomIndex = r.Next(0, inputList.Count); //Choose a random object in the list
  249.                 randomList.Add(inputList[randomIndex]); //add it to the new, random list
  250.                 inputList.RemoveAt(randomIndex); //remove to avoid duplicates
  251.             }
  252.  
  253.             return randomList; //return the new random list
  254.         }
  255.  
  256.         private void media_MediaEnded(object sender, RoutedEventArgs e)
  257.         {
  258.             media.Position = TimeSpan.Zero;
  259.             media.Play();
  260.         }
  261.  
  262.         private void LoadSound(String SoundFilePath, out SoundEffect Sound)
  263.         {
  264.             Sound = null;
  265.             try
  266.             {
  267.                 StreamResourceInfo SoundFileInfo = App.GetResourceStream(new Uri(SoundFilePath, UriKind.Relative));
  268.                 Sound = SoundEffect.FromStream(SoundFileInfo.Stream);
  269.             }
  270.             catch (NullReferenceException)
  271.             {
  272.                 MessageBox.Show("Couldn't load sound " + SoundFilePath);
  273.             }
  274.         }
  275.  
  276.         private Boolean isEverythingFinished()
  277.         {
  278.             if (isImagesFinished && isTrailersFinished && isSongsFinished)
  279.             {
  280.                 return true;
  281.             }
  282.             else
  283.             {
  284.                 return false;
  285.             }
  286.         }
  287.  
  288.         private void pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
  289.         {
  290.             if (pivot.SelectedIndex == 0) // Images
  291.             {
  292.                 if (!hasStarted_Images)
  293.                 {
  294.                     this.startImages();
  295.                 }
  296.                 else if(!isImagesFinished)
  297.                 {
  298.                     this.resumeImages();
  299.                     this.pauseTrailers();
  300.                     this.pauseSongs();
  301.                 }
  302.             }
  303.             else if (pivot.SelectedIndex == 1)// Trailers
  304.             {
  305.                 if (!hasStarted_Trailers)
  306.                 {
  307.                    this.startTrailers();
  308.                 }
  309.                 else if (!isTrailersFinished)
  310.                 {
  311.                     this.pauseImages();
  312.                     this.resumeTrailers();
  313.                     this.pauseSongs();
  314.                 }
  315.             }
  316.             else if (pivot.SelectedIndex == 2)// Songs
  317.             {
  318.                 if (!hasStarted_Songs)
  319.                 {
  320.                     this.startSongs();
  321.                 }
  322.                 else if (!isSongsFinished)
  323.                 {
  324.                     this.pauseImages();
  325.                     this.pauseTrailers();
  326.                     this.resumeSongs();
  327.                 }
  328.             }
  329.         }
  330.  
  331.         private void pauseImages()
  332.         {
  333.             timer_Images.Stop();
  334.         }
  335.  
  336.         private void resumeImages()
  337.         {
  338.             timer_Images.Start();
  339.         }
  340.  
  341.         private void btnAImages_Click(object sender, RoutedEventArgs e)
  342.         {
  343.             this.compareImages(btnAImages.Content.ToString());
  344.         }
  345.  
  346.         private void btnBImages_Click(object sender, RoutedEventArgs e)
  347.         {
  348.             this.compareImages(btnBImages.Content.ToString());
  349.         }
  350.  
  351.         private void btnCImages_Click(object sender, RoutedEventArgs e)
  352.         {
  353.             this.compareImages(btnCImages.Content.ToString());
  354.         }
  355.  
  356.         private void nextQuestion_Images()
  357.         {
  358.             questions_Images = ShuffleList<Question>(questions_Images);
  359.             currentQuestion_Images = questions_Images.ElementAt<Question>(0);
  360.             txtQuestionImages.Text = currentQuestion_Images.text;
  361.             txtTimerImages.Text = "Time Left: " + currentQuestion_Images.timer;
  362.             Images.Source = currentQuestion_Images.image;
  363.             btnAImages.Content = currentQuestion_Images.a;
  364.             btnBImages.Content = currentQuestion_Images.b;
  365.             btnCImages.Content = currentQuestion_Images.c;
  366.         }
  367.  
  368.         private void compareImages(String answer)
  369.         {
  370.             timer_Images.Stop();
  371.  
  372.             if (answer.Equals(currentQuestion_Images.answer))
  373.             {
  374.                 this.correctSound.Play();
  375.                 corrected_Images++;
  376.                 totalTimeElapsed_Images += (30 - Convert.ToInt16(txtTimerImages.Text.Substring(10)));
  377.                 txtCorrectImages.Text = "Correct: " + corrected_Images + "/" + totalQuestions_Images;
  378.  
  379.                 var messagePrompt = new MessagePrompt();
  380.                 messagePrompt.Title = "Correct Answer";
  381.                 messagePrompt.OnCompleted(new PopUpEventArgs<string, PopUpResult>
  382.                 {
  383.                     Result = messagePrompt.Value,
  384.                     PopUpResult = PopUpResult.Ok
  385.                 });
  386.  
  387.                 messagePrompt.Completed += messagePromptImages_Completed;
  388.                 messagePrompt.Show();
  389.             }
  390.             else
  391.             {
  392.                 this.wrongSound.Play();
  393.                 var messagePrompt = new MessagePrompt();
  394.                 messagePrompt.Title = "Wrong Answer";
  395.                 messagePrompt.Message = "The correct answer is: " + currentQuestion_Images.answer;
  396.                 messagePrompt.OnCompleted(new PopUpEventArgs<string, PopUpResult>
  397.                 {
  398.                     Result = messagePrompt.Value,
  399.                     PopUpResult = PopUpResult.Ok
  400.                 });
  401.  
  402.                 messagePrompt.Completed += messagePromptImages_Completed;
  403.                 messagePrompt.Show();
  404.             }
  405.         }
  406.  
  407.         void timer_Tick_Images(object sender, EventArgs e)
  408.         {
  409.             seconds_Images++;
  410.             int timeLeft = currentQuestion_Images.timer - seconds_Images;
  411.             if (timeLeft > 0)
  412.             {
  413.                 txtTimerImages.Text = "Time Left: " + timeLeft;
  414.             }
  415.             else
  416.             {
  417.                 seconds_Images = 0;
  418.                 if(questions_Images.Count > 0)
  419.                 {
  420.                     questions_Images.RemoveAt(0);
  421.                     if (questions_Images.Count > 0)
  422.                     {
  423.                         this.nextQuestion_Images();
  424.                     }
  425.                     else
  426.                     {
  427.                         this.stopImages();
  428.                     }
  429.                 }
  430.                 else{
  431.                     this.stopImages();
  432.                 }
  433.             }
  434.         }
  435.  
  436.         private void stopImages()
  437.         {
  438.             seconds_Images = 0;
  439.             timer_Images.Stop();
  440.             isImagesFinished = true;
  441.             btnAImages.IsEnabled = false;
  442.             btnBImages.IsEnabled = false;
  443.             btnCImages.IsEnabled = false;
  444.             pivot.SelectedIndex = 1;
  445.  
  446.             if (this.isEverythingFinished())
  447.             {
  448.                 this.showGameFinished();
  449.             }
  450.         }
  451.  
  452.         private void startImages()
  453.         {
  454.             txtTimerImages.Text = "Time Left: " + currentQuestion_Images.timer;
  455.             timer_Images.Start();
  456.             this.nextQuestion_Images();
  457.             hasStarted_Images = true;
  458.         }
  459.  
  460.         private void initialize_Images()
  461.         {
  462.             Question question = null;
  463.             question = null;
  464.             question = new Question();
  465.             question.image = new BitmapImage(new Uri("Images/adobe.png", UriKind.Relative));
  466.             question.text = "Is an American multinational computer software company founded in 1982 and headquartered in San Jose, California, United States.";
  467.             question.a = "Gimp";
  468.             question.b = "Adobe Systems";
  469.             question.c = "Microsoft";
  470.             question.answer = "Adobe Systems";
  471.             question.timer = 30;
  472.             questions_Images.Add(question);
  473.  
  474.             // you can add more - template below
  475.             //question = null;
  476.             //question = new Question();
  477.             //question.image = new BitmapImage(new Uri("Images/xxx.png", UriKind.Relative));
  478.             //question.text = "xxx";
  479.             //question.a = "xxx";
  480.             //question.b = "xxx";
  481.             //question.c = "xxx";
  482.             //question.answer = "xxx";
  483.             //question.timer = 30;
  484.             //questions_Images.Add(question);
  485.  
  486.             totalQuestions_Images = questions_Images.Count;
  487.             txtCorrectImages.Text = "Correct: " + corrected_Images + "/" + totalQuestions_Images;
  488.  
  489.             timer_Images = new System.Windows.Threading.DispatcherTimer();
  490.             timer_Images.Interval = new TimeSpan(0, 0, 0, 0, 1000); // 500 Milliseconds
  491.             timer_Images.Tick += new EventHandler(timer_Tick_Images);
  492.         }
  493.  
  494.  
  495.  
  496.         ///////////////////////////////////////////////////////////////////////////////
  497.  
  498.  
  499.  
  500.         private void pauseTrailers()
  501.         {
  502.             timer_Trailers.Stop();
  503.             media.Pause();
  504.             lastTrailers = currentQuestion_Trailers.trailer;
  505.         }
  506.  
  507.         private void resumeTrailers()
  508.         {
  509.             timer_Trailers.Start();
  510.             media.Source = new Uri("Trailers/" + lastTrailers, UriKind.Relative);
  511.             media.Play();
  512.         }
  513.  
  514.         private void btnATrailers_Click(object sender, RoutedEventArgs e)
  515.         {
  516.             this.compareTrailers(btnATrailers.Content.ToString());
  517.         }
  518.  
  519.         private void btnBTrailers_Click(object sender, RoutedEventArgs e)
  520.         {
  521.             this.compareTrailers(btnBTrailers.Content.ToString());
  522.         }
  523.  
  524.         private void btnCTrailers_Click(object sender, RoutedEventArgs e)
  525.         {
  526.             this.compareTrailers(btnCTrailers.Content.ToString());
  527.         }
  528.  
  529.         private void nextQuestion_Trailers()
  530.         {
  531.             questions_Trailers = ShuffleList<Question>(questions_Trailers);
  532.             currentQuestion_Trailers = questions_Trailers.ElementAt<Question>(0);
  533.             txtQuestionTrailers.Text = currentQuestion_Trailers.text;
  534.             txtTimerTrailers.Text = "Time Left: " + currentQuestion_Trailers.timer;
  535.             media.Source = new Uri("Trailers/" + currentQuestion_Trailers.trailer, UriKind.Relative);
  536.             media.Play();
  537.             btnATrailers.Content = currentQuestion_Trailers.a;
  538.             btnBTrailers.Content = currentQuestion_Trailers.b;
  539.             btnCTrailers.Content = currentQuestion_Trailers.c;
  540.         }
  541.  
  542.         private void compareTrailers(String answer)
  543.         {
  544.             timer_Trailers.Stop();
  545.             if (answer.Equals(currentQuestion_Trailers.answer))
  546.             {
  547.                 this.correctSound.Play();
  548.                 corrected_Trailers++;
  549.                 totalTimeElapsed_Trailers += (60 - Convert.ToInt16(txtTimerTrailers.Text.Substring(10)));
  550.                 txtCorrectTrailers.Text = "Correct: " + corrected_Trailers + "/" + totalQuestions_Trailers;
  551.  
  552.                 var messagePrompt = new MessagePrompt();
  553.                 messagePrompt.Title = "Correct Answer";
  554.                 messagePrompt.OnCompleted(new PopUpEventArgs<string, PopUpResult>
  555.                 {
  556.                     Result = messagePrompt.Value,
  557.                     PopUpResult = PopUpResult.Ok
  558.                 });
  559.  
  560.                 messagePrompt.Completed += messagePromptTrailers_Completed;
  561.                 messagePrompt.Show();
  562.             }
  563.             else
  564.             {
  565.                 this.wrongSound.Play();
  566.                 var messagePrompt = new MessagePrompt();
  567.                 messagePrompt.Title = "Wrong Answer";
  568.                 messagePrompt.Message = "The correct answer is: " + currentQuestion_Trailers.answer;
  569.                 messagePrompt.OnCompleted(new PopUpEventArgs<string, PopUpResult>
  570.                 {
  571.                     Result = messagePrompt.Value,
  572.                     PopUpResult = PopUpResult.Ok
  573.                 });
  574.  
  575.                 messagePrompt.Completed += messagePromptTrailers_Completed;
  576.                 messagePrompt.Show();
  577.             }
  578.         }
  579.  
  580.         void timer_Tick_Trailers(object sender, EventArgs e)
  581.         {
  582.             seconds_Trailers++;
  583.             int timeLeft = currentQuestion_Trailers.timer - seconds_Trailers;
  584.             if (timeLeft > 0)
  585.             {
  586.                 txtTimerTrailers.Text = "Time Left: " + timeLeft;
  587.             }
  588.             else
  589.             {
  590.                 seconds_Trailers = 0;
  591.                 if(questions_Trailers.Count > 0)
  592.                 {
  593.                     questions_Trailers.RemoveAt(0);
  594.                     if(questions_Trailers.Count > 0)
  595.                     {
  596.                         this.nextQuestion_Trailers();
  597.                     }
  598.                     else
  599.                     {
  600.                         this.stopTrailers();
  601.                     }
  602.                 }
  603.                 else
  604.                 {
  605.                     this.stopTrailers();
  606.                 }
  607.             }
  608.         }
  609.  
  610.         private void stopTrailers()
  611.         {
  612.             seconds_Trailers = 0;
  613.             timer_Trailers.Stop();
  614.             media.Stop();
  615.             isTrailersFinished = true;
  616.             pivot.SelectedIndex = 2;
  617.             btnATrailers.IsEnabled = false;
  618.             btnBTrailers.IsEnabled = false;
  619.             btnCTrailers.IsEnabled = false;
  620.  
  621.             if (this.isEverythingFinished())
  622.             {
  623.                 this.showGameFinished();
  624.             }
  625.         }
  626.  
  627.         private void startTrailers()
  628.         {
  629.             txtTimerTrailers.Text = "Time Left: " + currentQuestion_Trailers.timer;
  630.             timer_Trailers.Start();
  631.             this.nextQuestion_Trailers();
  632.             hasStarted_Trailers = true;
  633.         }
  634.  
  635.         private void initialize_Trailers()
  636.         {
  637.             Question question = null;
  638.             question = new Question();
  639.             question.trailer = "3idiots.wmv";
  640.             question.text = "Is a 2009 Indian comedy film directed by Rajkumar Hirani";
  641.             question.a = "4 Idiots";
  642.             question.b = "3 Idiots";
  643.             question.c = "2 Idiots";
  644.             question.answer = "3 Idiots";
  645.             question.timer = 60;
  646.             questions_Trailers.Add(question);
  647.  
  648.             // you can add more - template below
  649.             //question = null;
  650.             //question = new Question();
  651.             //question.trailer = "xxx";
  652.             //question.text = "xxx";
  653.             //question.a = "xxx";
  654.             //question.b = "xxx";
  655.             //question.c = "xxx";
  656.             //question.answer = "xxx";
  657.             //question.timer = 30;
  658.             //questions_Trailers.Add(question);
  659.  
  660.             totalQuestions_Trailers = questions_Trailers.Count;
  661.             txtCorrectTrailers.Text = "Correct: " + corrected_Trailers + "/" + totalQuestions_Trailers;
  662.  
  663.             timer_Trailers = new System.Windows.Threading.DispatcherTimer();
  664.             timer_Trailers.Interval = new TimeSpan(0, 0, 0, 0, 1000); // 500 Milliseconds
  665.             timer_Trailers.Tick += new EventHandler(timer_Tick_Trailers);
  666.         }
  667.  
  668.  
  669.  
  670.         ///////////////////////////////////////////////////////////////////////////////
  671.  
  672.  
  673.         private void pauseSongs()
  674.         {
  675.             lastSongs = currentQuestion_Songs.song;
  676.             timer_Songs.Stop();
  677.             media.Pause();
  678.         }
  679.  
  680.         private void resumeSongs()
  681.         {
  682.             timer_Songs.Start();
  683.             media.Source = new Uri("Songs3/" + lastSongs, UriKind.Relative);
  684.             media.Play();
  685.         }
  686.  
  687.         private void btnASongs_Click(object sender, RoutedEventArgs e)
  688.         {
  689.             this.compareSongs(btnASongs.Content.ToString());
  690.         }
  691.  
  692.         private void btnBSongs_Click(object sender, RoutedEventArgs e)
  693.         {
  694.             this.compareSongs(btnBSongs.Content.ToString());
  695.         }
  696.  
  697.         private void btnCSongs_Click(object sender, RoutedEventArgs e)
  698.         {
  699.             this.compareSongs(btnCSongs.Content.ToString());
  700.         }
  701.  
  702.         private void nextQuestion_Songs()
  703.         {
  704.             questions_Songs = ShuffleList<Question>(questions_Songs);
  705.             currentQuestion_Songs = questions_Songs.ElementAt<Question>(0);
  706.             txtQuestionSongs.Text = currentQuestion_Songs.text;
  707.             txtTimerSongs.Text = "Time Left: " + currentQuestion_Songs.timer;
  708.             media.Source = new Uri("Songs3/" + currentQuestion_Songs.song, UriKind.Relative);
  709.             media.Play();
  710.             btnASongs.Content = currentQuestion_Songs.a;
  711.             btnBSongs.Content = currentQuestion_Songs.b;
  712.             btnCSongs.Content = currentQuestion_Songs.c;
  713.         }
  714.  
  715.         private void compareSongs(String answer)
  716.         {
  717.             timer_Songs.Stop();
  718.  
  719.             if (answer.Equals(currentQuestion_Songs.answer))
  720.             {
  721.                 this.correctSound.Play();
  722.                 corrected_Songs++;
  723.                 totalTimeElapsed_Songs += (60 - Convert.ToInt16(txtTimerTrailers.Text.Substring(10)));
  724.                 txtCorrectSongs.Text = "Correct: " + corrected_Songs + "/" + totalQuestions_Songs;
  725.  
  726.                 var messagePrompt = new MessagePrompt();
  727.                 messagePrompt.Title = "Correct Answer";
  728.                 messagePrompt.OnCompleted(new PopUpEventArgs<string, PopUpResult>
  729.                 {
  730.                     Result = messagePrompt.Value,
  731.                     PopUpResult = PopUpResult.Ok
  732.                 });
  733.  
  734.                 messagePrompt.Completed += messagePromptSongs_Completed;
  735.                 messagePrompt.Show();
  736.             }
  737.             else
  738.             {
  739.                 this.wrongSound.Play();
  740.                 var messagePrompt = new MessagePrompt();
  741.                 messagePrompt.Title = "Wrong Answer";
  742.                 messagePrompt.Message = "The correct answer is: " + currentQuestion_Songs.answer;
  743.                 messagePrompt.OnCompleted(new PopUpEventArgs<string, PopUpResult>
  744.                 {
  745.                     Result = messagePrompt.Value,
  746.                     PopUpResult = PopUpResult.Ok
  747.                 });
  748.  
  749.                 messagePrompt.Completed += messagePromptSongs_Completed;
  750.                 messagePrompt.Show();
  751.             }
  752.         }
  753.  
  754.         void timer_Tick_Songs(object sender, EventArgs e)
  755.         {
  756.             seconds_Songs++;
  757.             int timeLeft = currentQuestion_Songs.timer - seconds_Songs;
  758.             if (timeLeft > 0)
  759.             {
  760.                 txtTimerSongs.Text = "Time Left: " + timeLeft;
  761.             }
  762.             else
  763.             {
  764.                 if (questions_Songs.Count > 0)
  765.                 {
  766.                     seconds_Songs = 0;
  767.                     questions_Songs.RemoveAt(0);
  768.                     if (questions_Songs.Count > 0)
  769.                     {
  770.                         this.nextQuestion_Songs();
  771.                     }
  772.                     else
  773.                     {
  774.                         this.stopSongs();
  775.                     }
  776.                 }
  777.                 else
  778.                 {
  779.                     this.stopSongs();
  780.                 }
  781.             }
  782.         }
  783.  
  784.         private void stopSongs()
  785.         {
  786.             seconds_Songs = 0;
  787.             timer_Songs.Stop();
  788.             media.Stop();
  789.             isSongsFinished = true;
  790.             pivot.SelectedIndex = 0;
  791.             btnASongs.IsEnabled = false;
  792.             btnBSongs.IsEnabled = false;
  793.             btnCSongs.IsEnabled = false;
  794.  
  795.             if (this.isEverythingFinished())
  796.             {
  797.                 this.showGameFinished();
  798.             }
  799.         }
  800.  
  801.  
  802.         private void startSongs()
  803.         {
  804.             txtTimerSongs.Text = "Time Left: " + currentQuestion_Songs.timer;
  805.             timer_Songs.Start();
  806.             this.nextQuestion_Songs();
  807.             hasStarted_Songs = true;
  808.         }
  809.  
  810.         private void initialize_Songs()
  811.         {
  812.             Question question = null;
  813.             question = new Question();
  814.             question.song = "always.mp3";
  815.             question.text = "Is a power ballad by Bon Jovi. It was released as a single from their 1994 album, Cross Road and went on to become their best selling single, with 3 million copies sold in the U.S. and more than 10 million worldwide.";
  816.             question.a = "Always";
  817.             question.b = "Never Say Goodbye";
  818.             question.c = "Edge of a Broken Heart";
  819.             question.answer = "Always";
  820.             question.timer = 60;
  821.             questions_Songs.Add(question);
  822.  
  823.             // you can add more - template below
  824.             //question = null;
  825.             //question = new Question();
  826.             //question.song = "xxx";
  827.             //question.text = "xxx";
  828.             //question.a = "xxx";
  829.             //question.b = "xxx";
  830.             //question.c = "xxx";
  831.             //question.answer = "xxx";
  832.             //question.timer = 60;
  833.             //questions_Songs.Add(question);
  834.  
  835.             totalQuestions_Songs = questions_Songs.Count;
  836.             txtCorrectSongs.Text = "Correct: " + corrected_Songs + "/" + totalQuestions_Songs;
  837.  
  838.             timer_Songs = new System.Windows.Threading.DispatcherTimer();
  839.             timer_Songs.Interval = new TimeSpan(0, 0, 0, 0, 1000); // 500 Milliseconds
  840.             timer_Songs.Tick += new EventHandler(timer_Tick_Songs);
  841.         }
  842.  
  843.         private void btnRestart_Click(object sender, RoutedEventArgs e)
  844.         {
  845.             this.restart();
  846.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement