I am currently working on a small text game after watching the new Throne movie the other day. (how you do it when you play with a lot of time on your hands).
I have created a grid in which objects can be placed, and currently I find that creating my grid takes a lot of time.
I wonder how you would apply this and any design patterns, ideas, concepts, etc. that would be useful for this type of thing.
I currently have 4 main โpartsโ that make up the grid.
Firstly, I have the grid itself, which contains an array of "rows"
public interface IGrid { GridRow[] Rows { get; set; } }
A GridRow , in turn, contains an array of GridCell 's, each of which contains an array of IEntity (each object that can be placed in a grid cell must implement IEntity.
public class GridRow { public int Index { get; set; } public GridCell[] Cells { get; set; } } public class GridCell { public int Index { get; set; } public IEntity[] Entities { get; set; } }
When it comes to meshing, it takes quite a while. Currently 200 * 200 'grid takes ~ 17 seconds to compose.
I am sure there should be a much more efficient way to save this data or create a grid using the current concept.
We invite everyone and all tips.
UPDATE
This is how I am drawing up the grid now:
public IGrid Create(int rows, int cols, int concurentEntitiesPerCell) { var grid = new Grid(); Rows = new GridRow[rows]; grid.Rows = Rows; var masterCells = new GridCell[cols]; var masterRow = new GridRow(); var masterCell = new GridCell(); for (var i = 0; i < masterCells.Count(); i++) { masterCells[i] = new GridCell(); masterCells[i].Index = i; masterCells[i].Entities = new IEntity[concurentEntitiesPerCell]; } masterRow.Cells = masterCells; for (var j = 0; j < rows; j++) { grid.Rows[j] = new GridRow(); } return grid; }