-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathField.cs
87 lines (68 loc) · 1.78 KB
/
Field.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
using System;
namespace Celluros
{
public class Field
{
private Cell[,] Field_;
public Field(int xSize, int ySize, params Cell[] startTypes)
{
Field_ = new Cell[xSize, ySize];
Random random = new Random();
for (int x = 0; x < xSize; x++)
{
for(int y = 0; y < ySize; y++)
{
Field_[x, y] = startTypes[random.Next(0, startTypes.Length)];
}
}
}
public Cell[,] GetField()
{
Cell[,] field = new Cell[Field_.GetLength(0), Field_.GetLength(1)];
for (int x = 0; x < Field_.GetLength(0); x++)
{
for (int y = 0; y < Field_.GetLength(1); y++)
{
field[x,y] = new Cell(Field_[x, y]);
}
}
return field;
}
public void SetField(Cell[,] newField)
{
Field_ = newField;
}
public bool IsTypeAtPosition(int x, int y, Cell type)
{
int newX, newY;
newX = x;
newY = y;
if(x < 0)
{
newX = Field_.GetLength(0) - 1;
}
if(y < 0)
{
newY = Field_.GetLength(1) - 1;
}
if(x >= Field_.GetLength(0))
{
newX = 0;
}
if(y >= Field_.GetLength(1))
{
newY = 0;
}
if(Field_[newX, newY] == type)
{
return true;
}
return false;
}
public int GetLength(int dimension)
{
return Field_.GetLength(dimension);
}
}
}