private void MoveSpider(Spider spider) { if (spider.Path == null) { spider.Dead = true; } else if (spider.Path.Count > 0) { var next = spider.Path.Pop(); Cell cell; if (!dungeon.TryGetCell(next, out cell)) { cell = new Cell(next.Row, next.Column); cell.Type = CellType.Floor; dungeon[next] = cell; } } else { spider.Dead = true; } }
private IEnumerable <Node> GetNeighbors(Node node, Index goal) { int[][] dirs = new int[4][] { new int[] { 1, 0 }, new int[] { -1, 0 }, new int[] { 0, 1 }, new int[] { 0, -1 }, }; foreach (var dir in dirs) { var index = new Index(node.Row + dir[0], node.Column + dir[1]); Node neighbor; if (environment.TryGetValue(index, out neighbor)) { Cell cell; if (index.Equals(goal) || !dungeon.TryGetCell(index, out cell) || cell.Type == CellType.Floor) { yield return(neighbor); } } } }