Skip to content

Instantly share code, notes, and snippets.

Created August 2, 2012 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3235132 to your computer and use it in GitHub Desktop.
Save anonymous/3235132 to your computer and use it in GitHub Desktop.
pexeso
using System.Collections.Generic;
using Microsoft.VisualBasic;
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 string name1 = "Hráč1", name2 = "Hráč2";
private int[] s = new int[2]{ -5, -5 };
private bool b = true;
private int poc = 1;
public Form1()
{
this.InitializeComponent();
this.ShuffleList(this.i.Count);
}
#endregion
#region Main
#region PictureBoxes
private void pictureBox1_Click(object sender, EventArgs e)
{
this.pictureBox1.Image = this.l[this.i[0]];
this.Pics(0);
}
private void pictureBox2_Click(object sender, EventArgs e)
{
this.pictureBox2.Image = this.l[this.i[1]];
this.Pics(1);
}
private void pictureBox3_Click(object sender, EventArgs e)
{
this.pictureBox3.Image = this.l[this.i[2]];
this.Pics(2);
}
private void pictureBox4_Click(object sender, EventArgs e)
{
this.pictureBox4.Image = this.l[this.i[3]];
this.Pics(3);
}
private void pictureBox5_Click(object sender, EventArgs e)
{
this.pictureBox5.Image = this.l[this.i[4]];
this.Pics(4);
}
private void pictureBox6_Click(object sender, EventArgs e)
{
this.pictureBox6.Image = this.l[this.i[5]];
this.Pics(5);
}
private void pictureBox7_Click(object sender, EventArgs e)
{
this.pictureBox7.Image = this.l[this.i[6]];
this.Pics(6);
}
private void pictureBox8_Click(object sender, EventArgs e)
{
this.pictureBox8.Image = this.l[this.i[7]];
this.Pics(7);
}
private void pictureBox9_Click(object sender, EventArgs e)
{
this.pictureBox9.Image = this.l[this.i[8]];
this.Pics(8);
}
private void pictureBox10_Click(object sender, EventArgs e)
{
this.pictureBox10.Image = this.l[this.i[9]];
this.Pics(9);
}
private void pictureBox11_Click(object sender, EventArgs e)
{
this.pictureBox11.Image = this.l[this.i[10]];
this.Pics(10);
}
private void pictureBox12_Click(object sender, EventArgs e)
{
this.pictureBox12.Image = this.l[this.i[11]];
this.Pics(11);
}
private void pictureBox13_Click(object sender, EventArgs e)
{
this.pictureBox13.Image = this.l[this.i[12]];
this.Pics(12);
}
private void pictureBox14_Click(object sender, EventArgs e)
{
this.pictureBox14.Image = this.l[this.i[13]];
this.Pics(13);
}
private void pictureBox15_Click(object sender, EventArgs e)
{
this.pictureBox15.Image = this.l[this.i[14]];
this.Pics(14);
}
private void pictureBox16_Click(object sender, EventArgs e)
{
this.pictureBox16.Image = this.l[this.i[15]];
this.Pics(15);
}
#endregion
#region Labels
private void label1_Click(object sender, EventArgs e)
{
int doc = name1.Length;
if ((this.name1 = Interaction.InputBox("Zadejte jméno hráče1.", "Nastavení jména hráče1", this.name1, Screen.PrimaryScreen.Bounds.Width / 2 - 180, Screen.PrimaryScreen.Bounds.Height / 2 - 100)) == "")
this.name1 = "Hráč1";
this.label1.Text = this.name1 + ": " + this.label1.Text.Substring(doc + 2);
}
private void label2_Click(object sender, EventArgs e)
{
int doc = name2.Length;
if ((this.name2 = Interaction.InputBox("Zadejte jméno hráče2.", "Nastavení jména hráče2", this.name1, Screen.PrimaryScreen.Bounds.Width / 2 - 180, Screen.PrimaryScreen.Bounds.Height / 2 - 100)) == "")
this.name2 = "Hráč1";
this.label2.Text = this.name2 + ": " + this.label2.Text.Substring(doc + 2);
}
#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)
{
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!");
int h1 = int.Parse(this.label1.Text.Substring(name1.Length + 2)), h2 = int.Parse(this.label2.Text.Substring(name2.Length + 2));
if (this.b == true)
{
h1 = h1 + 1;
this.label1.Text = this.name1 + ": " + h1.ToString();
}
else
{
h2 = h2 + 1;
this.label2.Text = this.name2 + ": " + h2.ToString();
}
if ((h1 + h2) == this.poc * 8)
{
string vit;
if (h1 > h2)
vit = this.name1 + ".";
else if (h1 < h2)
vit = this.name2 + ".";
else
vit = "Nikdo - remíza.";
MessageBox.Show("Konec hry! Zvítězil: " + vit);
if (MessageBox.Show("Chcete pokračovat ve hře? Pokud ne, bude program ukončen...", "Předzavírací dialog", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
{
this.poc++;
this.Zr();
this.pictureBox1.Visible = this.pictureBox2.Visible = this.pictureBox3.Visible = this.pictureBox4.Visible = this.pictureBox5.Visible = this.pictureBox6.Visible = this.pictureBox7.Visible = this.pictureBox8.Visible = this.pictureBox9.Visible = this.pictureBox10.Visible = this.pictureBox11.Visible = this.pictureBox12.Visible = this.pictureBox13.Visible = this.pictureBox14.Visible = this.pictureBox15.Visible = this.pictureBox16.Visible = true;
this.ShuffleList(this.i.Count);
}
else
this.Close();
}
}
else
{
this.Zr();
if (this.s[1] != this.i[pic])
{
this.b = !this.b;
if (this.b == true)
{
this.label1.ForeColor = Color.RoyalBlue;
this.label2.ForeColor = Color.Black;
}
else
{
this.label2.ForeColor = Color.RoyalBlue;
this.label1.ForeColor = Color.Black;
}
}
}
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