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;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public System.Windows.Forms.Button Button1;
public System.Windows.Forms.Button Button2;
Random rand = new Random();
Button[] buttons = new Button[10];
int a1, a2, a3, a4;
double b1, b2, b3, b4;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int x, y;
int[] m = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
for (int i = 9; i > 1; i--)
{
x = rand.Next(0, i);
y = m[x];
m[x] = m[i];
m[i] = y;
}
a1 = m[1];
a2 = m[2];
a3 = m[3];
a4 = m[4];
//MessageBox.Show(Convert.ToString(a1) + Convert.ToString(a2) + Convert.ToString(a3) + Convert.ToString(a4));
label1.Visible = true;
label2.Visible = true;
label3.Visible = true;
label4.Visible = true;
label1.Text = " ";
label2.Text = " ";
label3.Text = " ";
label4.Text = " ";
for(int i=0;i<10;i++)
{
buttons[i] = new Button();
buttons[i].Location = new Point(10 + i * 30, 120 );
buttons[i].Size = new Size(30, 30);
buttons[i].Text = Convert.ToString(i);
this.Controls.Add(buttons[i]);
buttons[i].Click += new EventHandler(a_Click);
}
Button1 = new System.Windows.Forms.Button();
Button1.Location = new Point(165, 150);
Button1.Size = new Size(50, 30);
Button1.Click += new EventHandler(Button1_Click);
Button1.Text = "取消";
this.Controls.Add(Button1);
Button2 = new System.Windows.Forms.Button();
Button2.Location = new Point(105, 150);
Button2.Size = new Size(50, 30);
Button2.Click += new EventHandler(Button2_Click);
Button2.Text = "確定";
this.Controls.Add(Button2);
label5.Text = " ";
button1.Text = "開始新局";
}
int j = 0;
private void a_Click(object sender, EventArgs e)
{
j++;
Button b = (Button)sender;
double x = Convert.ToDouble(b.Text);
for(int i=0;i<10;i++)
{
if(i==x)
{
buttons[i].Visible = false;
}
}
if(j%4==1)
{
label1.Text = b.Text;
}
if (j%4 == 2)
{
label2.Text = b.Text;
}
if (j%4 == 3)
{
label3.Text = b.Text;
}
if (j%4 == 0)
{
label4.Text = b.Text;
}
}
private void Button1_Click(object sender, EventArgs e)
{
label1.Visible = true;
label1.Text = " ";
label2.Visible = true;
label2.Text = " ";
label3.Visible = true;
label3.Text = " ";
label4.Visible = true;
label4.Text = " ";
}
int p = 0;
private void Button2_Click(object sender, EventArgs e)
{
p++;
int a=0,b=0;
b1 = Convert.ToDouble(label1.Text);
b2 = Convert.ToDouble(label2.Text);
b3 = Convert.ToDouble(label3.Text);
b4 = Convert.ToDouble(label4.Text);
if (a1 == b1 && a2 == b2 && a3 == b3 && a4 == b4)
MessageBox.Show("贏了");
if (a1 == b1)
a++;
if (a1 == b2 || a1 == b3 || a1 == b4)
b++;
if (a2 == b2)
a++;
if (a2 == b1 || a2 == b3 || a2 == b4)
b++;
if (a3 == b3)
a++;
if (a3 == b1 || a3 == b2 || a3 == b4)
b++;
if (a4 == b4)
a++;
if (a4 == b1 || a4 == b2 || a4 == b3)
b++;
label5.Text = label5.Text + Environment.NewLine+a + "a" + b + "b";
label1.Text = " ";
label2.Text = " ";
label3.Text = " ";
label4.Text = " ";
for (int i = 0; i < 10; i++)
{
buttons[i].Visible = true;
}
}
}
}
沒有留言:
張貼留言