Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. private void rectClick(object sender, MouseButtonEventArgs e)
  2. {
  3.  
  4. // If game is paused, prevent action
  5. if (pause == true)
  6. {
  7. return;
  8. }
  9.  
  10. // This variable contains the object that was clicked on
  11. var mouseWasDownOn = e.Source as FrameworkElement;
  12. // This hides the rectangle, revealing the image
  13. mouseWasDownOn.Visibility = Visibility.Hidden;
  14. MessageBox.Show("");
  15.  
  16.  
  17. // If an image is already revealed
  18. // This happens if no picture has been clicked
  19. if (firstImage == null)
  20. {
  21. firstImage = e.Source as FrameworkElement;
  22. }
  23. // This happens if an image is open
  24. else
  25. {
  26. secondImage = e.Source as FrameworkElement;
  27. samePicture = comparePicture(firstImage, secondImage);
  28. // If you clicked on same pictures
  29. if (samePicture)
  30. {
  31. points = points + 1;
  32. // Checks when the game is over
  33. if (points > 7)
  34. {
  35. MessageBox.Show("You've won! ");
  36. var currentValue = DateTime.Now - this.TimerStart;
  37. int x = (int)currentValue.Seconds;
  38. MessageBox.Show("You took " + x + " seconds to finish the game!");
  39.  
  40. HighScore score = new HighScore() { Score = points, Name = nameBox.Text };
  41. highScore.Add(score);
  42. MessageBox.Show("Feel free to retry the game if you want! ");
  43.  
  44.  
  45.  
  46. }
  47.  
  48. }
  49. else {
  50. if (difficulty == 1)
  51. {
  52. mouseWasDownOn.Visibility = Visibility.Hidden;
  53.  
  54. Thread.Sleep(2000);
  55. }
  56. else if (difficulty == 2)
  57. {
  58. mouseWasDownOn.Visibility = Visibility.Hidden;
  59.  
  60. Thread.Sleep(1000);
  61.  
  62. }
  63. else if (difficulty == 3)
  64. {
  65. mouseWasDownOn.Visibility = Visibility.Hidden;
  66.  
  67. Thread.Sleep(200);
  68.  
  69. }
  70.  
  71. firstImage.Visibility = Visibility.Visible;
  72. secondImage.Visibility = Visibility.Visible;
  73.  
  74. }
  75.  
  76.  
  77. firstImage = null;
  78. secondImage = null;
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement