Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace MatchingGame
- {
- public partial class Form1 : Form
- {
- //Starter
- private bool doImagesMatch()
- {
- string[] splitModern = setModern.Split('\\');
- string[] splitRetro = setRetro.Split('\\');
- string titleRetro = splitRetro[splitRetro.Length - 1];
- string titleModern = splitModern[splitModern.Length - 1];
- if (titleModern == titleRetro)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- // Starter
- Random randomNumbersGenerator = new Random();
- string ImagesFolder = $@"{AppDomain.CurrentDomain.BaseDirectory}\Graphics";
- int retroImagesCounter = 0;
- string[] retroImages = null;
- string[] modernImages = null;
- string setRetro = null;
- string setModern = null;
- public Form1()
- {
- InitializeComponent();
- //starter
- modernImages = Directory.GetFiles(ImagesFolder + @"\Modern");
- retroImages = Directory.GetFiles(ImagesFolder + @"\Retro");
- //
- loadRetroImage();
- loadRandomModernImage();
- }
- private void loadRetroImage()
- {
- if (retroImagesCounter < retroImages.Length)
- {
- setRetro = retroImages[retroImagesCounter];
- pbRetro.Image = Image.FromFile(setRetro);
- retroImagesCounter++;
- }
- else
- {
- MessageBox.Show("Game over");
- Application.Exit();
- }
- }
- private void loadRandomModernImage()
- {
- int numberOfImages = modernImages.Length;
- int randomNumber = randomNumbersGenerator.Next(numberOfImages);
- setModern = modernImages[randomNumber];
- pbModern.Image = Image.FromFile(setModern);
- }
- private void btnDraw_Click(object sender, EventArgs e)
- {
- loadRandomModernImage();
- }
- private void btnCheck_Click(object sender, EventArgs e)
- {
- if (doImagesMatch())
- {
- MessageBox.Show("Your answer is correct! The images match!!!");
- loadRetroImage();
- loadRandomModernImage();
- }
- else
- {
- MessageBox.Show("Your answer is incorrect! The images do not match!!!");
- loadRetroImage();
- loadRandomModernImage();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement