示例#1
0
        public static InputTask ZoneFactory(Func <Zone> factory)
        {
            return(new InputTask(InputMode.Area, (cells, selected) => {
                if (cells.Count == 0)
                {
                    return;
                }
                List <Zone> selectedZones = new List <Zone>();
                foreach (ISelectable selectedObject in selected)
                {
                    if (selectedObject is Zone)
                    {
                        selectedZones.Add((Zone)selectedObject);
                    }
                }

                Zone target = factory();
                foreach (Cell cell in cells)
                {
                    if (cell.MovementCost == 0)
                    {
                        continue;
                    }
                    List <Cell> neighbors = cell.GetNeighbors(false);
                    neighbors.Add(cell);
                    foreach (Cell neighbor in neighbors)
                    {
                        if (neighbor != null && neighbor.Zone != null && selectedZones.Contains(neighbor.Zone))                           // This cell has a neighbor that has a selected zone in it
                        {
                            target = neighbor.Zone;
                        }
                    }
                }
                foreach (Cell cell in cells)
                {
                    if (cell.MovementCost == 0)
                    {
                        continue;
                    }
                    target.AddCell(cell);
                }
                if (!cells.First().World.Zones.Contains(target))
                {
                    cells.First().World.AddZone(target);
                }
            }, (cell, spriteBatch) => {
                Zone copy = factory();
                copy.DrawAtCell(spriteBatch, cell, 1.0f, false);
            }, (cells) => {
                foreach (Cell cell in cells)
                {
                    if (cell.Zone != null)
                    {
                        cell.Zone.RemoveCell(cell);
                    }
                }
            }, (cell) => {
                return cell.Zone != null;
            }));
        }