-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrid.cs
More file actions
84 lines (63 loc) · 1.59 KB
/
Grid.cs
File metadata and controls
84 lines (63 loc) · 1.59 KB
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace ABLibrary
{
public class Grid<T> : MonoBehaviour
{
public delegate void ElementOperator(ref T element);
public struct Size
{
public int row;
public int column;
}
public struct Position
{
public int row;
public int column;
}
public Grid(int rows, int columns)
{
_grid = new T[rows, columns];
}
public int GetRowCount()
{
return _grid.GetLength(0);
}
public int GetColumnCount()
{
return _grid.GetLength(1);
}
public Size GetSize()
{
Size sz;
sz.row = GetRowCount();
sz.column = GetColumnCount();
return sz;
}
public T Get(Position pos)
{
return Get(pos.row, pos.column);
}
public T Get(int row, int column)
{
return _grid[row, column];
}
public void Set(Position pos, T val)
{
Set(pos.row, pos.column, val);
}
public void Set(int row, int column, T val)
{
_grid[row, column] = val;
}
public void ForEach(ElementOperator op)
{
Size sz = GetSize();
for (int row = 0; row < sz.row; ++row)
for (int col = 0; col < sz.column; ++col)
op(ref _grid[row, col]);
}
private T[,] _grid = null;
}
}