1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| public void GenerateGrid()
{
for (int n = 0; n <= SizeTable.Height; ++n)
{
for(int i = 0; i <= SizeTable.Width +1; ++i)
{
int E_H = n * SizeCell;
int E_W = i * SizeCell * 2;
Point A = new Point(SizeCell + E_W, E_H);
Point B = new Point(SizeCell * 2 + E_W, SizeCell / 2 + E_H);
Point C = new Point(SizeCell + E_W, SizeCell + E_H);
Point D = new Point(E_W, SizeCell / 2 + E_H);
int ID = i + (n * SizeTable.Width * 2) - n;
if(ID <= MyMap.Cells.Length-1)
{
if (MyMap.Cells[ID] == null)
{
CellsData NewCell = new CellsData();
NewCell.New(this);
NewCell.ID = ID;
NewCell.Location = new Point[] { A, B, C, D };
MyMap.Cells[NewCell.ID] = NewCell;
}
else
{
MyMap.Cells[ID].JoinMap(this);
MyMap.Cells[ID].Location = new Point[] { A, B, C, D };
}
}
}
}
for(int u = 0; u <= SizeTable.Height -2; u++ )
{
for(int o = 0; o<= SizeTable.Width -2; o++)
{
int E_H = (u * SizeCell) + (SizeCell / 2);
int E_W = (o * SizeCell * 2) + SizeCell;
Point A = new Point(SizeCell + E_W, E_H);
Point B = new Point(SizeCell * 2 + E_W, SizeCell / 2 + E_H);
Point C = new Point(SizeCell * 2 + E_W, SizeCell + E_H);
Point D = new Point(E_W, SizeCell / 2 + E_H);
int ID = o + (u * (SizeTable.Width * 2) + SizeTable.Width) - u;
if(ID <= MyMap.Cells.Length -1)
{
if(MyMap.Cells[ID] == null)
{
CellsData CD = new CellsData();
CD.New(this);
CD.ID = ID;
CD.Location = new Point[] { A, B, C, D };
MyMap.Cells[CD.ID] = CD;
}
else
{
MyMap.Cells[ID].JoinMap(this);
MyMap.Cells[ID].Location = new Point[] { A, B, C, D };
}
}
}
}
CellsData W = MyMap.Cells.Last();
MessageBox.Show($"{W.ID} / {MyMap.Cells.Length}");
} |
Partager