-
-
Save anonymous/3681dcc5ca6ea90958ca to your computer and use it in GitHub Desktop.
Pexeso - otočení karty
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Windows.Forms; | |
using System.Drawing; | |
using System; | |
namespace Lonesure | |
{ | |
public partial class Form1 : Form | |
{ | |
#region Initialization | |
private List<Image> l = new List<Image>() { Image.FromFile(@"Images\1.png"), Image.FromFile(@"Images\2.png"), Image.FromFile(@"Images\3.png"), Image.FromFile(@"Images\4.png"), Image.FromFile(@"Images\5.png"), Image.FromFile(@"Images\6.png"), Image.FromFile(@"Images\7.png"), Image.FromFile(@"Images\8.png") }; | |
private List<int> i = new List<int>() { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7 }; | |
private Image deafult = Image.FromFile(@"Images\0.png"); | |
private Random r = new Random(); | |
private int[] s = new int[2]{ -5, -5 }; | |
private bool b = true; | |
public Form1() | |
{ | |
this.InitializeComponent(); | |
this.ShuffleList(this.i.Count); | |
} | |
#endregion | |
#region Main | |
#region PictureBoxes | |
private void pictureBox1_Click(object sender, EventArgs e) | |
{ | |
this.Pics(0); | |
} | |
private void pictureBox2_Click(object sender, EventArgs e) | |
{ | |
this.Pics(1); | |
} | |
private void pictureBox3_Click(object sender, EventArgs e) | |
{ | |
this.Pics(2); | |
} | |
private void pictureBox4_Click(object sender, EventArgs e) | |
{ | |
this.Pics(3); | |
} | |
private void pictureBox5_Click(object sender, EventArgs e) | |
{ | |
this.Pics(4); | |
} | |
private void pictureBox6_Click(object sender, EventArgs e) | |
{ | |
this.Pics(5); | |
} | |
private void pictureBox7_Click(object sender, EventArgs e) | |
{ | |
this.Pics(6); | |
} | |
private void pictureBox8_Click(object sender, EventArgs e) | |
{ | |
this.Pics(7); | |
} | |
private void pictureBox9_Click(object sender, EventArgs e) | |
{ | |
this.Pics(8); | |
} | |
private void pictureBox10_Click(object sender, EventArgs e) | |
{ | |
this.Pics(9); | |
} | |
private void pictureBox11_Click(object sender, EventArgs e) | |
{ | |
this.Pics(10); | |
} | |
private void pictureBox12_Click(object sender, EventArgs e) | |
{ | |
this.Pics(11); | |
} | |
private void pictureBox13_Click(object sender, EventArgs e) | |
{ | |
this.Pics(12); | |
} | |
private void pictureBox14_Click(object sender, EventArgs e) | |
{ | |
this.Pics(13); | |
} | |
private void pictureBox15_Click(object sender, EventArgs e) | |
{ | |
this.Pics(14); | |
} | |
private void pictureBox16_Click(object sender, EventArgs e) | |
{ | |
this.Pics(15); | |
} | |
#endregion | |
#region Functions | |
private void ShuffleList(int t) | |
{ | |
int randomIndex = this.r.Next(0, t); | |
this.i.Add(this.i[randomIndex]); | |
this.i.RemoveAt(randomIndex); | |
if (t > 1) | |
this.ShuffleList(t - 1); | |
} | |
private void Pics(int pic) | |
{ | |
switch (pic) | |
{ | |
case 0: | |
this.pictureBox1.Image = this.l[this.i[pic]]; | |
break; | |
case 1: | |
this.pictureBox2.Image = this.l[this.i[pic]]; | |
break; | |
case 2: | |
this.pictureBox3.Image = this.l[this.i[pic]]; | |
break; | |
case 3: | |
this.pictureBox4.Image = this.l[this.i[pic]]; | |
break; | |
case 4: | |
this.pictureBox5.Image = this.l[this.i[pic]]; | |
break; | |
case 5: | |
this.pictureBox6.Image = this.l[this.i[pic]]; | |
break; | |
case 6: | |
this.pictureBox7.Image = this.l[this.i[pic]]; | |
break; | |
case 7: | |
this.pictureBox8.Image = this.l[this.i[pic]]; | |
break; | |
case 8: | |
this.pictureBox9.Image = this.l[this.i[pic]]; | |
break; | |
case 9: | |
this.pictureBox10.Image = this.l[this.i[pic]]; | |
break; | |
case 10: | |
this.pictureBox11.Image = this.l[this.i[pic]]; | |
break; | |
case 11: | |
this.pictureBox12.Image = this.l[this.i[pic]]; | |
break; | |
case 12: | |
this.pictureBox13.Image = this.l[this.i[pic]]; | |
break; | |
case 13: | |
this.pictureBox14.Image = this.l[this.i[pic]]; | |
break; | |
case 14: | |
this.pictureBox15.Image = this.l[this.i[pic]]; | |
break; | |
case 15: | |
this.pictureBox16.Image = this.l[this.i[pic]]; | |
break; | |
} | |
if (this.s[0] == -5) | |
{ | |
this.s[0] = pic; | |
this.s[1] = this.i[pic]; | |
} | |
else | |
{ | |
if (this.s[0] != pic && this.s[1] == this.i[pic]) | |
{ | |
this.Zr(pic); | |
this.Zr(this.s[0]); | |
MessageBox.Show("Good job!"); | |
} | |
else | |
this.Zr(); | |
this.s[0] = -5; | |
} | |
} | |
private void Zr(int co = -5) | |
{ | |
if (co == -5) | |
this.pictureBox1.Image = this.pictureBox2.Image = this.pictureBox3.Image = this.pictureBox4.Image = this.pictureBox5.Image = this.pictureBox6.Image = this.pictureBox7.Image = this.pictureBox8.Image = this.pictureBox9.Image = this.pictureBox10.Image = this.pictureBox11.Image = this.pictureBox12.Image = this.pictureBox13.Image = this.pictureBox14.Image = this.pictureBox15.Image = this.pictureBox16.Image = this.deafult; | |
else | |
switch (co) | |
{ | |
case 0: | |
this.pictureBox1.Visible = false; | |
break; | |
case 1: | |
this.pictureBox2.Visible = false; | |
break; | |
case 2: | |
this.pictureBox3.Visible = false; | |
break; | |
case 3: | |
this.pictureBox4.Visible = false; | |
break; | |
case 4: | |
this.pictureBox5.Visible = false; | |
break; | |
case 5: | |
this.pictureBox6.Visible = false; | |
break; | |
case 6: | |
this.pictureBox7.Visible = false; | |
break; | |
case 7: | |
this.pictureBox8.Visible = false; | |
break; | |
case 8: | |
this.pictureBox9.Visible = false; | |
break; | |
case 9: | |
this.pictureBox10.Visible = false; | |
break; | |
case 10: | |
this.pictureBox11.Visible = false; | |
break; | |
case 11: | |
this.pictureBox12.Visible = false; | |
break; | |
case 12: | |
this.pictureBox13.Visible = false; | |
break; | |
case 13: | |
this.pictureBox14.Visible = false; | |
break; | |
case 14: | |
this.pictureBox15.Visible = false; | |
break; | |
case 15: | |
this.pictureBox16.Visible = false; | |
break; | |
} | |
} | |
#endregion | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment