root/src/BRAINSFramework/Map/Cluster.cs

2023
4
using System.Text;
4
using System.Text;
5
using Brains.Framework;
5
using Brains.Framework;
6
using Microsoft.Xna.Framework;
6
using Microsoft.Xna.Framework;
7
using Brains.Framework.PathFinding;
7
8
8
namespace Brains.Framework.Map
9
namespace Brains.Framework.Map
9
{
10
{
10
    public class Cluster
11
    public class Cluster
11
    {
12
    {
13
        
12
        private int _rows;
14
        private int _rows;
13
        private int _cols;
15
        private int _cols;
14
        private List<Grid> _grids;
16
        private List<Grid> _grids;
...
...
37
            //HACK: should support different sized grids
39
            //HACK: should support different sized grids
38
            get { return Grids[0].Cols * Cols; }
40
            get { return Grids[0].Cols * Cols; }
39
        }
41
        }
42
40
        public int TotalRows
43
        public int TotalRows
41
        {
44
        {
42
            //HACK: should support different sized grids
45
            //HACK: should support different sized grids
...
...
57
            }
60
            }
58
            return null;
61
            return null;
59
        }
62
        }
60
        
63
64
        public int GetGridIndex(int x, int y)
65
        {
66
            return y * Cols + x;
67
        }
68
        public Grid GetGrid(int x, int y)
69
        {
70
            return Grids[GetGridIndex(x, y)];
71
        }
72
73
        internal void AddEntrance(GridCell cellA, GridCell cellB)
74
        {
75
            if (!EntranceExists(cellA, cellB))
76
                Entrances.Add(new Entrance(cellA, cellB));
77
        }
78
79
        private bool EntranceExists(GridCell cellA, GridCell cellB)
80
        {
81
            for (int i = 0; i < Entrances.Count; i++)
82
            {
83
                Entrance ent = Entrances[i];
84
                if (ent.CellA == cellA && ent.CellB == cellB)
85
                    return true;
86
            }
87
            return false;
88
        }
89
        public List<Entrance> Entrances = new List<Entrance>();
61
    }
90
    }
91
    public class Entrance
92
    {
93
        public GridCell CellA { get; set; }
94
        public GridCell CellB { get; set; }
95
        public Entrance(GridCell a, GridCell b)
96
        {
97
            CellA = a;
98
            CellB = b;
99
        }
100
      
101
    }
62
}
102
}