public override Item GetItem(Func<Item, bool> predicate, StartAt startAt)
{
if (startAt == StartAt.Random)
return _items.Values.FirstOrDefault(predicate);
for (int y = 0; y < _height; ++y)
{
for (int x = 0; x < _width; ++x)
{
// Reverse index for bottom right start point
var item = startAt == StartAt.TopLeft
? _map[x, y]
: _map[_width - 1 - x, _height - 1 - y];
// Skip empty slots
if (item == null)
continue;
// Take item if it matches predicate
if (predicate(item))
return item;
}
}
return null;
}