コード例 #1
0
 public IEnumerable <GameCell> GetAdjacentCells(Pos2D pos)
 {
     foreach (var dir in new[] { MoveDirection.Up, MoveDirection.Right, MoveDirection.Down, MoveDirection.Left })
     {
         var cell = GetCell(pos.GetNeighbor(dir));
         if (cell != null)
         {
             yield return(cell);
         }
     }
 }
コード例 #2
0
        public void MoveObject(GameObjectBase obj, Pos2D newPos)
        {
            var currentCell = GetCell(obj.Pos);

            currentCell?.RemoveObject(obj);

            var newCell = GetCell(newPos);

            newCell.AddObject(obj);

            ClearVisibilityCache();
        }
コード例 #3
0
        private static Pos2D CreatePos2DFromString(string input)
        {
            if (string.IsNullOrWhiteSpace(input))
            {
                return(new Pos2D());
            }

            var strings = input.Split(',');

            var pos = new Pos2D(int.Parse(strings[0]), int.Parse(strings[1]));

            return(pos);
        }
コード例 #4
0
        public IEnumerable <GameObjectBase> GetTargetsAtPos(Pos2D pos)
        {
            var cell = GetCell(pos);

            if (cell == null)
            {
                yield break;
            }

            foreach (var obj in cell.Objects.Where(o => o.IsTargetable))
            {
                yield return(obj);
            }
        }
コード例 #5
0
        public IEnumerable <GameCell> GetCellAndAdjacent(Pos2D pos)
        {
            var cell = GetCell(pos);

            if (cell != null)
            {
                yield return(cell);
            }

            foreach (var adjacentCell in GetAdjacentCells(pos))
            {
                yield return(adjacentCell);
            }
        }
コード例 #6
0
        public bool HasSightBlocker(Pos2D pos)
        {
            // Attempt to grab from cache
            if (_sightBlockerCache.ContainsKey(pos))
            {
                return(_sightBlockerCache[pos]);
            }

            // Calculate whether or not things have a sight blocker
            var cell            = GetCell(pos);
            var hasSightBlocker = cell != null && cell.BlocksSight;

            // Cache it for next time
            _sightBlockerCache[pos] = hasSightBlocker;

            return(hasSightBlocker);
        }
コード例 #7
0
        public IEnumerable <GameCell> GetCellsInSquare(Pos2D pos, int radius)
        {
            int minX = pos.X - radius;
            int maxX = pos.X + radius;
            int minY = pos.Y - radius;
            int maxY = pos.Y + radius;

            for (int y = minY; y <= maxY; y++)
            {
                for (int x = minX; x <= maxX; x++)
                {
                    var cell = GetCell(new Pos2D(x, y));

                    if (cell != null)
                    {
                        yield return(cell);
                    }
                }
            }
        }
コード例 #8
0
 /// <summary>
 /// Gets the cell at the specified position, or returns null if no cell was found.
 /// </summary>
 /// <param name="pos">The position.</param>
 /// <returns>The cell.</returns>
 public GameCell GetCell(Pos2D pos) => !CellsDictionary.ContainsKey(pos) ? null : _cells[pos];
コード例 #9
0
 public bool IsPosExterior(Pos2D pos) => pos.X == UpperLeft.X || pos.X == LowerRight.X || pos.Y == LowerRight.Y || pos.Y == UpperLeft.Y;