所以我有这个代码:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click_1(object sender, EventArgs e)
{
Table t = new Table();
}
}
class Cell
{
Point position;
const int SIZE = 20;
Cell[] neighbors;
public Cell(Point position, Random r)
{
this.position = position;
Visualisation(r);
}
void Visualisation(Random r)
{
Graphics paper= Form1.ActiveForm.CreateGraphics();
paper.DrawRectangle(new Pen(Color.Red), position.X, position.Y, SIZE, SIZE);
}
}
class Table
{
Cell[] table = new Cell[100];
public Table()
{
Random r = new Random();
for (int i = 0; i < 100; i++)
{
table[i] = new Cell(new Point(i % 10 * 20 + 40, i / 10 * 20 + 40), r);
}
}
我会将数字写入所有单元格,每个单元格有多少邻居。我该怎么做?塞拉[] szomszedok; 是我应该计算每个单元格有多少邻居的部分。我在细胞中需要的目标:
3 5 5 5 5 5 5 5 5 3
5 8 8 8 8 8 8 8 8 5
5 8 8 8 8 8 8 8 8 5
5 8 8 8 8 8 8 8 8 5
5 8 8 8 8 8 8 8 8 5
5 8 8 8 8 8 8 8 8 5
5 8 8 8 8 8 8 8 8 5
5 8 8 8 8 8 8 8 8 5
5 8 8 8 8 8 8 8 8 5
3 5 5 5 5 5 5 5 5 3