hafıza oyunu
unknown
csharp
18 days ago
9.8 kB
3
Indexable
Never
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; using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace metegoktas { public partial class Form1 : Form { public Form1() { InitializeComponent(); timer1 = new Timer(); timer1.Interval = 1000; timer1.Tick += timer1_tick; resimlerikaristir(); } Image[] resimler = { Properties.Resources._1, Properties.Resources._2, Properties.Resources._3, Properties.Resources._4, Properties.Resources._5, Properties.Resources._6, Properties.Resources._7, Properties.Resources._8, Properties.Resources._9, Properties.Resources._10, Properties.Resources._11, Properties.Resources._12, Properties.Resources._13, Properties.Resources._14, Properties.Resources._15, Properties.Resources._16, Properties.Resources._17, Properties.Resources._18, Properties.Resources._19, Properties.Resources._20 }; int[] indeksler = { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17,18,18,19,19 }; PictureBox ilkkutu; int ilkindex; int bulunan, denemesayisi; int kalansure = 6; int ilkdogru, ikincidogru = 0; bool oyuncu = true; private void timer1_tick(object sender, EventArgs e) { if (kalansure > 0) { kalansure--; textBox2.Text = kalansure.ToString();// Kalan süreyi güncelle if (kalansure <= 2) { textBox1.ForeColor = Color.Red; } else { textBox1.ForeColor = Color.Blue; } } else { if (oyuncu == true) { oyuncu = false; textBox7.Visible = false; textBox8.Visible = true; kalansure = 6; } else { oyuncu=true; textBox8.Visible = false; textBox7.Visible=true; kalansure=6; } } } private void resimlerikaristir() { Random rnd = new Random(); for (int i = 0; i < 40; i++) { int sayi = rnd.Next(40); int gecici = indeksler[i]; indeksler[i] = indeksler[sayi]; indeksler[sayi] = gecici; } } private void Form1_Load(object sender, EventArgs e) { resimlerikaristir(); } private void textBox1_Click(object sender, EventArgs e) { PictureBox kutu = (PictureBox)sender; int kutuno = int.Parse(kutu.Name.Substring(10)); int indeksno = indeksler[kutuno - 1]; kutu.Image = resimler[indeksno]; kutu.Refresh(); if (ilkkutu == null) { ilkkutu = kutu; ilkindex = indeksno; denemesayisi++; kalansure = 6; } else { System.Threading.Thread.Sleep(1000); ilkkutu.Image = null; kutu.Image = null; kalansure = 6; if (ilkindex == indeksno) { ilkkutu.Visible = false; kutu.Visible = false; bulunan++; if (oyuncu==true) { ilkdogru++; textBox4.Text = ilkdogru.ToString(); } if (oyuncu==false) { ikincidogru++; textBox6.Text = ikincidogru.ToString(); } if (ilkdogru==11||ikincidogru==11) { timer1.Stop(); if (ilkdogru==11) { MessageBox.Show("Tebrikler " + ilkdogru + " dogru ile 1. oyuncu kazandı"); } if (ikincidogru==11) { MessageBox.Show("Tebrikler " + ikincidogru + " dogru ile 2. oyuncu kazandı"); } sıfırla(); denemesayisi = 0; ilkdogru = 0; ikincidogru = 0; this.Close(); } } ilkkutu = null; } } void sıfırla() { bulunan = 0; denemesayisi = 0; foreach (Control kontrol in Controls) { kontrol.Visible = true; } resimlerikaristir(); } private void startbutton_Click(object sender, EventArgs e) { resimlerikaristir(); timer1.Start(); goster(); System.Threading.Thread.Sleep(5000); gizle(); } private void pictureBox36_Click(object sender, EventArgs e) { PictureBox kutu = (PictureBox)sender; int kutuno = int.Parse(kutu.Name.Substring(10)); int indeksno = indeksler[kutuno - 1]; kutu.Image = resimler[indeksno]; kutu.Refresh(); if (ilkkutu == null) { ilkkutu = kutu; ilkindex = indeksno; denemesayisi++; kalansure = 6; } else { System.Threading.Thread.Sleep(1000); ilkkutu.Image = null; kutu.Image = null; kalansure = 6; if (ilkindex == indeksno) { ilkkutu.Visible = false; kutu.Visible = false; bulunan++; if (oyuncu==true) { ilkdogru++; textBox4.Text = ilkdogru.ToString(); } if (oyuncu==false) { ikincidogru++; textBox6.Text = ikincidogru.ToString(); } if (bulunan == 18) { timer1.Stop(); if (oyuncu==true) { MessageBox.Show("Tebrikler " + ilkdogru + " dogru ile 1. oyuncu kazandı"); } if (oyuncu == false) { MessageBox.Show("Tebrikler " + ikincidogru + " dogru ile 2. oyuncu kazandı"); } sıfırla(); denemesayisi = 0; ilkdogru = 0; ikincidogru = 0; this.Close(); } } else { if (oyuncu == true) { oyuncu = false; textBox7.Visible = false; textBox8.Visible = true; kalansure = 6; } else { oyuncu = true; textBox8.Visible = false; textBox7.Visible = true; kalansure = 6; } } ilkkutu = null; } } void goster() { for (int i = 1; i <= 40; i++) { string pictureBoxName = "pictureBox" + i.ToString(); PictureBox kutu = Controls.Find(pictureBoxName, true).FirstOrDefault() as PictureBox; if (kutu != null) { int indeksno = indeksler[i - 1]; kutu.Image = resimler[indeksno]; kutu.Refresh(); } } } void gizle() { for (int i = 1; i <= 40; i++) { string pictureBoxName = "pictureBox" + i.ToString(); PictureBox kutu = Controls.Find(pictureBoxName, true).FirstOrDefault() as PictureBox; if (kutu != null) { // Assuming there's a default image or null to reset the PictureBox kutu.Image = null; kutu.Refresh(); } } } } }
Leave a Comment