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 |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Brains.Framework;
using Microsoft.Xna.Framework;
using Brains.Framework.PathFinding;
namespace Brains.Framework.Map
{
public class Cluster
{
private int _rows;
private int _cols;
private List<Grid> _grids;
public int Rows { get { return _rows; } }
public int Cols { get { return _cols; } }
public List<Grid> Grids { get { return _grids; } }
internal Cluster()
{
_grids = new List<Grid>();
}
internal void AddGrid(Grid grid)
{
Grids.Add(grid);
}
internal void Setup(int rows, int cols)
{
_rows = rows;
_cols = cols;
}
public int TotalCols
{
//HACK: should support different sized grids
get { return Grids[0].Cols * Cols; }
}
public int TotalRows
{
//HACK: should support different sized grids
get { return Grids[0].Rows* Rows; }
}
public Grid GetGridAtPosition(Vector2 position)
{
foreach (var item in Grids)
{
if (
(position.X > item.Position.X && position.X < (item.Position.X + item.Width)) &&
(position.Y > item.Position.Y && position.Y < (item.Position.Y + item.Height))
)
{
return item;
}
}
return null;
}
public int GetGridIndex(int x, int y)
{
return y * Cols + x;
}
public Grid GetGrid(int x, int y)
{
return Grids[GetGridIndex(x, y)];
}
internal void AddEntrance(GridCell cellA, GridCell cellB)
{
if (!EntranceExists(cellA, cellB))
Entrances.Add(new Entrance(cellA, cellB));
}
private bool EntranceExists(GridCell cellA, GridCell cellB)
{
for (int i = 0; i < Entrances.Count; i++)
{
Entrance ent = Entrances[i];
if (ent.CellA == cellA && ent.CellB == cellB)
return true;
}
return false;
}
public List<Entrance> Entrances = new List<Entrance>();
}
public class Entrance
{
public GridCell CellA { get; set; }
public GridCell CellB { get; set; }
public Entrance(GridCell a, GridCell b)
{
CellA = a;
CellB = b;
}
}
} |