程式設計工藝大師
推盤
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 rand1;
int rand2;
int rand3;
int rand4;
int rand5;
int rand6;
int rand7;
int rand8;
int rand9;
public Form1()
{
InitializeComponent();
}
private void button7_Click(object sender, EventArgs e)
{
}
private void button10_Click(object sender, EventArgs e)
{
Random rand = new Random();
rand1 = rand.Next(0,9);
rand2 = rand.Next(0, 9);
rand3 = rand.Next(0, 9);
rand4 = rand.Next(0, 9);
rand5 = rand.Next(0, 9);
rand6 = rand.Next(0, 9);
rand7 = rand.Next(0, 9);
rand8 = rand.Next(0, 9);
rand9 = rand.Next(0, 9);
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
button5.Enabled = false;
button6.Enabled = false;
button7.Enabled = false;
button8.Enabled = false;
button9.Enabled = false;
do
{
rand1 = rand.Next(0,9);
rand2 = rand.Next(0, 9);
rand3 = rand.Next(0, 9);
rand4 = rand.Next(0, 9);
rand5 = rand.Next(0, 9);
rand6 = rand.Next(0, 9);
rand7 = rand.Next(0, 9);
rand8 = rand.Next(0, 9);
rand9 = rand.Next(0, 9);
button1.Text=rand1.ToString();
button2.Text=rand2.ToString();
button3.Text=rand3.ToString();
button4.Text=rand4.ToString();
button5.Text=rand5.ToString();
button6.Text=rand6.ToString();
button7.Text=rand7.ToString();
button8.Text=rand8.ToString();
button9.Text=rand9.ToString();
}while((rand1==rand2)||
(rand1==rand3)||(rand2==rand3)||
(rand1==rand4)||(rand2==rand4)||(rand3==rand4)||
(rand1==rand5)||(rand2==rand5)||(rand3==rand5)||(rand4==rand5)||
(rand1==rand6)||(rand2==rand6)||(rand3==rand6)||(rand4==rand6)||(rand5==rand6)||
(rand1==rand7)||(rand2==rand7)||(rand3==rand7)||(rand4==rand7)||(rand5==rand7)||(rand6==rand7)||
(rand1 == rand8) || (rand2 == rand8) || (rand3 == rand8) || (rand4 == rand8) || (rand5 == rand8) || (rand6 == rand8) || (rand7 == rand8) ||
(rand1 == rand9) || (rand2 == rand9) || (rand3 == rand9) || (rand4 == rand9) || (rand5 == rand9) || (rand6 == rand9) || (rand7 == rand9) || (rand8 == rand9));
}
}
}
沒有留言:
張貼留言