class Draw private Graphics canvas private int private int private int

 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
class Draw
{
private Graphics canvas;
private int N;
private int M;
private int[,] matrix;
private float xSpace;
private float ySpace;
public Draw(int[,] matrix, Graphics canvas, float width, float height, int N, int M)
{
this.matrix = matrix;
this.canvas = canvas;
this.N = N;
this.M = M;
xSpace = ((width - 1) / N);
ySpace = ((height - 1) / M);
}
public void DrawGrid()
{
Pen myPen = new Pen(Color.Black, 1);
float x = 0f;
float y = 0f;
for(int i = 0; i <= N; i++)
{
canvas.DrawLine(myPen, x, y, x, ySpace * M);
x += xSpace;
}
x = 0;
for (int i = 0; i <= M; i++)
{
canvas.DrawLine(myPen, x, y, xSpace * N, y);
y += ySpace;
}
}
public void BreakWalls()
{
for (int i = 0; i < N * M; i++)
{
for (int j = 0; j < M * N; j++)
{
if(matrix[i,j] == 1)
{
if(j == i + 1)
BreakRightWall(i / N, i % N);
else if(j == i + N)
BreakDownWall(i % N, i / N);
}
}
}
}
private void BreakRightWall(int i, int j)
{
Pen myPen = new Pen(SystemColors.Control, 1);
float y = ySpace * (i) ;
float x = xSpace * (j + 1) ;
canvas.DrawLine(myPen, x, y, x, y + ySpace);
}
private void BreakDownWall(int i, int j)
{
Pen myPen = new Pen(SystemColors.Control, 1);
float x = xSpace * i;
float y = ySpace * (j + 1);
canvas.DrawLine(myPen, x, y, x + xSpace, y);
}
}