Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2014
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.72 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.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. using System.Collections;
  11.  
  12. namespace finalniverse
  13. {
  14.     public partial class pexeso : Form
  15.     {
  16.         public pexeso()
  17.         {
  18.             this.pocetObra = pocetObr();
  19.             InitializeComponent();
  20.             start();
  21.         }
  22.  
  23.         Random rnd = new Random();   //vytváří náhodné čísla pro nahrání do pb
  24.         MujPcb[] Shapes = new MujPcb[20];  //vytváří 20 pictureboxů = 2x10 stejných kartiček
  25.        
  26.         int[] polecisel = new int[20];     //čísla podle kterých se potom nahrávají obrázky
  27.         int[] zamichane = new int[20];     // aby nebyly karticky vedle sebe
  28.  
  29.         int pocetObra;
  30.         int otocene1;
  31.         int otocene2;
  32.         int pocetOtoceni;
  33.         int celkovyPocetOtoceni;
  34.         int uhodle;
  35.         int neuhodle;
  36.  
  37.         public void start()
  38.         {
  39.             nactiPcb();
  40.            
  41.             int[] zamichane = ShuffleArray(polecisel);
  42.         }
  43.  
  44.  
  45.  
  46.         private int pocetObr()
  47.         {
  48.             ArrayList array = new ArrayList();
  49.             array.AddRange(File.ReadAllLines(@"Contents\houby.txt", Encoding.GetEncoding("WINDOWS-1250")));
  50.  
  51.             return array.Count;  
  52.         }
  53.         private void nactiPcb()     //vytvoří pictureboxi a nahraje do nich obrázky
  54.         {
  55.             vybercisla();
  56.             zamichane = ShuffleArray(polecisel);
  57.             pocetOtoceni = 0;
  58.             celkovyPocetOtoceni = 0;
  59.             int counter = 0;
  60.  
  61.             for (int j = 0; j < 5; j++)
  62.             {
  63.                 for (int i = 0; i < 4; i++)
  64.                 {
  65.                     Shapes[counter] = new MujPcb();
  66.                     Shapes[counter].Name = "pcb_" + counter;
  67.                     Shapes[counter].Location = new Point(j * 159 + 5, i * 159 + 5);
  68.                     Shapes[counter].Size = new Size(150, 150);
  69.                     Shapes[counter].Image = Image.FromFile(@"Contents\miscs\zadnilogo.jpg");
  70.                     Shapes[counter].Visible = true;
  71.                     Shapes[counter].SizeMode = PictureBoxSizeMode.StretchImage;
  72.                     Shapes[counter].Click += new EventHandler(image_Click);
  73.                     Shapes[counter].cisloPcb = counter;
  74.                     Shapes[counter].cisloObrazku = zamichane[counter];
  75.                     this.Controls.Add(Shapes[counter]);
  76.  
  77.                     counter++;
  78.  
  79.                 }
  80.             }
  81.  
  82.             uhodle = 0;
  83.         }
  84.  
  85.  
  86.         public void t_Tick(object sender, EventArgs e)
  87.         {
  88.             t.Stop();
  89.  
  90.             if (Shapes[otocene1].cisloObrazku == Shapes[otocene2].cisloObrazku)
  91.             {
  92.                 Shapes[otocene1].uhodnuto = true;
  93.                 Shapes[otocene1].Hide();
  94.                 Shapes[otocene2].uhodnuto = true;
  95.                 Shapes[otocene2].Hide();
  96.                 uhodle += 2;
  97.                 label2.Text = (uhodle / 2).ToString();
  98.             }
  99.             else
  100.             {
  101.                 Shapes[otocene1].Image = Image.FromFile(@"Contents\miscs\zadnilogo.jpg");
  102.                 Shapes[otocene2].Image = Image.FromFile(@"Contents\miscs\zadnilogo.jpg");
  103.                 neuhodle += 1;
  104.                 label6.Text = neuhodle.ToString();
  105.             }
  106.  
  107.  
  108.  
  109.             if (uhodle == 4)
  110.             {
  111.                 hra.Stop();
  112.                 DialogResult dial = MessageBox.Show("Vyhráli ste v čase: " + label4.Text + "  Chcete pokračovat? ", "Pokračovat?", MessageBoxButtons.YesNo);
  113.  
  114.                 if (dial == DialogResult.Yes)
  115.                 {
  116.                     otocene1 = 0;
  117.                     otocene2 = 0;
  118.                     pocetOtoceni = 0;
  119.                     celkovyPocetOtoceni = 0;
  120.                    
  121.                     start();
  122.                 }
  123.                 else if (dial == DialogResult.No)
  124.                 {
  125.                     Application.Exit();
  126.                 }
  127.             }
  128.  
  129.             pocetOtoceni = 0;
  130.         }
  131.  
  132.         public void image_Click(object sender, EventArgs e)
  133.         {
  134.  
  135.             MujPcb p = sender as MujPcb;
  136.  
  137.             if (pocetOtoceni == 0)
  138.             {
  139.                  p.Image = Image.FromFile(@"Contents\" + tridaZiv + "\\" + p.cisloObrazku + ".jpg");
  140.                 otocene1 = p.cisloPcb;
  141.                 pocetOtoceni++;
  142.             }
  143.             else if (pocetOtoceni == 1)
  144.             {
  145.                 p.Image = Image.FromFile(@"Contents\" + tridaZiv + "\\" + p.cisloObrazku + ".jpg");
  146.                 otocene2 = p.cisloPcb;
  147.                 pocetOtoceni++;
  148.             }
  149.         }
  150.  
  151.         private void vybercisla() //vybere náhodné číslo z celkového počtu obrázků a vloží jej do pole 2x (dvojice)
  152.         {
  153.             for (int i = 0; i < 20; i += 2)
  154.             {
  155.                 int nahodna = rnd.Next(0, pocetObra);
  156.                 polecisel[i] = nahodna;
  157.                 polecisel[i + 1] = nahodna;
  158.             }
  159.         }
  160.  
  161.         int[] ShuffleArray(int[] array)   //zamíchá pole čísel, aby se vytvořila náhodnost obrázků
  162.         {
  163.             Random r = new Random();
  164.             for (int i = array.Length; i > 0; i--)
  165.             {
  166.                 int j = r.Next(i);
  167.                 int k = array[j];
  168.                 array[j] = array[i - 1];
  169.                 array[i - 1] = k;
  170.             }
  171.             return array;
  172.         }
  173.  
  174.                
  175.     }
  176.     public class MujPcb : PictureBox  //přidání vlastností k PictureBoxu
  177.     {
  178.         public int cisloObrazku { get; set; }
  179.         public int cisloPcb { get; set; }
  180.         public bool uhodnuto { get; set; }
  181.     }
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement