-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChunk.cs
52 lines (47 loc) · 1.68 KB
/
Chunk.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
using System.Collections.Generic;
using System;
namespace Conway
{
class Chunk
{
public (int, int) Position;
private List<Cell> Cells;
public static List<Chunk> Chunks = new List<Chunk>();
Chunk( (int, int) position)
{
Cells = new List<Cell>();
foreach (Chunk chunk in Chunks)
{
if (chunk.Position == position)
throw(new Exception()); //Do not allow multiple chunks
else Position = position;
}
}
public static Chunk GetChunk( (int X, int Y) position)
{
(int, int) _position = //Translate cell position to chunk position
((int)Math.Floor((double)(position.X / GameofLife.ChunkSize)),
(int)Math.Floor((double)(position.Y / GameofLife.ChunkSize)));
foreach (Chunk chunk in Chunks)
{ if (chunk.Position == _position) return chunk; }
return new Chunk(position);
}
public static Chunk GetChunk( (int X, int Y) position, bool isChunkTransform)
{
foreach (Chunk chunk in Chunks)
{ if (chunk.Position == position) return chunk; }
return new Chunk(position);
}
public void AddCell(Cell cell) { Cells.Add(cell); }
public List<Cell> GetCells() { return Cells; }
public List<Cell> GetCells((int, int) exclude)
{
List<Cell> _excludedCells = new List<Cell>();
foreach (Cell cell in Cells)
{
if (cell._position != exclude)
_excludedCells.Add(cell);
} return _excludedCells;
}
}
}