public bool IsValidCoordinate(CellCoordinate coord) { return(coord.X >= 0 && coord.X < Width && coord.Y >= 0 && coord.Y < Height && coord.Floor == 0); }
public Cell GetCell(CellCoordinate coord) { if (IsValidCoordinate(coord) == false) { throw CellCoordException.Invalid(coord); } Cell output = default(Cell); if (_world.TryGetValue(coord, out output) == false) { throw CellCoordException.NoData(coord); } return(output); }
// Use this for initialization void Start() { // init the entire world to exist. _world = new Dictionary <CellCoordinate, Cell>(); for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { var coord = new CellCoordinate(x, y); _world.Add(coord, new Cell(CellStatus.FILLED, CellType.DUNGEON)); } } // fire event Events.Emit <IWorldEventHandler>(h => h.OnWorldCreated(this)); }
public bool SetCell(CellCoordinate coord, Cell cell) { if (IsValidCoordinate(coord) == false) { throw CellCoordException.Invalid(coord); } var existingCell = default(Cell); if (_world.TryGetValue(coord, out existingCell) == false) { throw CellCoordException.NoData(coord); } // TODO perhaps validate the new cell? _world[coord] = cell; Events.Emit <IWorldEventHandler>(h => h.OnCellChanged(coord, existingCell, cell)); return(true); }
public static CellCoordException Invalid(CellCoordinate coord) { return(new CellCoordException("The coordinate is invalid", coord)); }
public CellCoordException(string message, CellCoordinate coord) : base(message) { Coordinate = coord; }
public static CellCoordException NoData(CellCoordinate coord) { return(new CellCoordException("There is no data for the coordinate", coord)); }