diff --git a/api/resources/game.py b/api/resources/game.py index c389fb9..59ceb0c 100644 --- a/api/resources/game.py +++ b/api/resources/game.py @@ -33,7 +33,13 @@ class GameSingleResource(APIView): class GameEventResource(APIView): def get(self, request, game_id): """ Returns a list of all game events """ - events = GameEvent.objects.filter(game_id=game_id) + + try: + game = Game.objects.get(pk=game_id) + except Game.DoesNotExist: + return Response(status=status.HTTP_404_NOT_FOUND) + + events = GameEvent.objects.filter(game=game) serializer = GameEventSerializer(events, many=True) return Response(serializer.data) diff --git a/game/game.py b/game/game.py index 0fa7ba5..8532038 100644 --- a/game/game.py +++ b/game/game.py @@ -72,24 +72,21 @@ class Minesweeper: def is_mine(self, row, col): """ Checks whether the given location have a mine """ - try: - return self.board[row][col] == -1 - except IndexError: + if not self.is_point_in_board(row, col): return False + return self.board[row][col] == -1 def is_empty(self, row, col): """ Checks whether the given location is empty """ - try: - return self.board[row][col] == 0 - except IndexError: + if not self.is_point_in_board(row, col): return False + return self.board[row][col] == 0 def is_point(self, row, col): """ Checks whether the given location have pontuation """ - try: - return self.board[row][col] > 0 - except IndexError: + if not self.is_point_in_board(row, col): return False + return self.board[row][col] > 0 def is_point_in_board(self, row, col): """ Checks whether the location is inside board """