示例#1
0
 public static IEnumerable <Vector2D> Positions <T>(this IPersistentGrid <T> grid)
 {
     foreach (var x in Enumerable.Range(0, grid.Width))
     {
         foreach (var y in Enumerable.Range(0, grid.Height))
         {
             yield return(new Vector2D(x, y));
         }
     }
 }
示例#2
0
        public static Vector2D FindPosition <T>(this IPersistentGrid <T> grid, Func <T, bool> predicate)
        {
            foreach (var position in grid.Positions())
            {
                if (predicate(grid[position]))
                {
                    return(position);
                }
            }

            return(null);
        }
示例#3
0
 public static IPersistentGrid <T> Update <T>(this IPersistentGrid <T> grid, Vector2D position, Func <T, T> updater)
 {
     return(grid.Set(position, updater(grid[position])));
 }
示例#4
0
 public static IPersistentGrid <U> Map <T, U>(this IPersistentGrid <T> grid, Func <T, U> mapper)
 {
     return(new PersistentGrid <U>(grid.Width, grid.Height, p => mapper(grid[p])));
 }
示例#5
0
 public static bool IsValidPosition <T>(this IPersistentGrid <T> grid, Vector2D position)
 {
     return(0 <= position.X && position.X < grid.Width && 0 <= position.Y && position.Y < grid.Height);
 }