public Task <ShipDomainModel> TryGetShip(SearchShipCriteria criteria) { ThrowIfGameNotExists(criteria.Game); long gameId = criteria.Game.Id; int x = criteria.Coordinate.X; int y = criteria.Coordinate.Y; var ships = _ships.GetOrAdd(gameId, id => throw GetDefaultException()); var ship = ships .Where(s => x >= s.Start.X && y >= s.Start.Y) .Where(s => x <= s.End.X && y <= s.End.Y) .FirstOrDefault(); return(Task.FromResult(ship)); }
public async Task <ShipDomainModel> TryGetShip(SearchShipCriteria criteria) { long gameId = criteria.Game.Id; int x = criteria.Coordinate.X; int y = criteria.Coordinate.Y; ShipEntity shipEntity = await _context.Ships .Where(ship => ship.GameId == gameId) .Where(ship => x >= ship.XStart && y >= ship.YStart) .Where(ship => x <= ship.XEnd && y <= ship.YEnd) .Include(ship => ship.Shots) .OrderBy(ship => ship.Id) .AsNoTracking() .AsSplitQuery() .FirstOrDefaultAsync(); if (shipEntity is null) { return(null); } return(CreateShip(shipEntity)); }
private Task <ShipDomainModel> TryKnockShip(GameDomainModel game, ShotDomainModel shot) { SearchShipCriteria criteria = new SearchShipCriteria(game, shot.Point); return(_gameStateRepository.TryGetShip(criteria)); }