public HitResult Hit(Guid gameId, int x, int y) { if (x > 9 || x < 0 || y > 9 || y < 0) { throw new ArgumentException("Value of x and y must be between 0 and 9 (inclusive)"); } var game = _entities.Games.Include(t => t.GameHits).FirstOrDefault(t => t.Id == gameId); if (game == null) { throw new GameNotFoundException("Game with id '" + gameId + "' not found."); } if (game.Completed) { return(HitResult.Create(false, true)); } var newHit = new GameHit { GameId = game.Id, X = x, Y = y }; game.GameHits.Add(newHit); _entities.SaveChanges(); var result = new HitResult(); result.Hit = game.Player2.Cells.Any(t => t.X == x && t.Y == y); if (game.GameHits.Count() == GameHit.MaxValue) { result.Completed = true; game.Completed = true; _entities.SaveChanges(); } return(result); }