Advertisement
coding_giants

c# offline base

May 24th, 2023
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11.  
  12. namespace MatchingGame
  13. {
  14. public partial class Form1 : Form
  15. {
  16. //Starter
  17. private bool doImagesMatch()
  18. {
  19. string[] splitModern = setModern.Split('\\');
  20. string[] splitRetro = setRetro.Split('\\');
  21.  
  22. string titleRetro = splitRetro[splitRetro.Length - 1];
  23. string titleModern = splitModern[splitModern.Length - 1];
  24.  
  25. if (titleModern == titleRetro)
  26. {
  27. return true;
  28. }
  29. else
  30. {
  31. return false;
  32. }
  33.  
  34.  
  35. }
  36. // Starter
  37. Random randomNumbersGenerator = new Random();
  38. string ImagesFolder = $@"{AppDomain.CurrentDomain.BaseDirectory}\Graphics";
  39. int retroImagesCounter = 0;
  40. string[] retroImages = null;
  41. string[] modernImages = null;
  42. string setRetro = null;
  43. string setModern = null;
  44.  
  45.  
  46. public Form1()
  47. {
  48. InitializeComponent();
  49. //starter
  50. modernImages = Directory.GetFiles(ImagesFolder + @"\Modern");
  51. retroImages = Directory.GetFiles(ImagesFolder + @"\Retro");
  52. //
  53. loadRetroImage();
  54. loadRandomModernImage();
  55. }
  56.  
  57. private void loadRetroImage()
  58. {
  59. if (retroImagesCounter < retroImages.Length)
  60. {
  61. setRetro = retroImages[retroImagesCounter];
  62. pbRetro.Image = Image.FromFile(setRetro);
  63. retroImagesCounter++;
  64. }
  65. else
  66. {
  67. MessageBox.Show("Game over");
  68. Application.Exit();
  69. }
  70. }
  71.  
  72. private void loadRandomModernImage()
  73. {
  74. int numberOfImages = modernImages.Length;
  75. int randomNumber = randomNumbersGenerator.Next(numberOfImages);
  76. setModern = modernImages[randomNumber];
  77. pbModern.Image = Image.FromFile(setModern);
  78. }
  79.  
  80. private void btnDraw_Click(object sender, EventArgs e)
  81. {
  82. loadRandomModernImage();
  83. }
  84.  
  85. private void btnCheck_Click(object sender, EventArgs e)
  86. {
  87. if (doImagesMatch())
  88. {
  89. MessageBox.Show("Your answer is correct! The images match!!!");
  90. loadRetroImage();
  91. loadRandomModernImage();
  92. }
  93. else
  94. {
  95. MessageBox.Show("Your answer is incorrect! The images do not match!!!");
  96. loadRetroImage();
  97. loadRandomModernImage();
  98. }
  99.  
  100. }
  101.  
  102. }
  103. }
  104.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement