Пример #1
0
 public bool IsValidCoordinate(CellCoordinate coord)
 {
     return(coord.X >= 0 &&
            coord.X < Width &&
            coord.Y >= 0 &&
            coord.Y < Height &&
            coord.Floor == 0);
 }
Пример #2
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);
        }
Пример #3
0
        // 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));
        }
Пример #4
0
        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);
        }
Пример #5
0
 public static CellCoordException Invalid(CellCoordinate coord)
 {
     return(new CellCoordException("The coordinate is invalid", coord));
 }
Пример #6
0
 public CellCoordException(string message, CellCoordinate coord)
     : base(message)
 {
     Coordinate = coord;
 }
Пример #7
0
 public static CellCoordException NoData(CellCoordinate coord)
 {
     return(new CellCoordException("There is no data for the coordinate", coord));
 }