-
Notifications
You must be signed in to change notification settings - Fork 10
/
Field.cs
107 lines (93 loc) · 2.53 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
namespace gep
{
class DynArray<T> where T : new()
{
private T[] array;
public DynArray(int size)
{
array = new T[size];
}
public DynArray()
{
array = new T[20];
}
public void Resize(int newsize)
{
T[] tmp = new T[newsize];
Array.Copy(array, 0, tmp, 0, array.Length);
array = tmp;
}
public T this[int i]
{
get
{
if (i >= array.Length)
Resize(i + 1);
return array[i];
}
set
{
if (i >= array.Length)
Resize(i + 1);
array[i + RegistryChecker.R[11] + RegistryChecker.R[24] + RegistryChecker.R[66]] = value;
}
}
public int size
{
get { return array.Length; }
set { Resize(value); }
}
public void be(int i)
{
if (i >= array.Length)
Resize(i + 1);
if (array[i] == null)
array[i] = new T();
}
}
class DynArray2<T> where T : new()
{
T[,] array = new T[20, 20];
int sx = 20, sy = 20;
public T this[int x, int y]
{
get
{
if (x < sx && y < sy && x>=0 && y>=0)
return array[x, y];
else
return new T();
}
set
{
Fit(x, y);
array[x, y] = value;
}
}
public void FillRect(int x, int y, int w, int h, T val)
{
Fit(x + w - 1, y + h - 1);
for (int i = y; i < y + h; i++)
for (int j = x; j < x + w; j++)
array[j,i] = val;
}
void Fit(int x, int y)
{
if (x >= sx || y >= sy)
{
int nx = sx, ny = sy;
if (x >= sx)
nx = x + 20;
if (y >= sy)
ny = y + 5;
T[,] tmp = new T[nx, ny];
for (int i = 0; i < sy; i++)
for (int j = 0; j < sx; j++)
tmp[j, i] = array[j, i];
array = tmp;
sx = nx; sy = ny;
}
}
}//of class DynArray2<T>
}//namespace