-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCell.cs
88 lines (72 loc) · 1.96 KB
/
Cell.cs
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
78
79
80
81
82
83
84
85
86
87
88
using System.Drawing;
namespace CellularAutomaton
{
internal class Cell //: Rectangle
{
private int _age;
private Color _color;
private int _state;
public Cell(int x, int y, int width, int height)
{
_color = Color.White;
Shape = new Rectangle(x, y, width, height);
Brush = new SolidBrush(_color);
State = 0;
}
public Cell(Cell copyCell, int x, int y, int width, int height)
{
Brush = copyCell.Brush;
_color = copyCell._color;
_state = copyCell.State;
Shape = new Rectangle(x, y, width, height);
}
public Cell(Cell copyCell)
{
Brush = copyCell.Brush;
_color = copyCell._color;
_state = copyCell.State;
Shape = new Rectangle(copyCell.Shape.X, copyCell.Shape.Y, copyCell.Shape.Width, copyCell.Shape.Height);
}
public SolidBrush Brush { get; }
public Rectangle Shape { get; set; }
public int State
{
get { return _state; }
set
{
_state = value;
_stateChanged();
}
}
public void GrowOlder()
{
_age++;
}
public int GetAge()
{
return _age;
}
private void _stateChanged()
{
switch (State)
{
case 0:
_color = Color.White;
break;
case 1:
_color = Color.Green;
break;
case 2:
_color = Color.Red;
break;
case 3:
_color = Color.Blue;
break;
case 4:
_color = Color.Black;
break;
}
Brush.Color = _color;
}
}
}