Design Patterns Code for Unity Games
Parent: Model
Boards arrange game objects according to a format/rule. The most common board type is the grid: checkers, chess, Tetris, tile-based games, etc.
Link: BoardTypes
A model object for storing objects in grids. Each grid is composed of Y List rows, each of which contains X elements.
Grid(Vector2Int size): Initalize the grid with a specific size.
Row GetRow(int index): Grids are stored as rows. Eeach row is a list with X elements.
Resize(Vector2Int newSize): Resize the grid and its underlying storage.
bool IsValidLoc(Vector2Int loc): Returns true if the grid location is valid.
T GetCell(Vector2Int loc): Returns type T
at the specified grid location, or null if it doesn’t exist.
SetCell(Vector2Int loc, T content): Set the T value for the cell at the specified location.
Stable, with Unit Tests.
Model for a grid with multiple layers.
Link: GridBoard
A grid board consists of cells, each cell records which tile is assigned to that cell. Large tiles can exist in multiple grid cells simultaneously. For overlapping tiles, use layers (z axis).
Stable.
A grid tile can be placed in a grid board, and will occupy 1 or more grid cells.
Currently only square shaped tiles are supported.
Support non-square tiles, such as Tetronimos.
Stable.
Specialization of Grid that uses GridCell
and GridTile
. Used by GridBoard
to define the layers of a multi-layer grid.
bool IsCellBlocked(Vector2Int loc): Returns true if the cell at the specified location is occupied by a GridTile
.
bool IsBlocked(Rect2Int bounds): Returns true if any of the cells covered by the Rectangle are occupied by a GridTile
.
Stable.