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.Windows.Forms;
- using System.IO;
- using System.Collections;
- namespace finalniverse
- {
- public partial class pexeso : Form
- {
- public pexeso()
- {
- this.pocetObra = pocetObr();
- InitializeComponent();
- start();
- }
- Random rnd = new Random(); //vytváří náhodné čísla pro nahrání do pb
- MujPcb[] Shapes = new MujPcb[20]; //vytváří 20 pictureboxů = 2x10 stejných kartiček
- int[] polecisel = new int[20]; //čísla podle kterých se potom nahrávají obrázky
- int[] zamichane = new int[20]; // aby nebyly karticky vedle sebe
- int pocetObra;
- int otocene1;
- int otocene2;
- int pocetOtoceni;
- int celkovyPocetOtoceni;
- int uhodle;
- int neuhodle;
- public void start()
- {
- nactiPcb();
- int[] zamichane = ShuffleArray(polecisel);
- }
- private int pocetObr()
- {
- ArrayList array = new ArrayList();
- array.AddRange(File.ReadAllLines(@"Contents\houby.txt", Encoding.GetEncoding("WINDOWS-1250")));
- return array.Count;
- }
- private void nactiPcb() //vytvoří pictureboxi a nahraje do nich obrázky
- {
- vybercisla();
- zamichane = ShuffleArray(polecisel);
- pocetOtoceni = 0;
- celkovyPocetOtoceni = 0;
- int counter = 0;
- for (int j = 0; j < 5; j++)
- {
- for (int i = 0; i < 4; i++)
- {
- Shapes[counter] = new MujPcb();
- Shapes[counter].Name = "pcb_" + counter;
- Shapes[counter].Location = new Point(j * 159 + 5, i * 159 + 5);
- Shapes[counter].Size = new Size(150, 150);
- Shapes[counter].Image = Image.FromFile(@"Contents\miscs\zadnilogo.jpg");
- Shapes[counter].Visible = true;
- Shapes[counter].SizeMode = PictureBoxSizeMode.StretchImage;
- Shapes[counter].Click += new EventHandler(image_Click);
- Shapes[counter].cisloPcb = counter;
- Shapes[counter].cisloObrazku = zamichane[counter];
- this.Controls.Add(Shapes[counter]);
- counter++;
- }
- }
- uhodle = 0;
- }
- public void t_Tick(object sender, EventArgs e)
- {
- t.Stop();
- if (Shapes[otocene1].cisloObrazku == Shapes[otocene2].cisloObrazku)
- {
- Shapes[otocene1].uhodnuto = true;
- Shapes[otocene1].Hide();
- Shapes[otocene2].uhodnuto = true;
- Shapes[otocene2].Hide();
- uhodle += 2;
- label2.Text = (uhodle / 2).ToString();
- }
- else
- {
- Shapes[otocene1].Image = Image.FromFile(@"Contents\miscs\zadnilogo.jpg");
- Shapes[otocene2].Image = Image.FromFile(@"Contents\miscs\zadnilogo.jpg");
- neuhodle += 1;
- label6.Text = neuhodle.ToString();
- }
- if (uhodle == 4)
- {
- hra.Stop();
- DialogResult dial = MessageBox.Show("Vyhráli ste v čase: " + label4.Text + " Chcete pokračovat? ", "Pokračovat?", MessageBoxButtons.YesNo);
- if (dial == DialogResult.Yes)
- {
- otocene1 = 0;
- otocene2 = 0;
- pocetOtoceni = 0;
- celkovyPocetOtoceni = 0;
- start();
- }
- else if (dial == DialogResult.No)
- {
- Application.Exit();
- }
- }
- pocetOtoceni = 0;
- }
- public void image_Click(object sender, EventArgs e)
- {
- MujPcb p = sender as MujPcb;
- if (pocetOtoceni == 0)
- {
- p.Image = Image.FromFile(@"Contents\" + tridaZiv + "\\" + p.cisloObrazku + ".jpg");
- otocene1 = p.cisloPcb;
- pocetOtoceni++;
- }
- else if (pocetOtoceni == 1)
- {
- p.Image = Image.FromFile(@"Contents\" + tridaZiv + "\\" + p.cisloObrazku + ".jpg");
- otocene2 = p.cisloPcb;
- pocetOtoceni++;
- }
- }
- private void vybercisla() //vybere náhodné číslo z celkového počtu obrázků a vloží jej do pole 2x (dvojice)
- {
- for (int i = 0; i < 20; i += 2)
- {
- int nahodna = rnd.Next(0, pocetObra);
- polecisel[i] = nahodna;
- polecisel[i + 1] = nahodna;
- }
- }
- int[] ShuffleArray(int[] array) //zamíchá pole čísel, aby se vytvořila náhodnost obrázků
- {
- Random r = new Random();
- for (int i = array.Length; i > 0; i--)
- {
- int j = r.Next(i);
- int k = array[j];
- array[j] = array[i - 1];
- array[i - 1] = k;
- }
- return array;
- }
- }
- public class MujPcb : PictureBox //přidání vlastností k PictureBoxu
- {
- public int cisloObrazku { get; set; }
- public int cisloPcb { get; set; }
- public bool uhodnuto { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement