close

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication7
{
public partial class Form1 : Form
{
Random rand = new Random();
Button[,] buttons = new Button[4, 4];
int newa, newb;
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].Size = new Size(80, 80);
buttons[i, j].Location = new Point(i * 85, j * 85);

this.Controls.Add(buttons[i, j]);
}


}
restart();
win();

}
public void restart()
{
int a, b, x;
int[] array = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };

 

for (int i = 15; i > 1; i--)
{

a = rand.Next(0, i);
b = array[a];
array[a] = array[i];
array[i] = b;
}


for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
x = array[j * 4 + i];

buttons[i, j].Text = Convert.ToString(x);
if (buttons[i, j].Text == "0")
{
buttons[i, j].Text = "";
newa = i;
newb = j;
}
this.Controls.Add(buttons[i, j]);
}


}
}
public void win()
{
if (buttons[0, 0].Text == "" || buttons[0, 3].Text == "3" || buttons[1, 3].Text == "7" || buttons[2, 3].Text == "11" || buttons[3, 3].Text == "15")
{
Messagebox("Win!!!");
}

}

private void Messagebox(string p)
{
throw new NotImplementedException();
}
private void button1_Click(object sender, EventArgs e)
{
restart();
}
public void run()
{

}
}
}

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 p06299995 的頭像
    p06299995

    d0146967的部落格

    p06299995 發表在 痞客邦 留言(0) 人氣()