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;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int a = 3, b,t;
int[] rand = new int[16];
Button[,] buttons = new Button[4, 4];
Random randomc1 = new Random(Guid.NewGuid().GetHashCode());
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < 4; ++i)
{
for (int j = 0; j < 4; ++j)
{
buttons[i, j] = new Button();
buttons[i, j].Location = new Point(i * 80, j * 80);
buttons[i, j].Size = new Size(80, 80);
this.Controls.Add(buttons[i, j]);
}
}
}
private void button10_Click(object sender, EventArgs e)
{
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void button11_Click(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 16; i++)
{
rand[i] = randomc1.Next(1, 17);
for (int j = 0; j < i; j++)
{
while (rand[j] == rand[i])
{
j = 0;
rand[i] = randomc1.Next(1, 17);
}
}
}
for (int i = 0; i < 4; ++i)
{
for (int j = 0; j < 4; ++j)
{
buttons[i, j].Text = Convert.ToString(rand[i * 4 + j]);
}
}
}
private void button2_Click_1(object sender, EventArgs e)
{
for (int i = 0; i < 16; i++)
{
for (int j = 0; j < 16; j++)
{
if (rand[i] > rand[j])
{
t = rand[i];
rand[i] = rand[j];
rand[j] = t;
}
}
}
for (int i = 0; i < 4; ++i)
{
for (int j = 0; j < 4; ++j)
{
buttons[i, j].Text = Convert.ToString(rand[i * 4 + j]);
}
}
}
}
}
2015年10月30日 星期五
2015年10月22日 星期四
亂數不重複
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;
public partial class Form1 : Formnamespace WindowsFormsApplication1
{
{
public Form1()
{
InitializeComponent();
}
private void button4_Click(object sender, EventArgs e)
{
}
private void button10_Click(object sender, EventArgs e)
{
Random rnd = new Random();
button1.Text = rnd.Next(0, 9).ToString();
button2.Text = rnd.Next(0, 9).ToString();
button3.Text = rnd.Next(0, 9).ToString();
button4.Text = rnd.Next(0, 9).ToString();
button5.Text = rnd.Next(0, 9).ToString();
button6.Text = rnd.Next(0, 9).ToString();
button7.Text = rnd.Next(0, 9).ToString();
button8.Text = rnd.Next(0, 9).ToString();
button9.Text = rnd.Next(0, 9).ToString();
while (button1.Text == button2.Text)
{
button2.Text = rnd.Next(0, 9).ToString();
}
while (button2.Text == button3.Text || button1.Text == button3.Text)
{
button3.Text = rnd.Next(0, 9).ToString();
}
while(button3.Text == button4.Text);
}}}
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;
public partial class Form1 : Formnamespace WindowsFormsApplication1
{
{
public Form1()
{
InitializeComponent();
}
private void button4_Click(object sender, EventArgs e)
{
}
private void button10_Click(object sender, EventArgs e)
{
Random rnd = new Random();
button1.Text = rnd.Next(0, 9).ToString();
button2.Text = rnd.Next(0, 9).ToString();
button3.Text = rnd.Next(0, 9).ToString();
button4.Text = rnd.Next(0, 9).ToString();
button5.Text = rnd.Next(0, 9).ToString();
button6.Text = rnd.Next(0, 9).ToString();
button7.Text = rnd.Next(0, 9).ToString();
button8.Text = rnd.Next(0, 9).ToString();
button9.Text = rnd.Next(0, 9).ToString();
while (button1.Text == button2.Text)
{
button2.Text = rnd.Next(0, 9).ToString();
}
while (button2.Text == button3.Text || button1.Text == button3.Text)
{
button3.Text = rnd.Next(0, 9).ToString();
}
while(button3.Text == button4.Text);
}}}
2015年10月16日 星期五
拉霸
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;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int c = 0, d = 0, a1,a2,a3;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
Random rnd = new Random(Guid.NewGuid().GetHashCode());
a1 = rnd.Next(1, 3);
a2 = rnd.Next(1, 3);
a3 = rnd.Next(1, 3);
button1.Text = a1.ToString();
button2.Text = a2.ToString();
button3.Text = a3.ToString();
}
private void button4_Click(object sender, EventArgs e)
{
c = c + 1;
d = c % 2;
if (d == 0) timer1.Enabled = true;
else timer1.Enabled = false;
button4.Text = d.ToString();
}
private void button5_Click_1(object sender, EventArgs e)
{
}
private void timer2_Tick(object sender, EventArgs e)
{
if (a1 == a2 && a2 == a3 && a3 == a1 )
button5.Text = "WIN";
}
}
}
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
{
int c = 0, d = 0, a1,a2,a3;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
Random rnd = new Random(Guid.NewGuid().GetHashCode());
a1 = rnd.Next(1, 3);
a2 = rnd.Next(1, 3);
a3 = rnd.Next(1, 3);
button1.Text = a1.ToString();
button2.Text = a2.ToString();
button3.Text = a3.ToString();
}
private void button4_Click(object sender, EventArgs e)
{
c = c + 1;
d = c % 2;
if (d == 0) timer1.Enabled = true;
else timer1.Enabled = false;
button4.Text = d.ToString();
}
private void button5_Click_1(object sender, EventArgs e)
{
}
private void timer2_Tick(object sender, EventArgs e)
{
if (a1 == a2 && a2 == a3 && a3 == a1 )
button5.Text = "WIN";
}
}
}
2015年10月2日 星期五
紅綠燈
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;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int c = 0
;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
c++;
button1.Text = c.ToString();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
c++;
if (c % 3 == 0)
{
button1.BackColor = Color.Red;
button2.BackColor = Color.Black;
button3.BackColor = Color.Black;
}
else if (c % 3 == 1)
{
button1.BackColor = Color.Black;
button2.BackColor = Color.Yellow;
button3.BackColor = Color.Black;
}
else if (c % 3 == 2)
{
button1.BackColor = Color.Black;
button2.BackColor = Color.Black;
button3.BackColor = Color.Green;
}
}
}
}
訂閱:
文章 (Atom)