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.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace MemoryGame
- {
- public partial class Form1 : Form
- {
- private GameSettings gameSettings;
- MemoryCard pierwsza;
- MemoryCard druga;
- public Form1()
- {
- InitializeComponent();
- gameSettings = new GameSettings();
- UstawKontrolki();
- GenerujKarty();
- timerCzasPodgladu.Start();
- }
- private void UstawKontrolki()
- {
- panelKart.Width = gameSettings.bok * gameSettings.kolumny;
- panelKart.Height = gameSettings.bok * gameSettings.wiersze;
- int width = panelKart.Width + 40;
- int height = panelKart.Height + 100;
- Width = width;
- Height = height;
- lblStartInfo.Text = $"Początek gry za {gameSettings.czasPodgladu}s.";
- lblPunktyWartosc.Text = gameSettings.aktualnePunkty.ToString();
- lblCzasWartosc.Text = gameSettings.czasGry.ToString();
- lblStartInfo.Visible = true;
- }
- private void GenerujKarty()
- {
- string[] memories = System.IO.Directory.GetFiles(gameSettings.folderObrazki);
- gameSettings.maxPunkty = memories.Length;
- List<MemoryCard> buttons = new List<MemoryCard>();
- foreach(string img in memories)
- {
- Guid id = Guid.NewGuid();
- MemoryCard b1 = new MemoryCard(id, gameSettings.plikLogo, img);
- buttons.Add(b1);
- MemoryCard b2 = new MemoryCard(id, gameSettings.plikLogo, img);
- buttons.Add(b2);
- }
- Random random = new Random();
- panelKart.Controls.Clear();
- for (int x = 0; x < gameSettings.kolumny; x++)
- {
- for (int y = 0; y < gameSettings.wiersze; y++)
- {
- int index = random.Next(0, buttons.Count);
- MemoryCard b = buttons[index];
- int margines = 2;
- b.Location = new Point((x * gameSettings.bok) + (margines * x), (y * gameSettings.bok) + (margines * y));
- b.Width = gameSettings.bok;
- b.Height = gameSettings.bok;
- b.Click += BtnClicked;
- b.Odkryj();
- panelKart.Controls.Add(b);
- buttons.Remove(b);
- }
- }
- }
- private void timerCzasPodgladu_Tick(object sender, EventArgs e)
- {
- gameSettings.czasPodgladu--;
- lblStartInfo.Text = $"Początek gry za {gameSettings.czasPodgladu}.";
- if(gameSettings.czasPodgladu <= 0)
- {
- lblStartInfo.Visible = false;
- foreach (Control kontrolka in panelKart.Controls)
- {
- MemoryCard card = (MemoryCard)kontrolka;
- card.Zakryj();
- }
- timerCzasPodgladu.Stop();
- timerCzasGry.Start();
- }
- }
- private void BtnClicked(object sender, EventArgs e)
- {
- MemoryCard btn = (MemoryCard)sender;
- if (pierwsza == null)
- {
- pierwsza = btn;
- pierwsza.Odkryj();
- } else
- {
- druga = btn;
- druga.Odkryj();
- panelKart.Enabled = false;
- if (pierwsza.Id == druga.Id)
- {
- gameSettings.aktualnePunkty++;
- lblPunktyWartosc.Text = gameSettings.aktualnePunkty.ToString();
- pierwsza = null;
- druga = null;
- panelKart.Enabled = true;
- } else
- {
- timerZakrywacz.Start();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement