예제 #1
0
class CreateGameUseCase(object):
    def __init__(self):
        self.game_factory = GameFactory()
        self.game_repository = GameRepository()
        self.board_factory = BoardFactory()

    def create(self):
        board = self.board_factory.create()

        game = self.game_factory.create(board=board)

        self.game_repository.persist(game=game)

        return game
class CreateSecretCodeUseCase(object):

    def __init__(self):
        self.game_repository = GameRepository()

    def create(self, game_id, secret_code):
        game = self.game_repository.get_by_id(game_id)

        board = game.board

        board.secret_code = secret_code

        game.board = board

        self.game_repository.persist(game)
예제 #3
0
class GuessUseCase(object):
    def __init__(self):
        self.game_repository = GameRepository()
        self.attempt_factory = AttemptFactory()

    def check(self, game_id, guess_code):
        game = self.game_repository.get_by_id(game_id)

        attempt = self.attempt_factory.create(board=game.board,
                                              guess_code=guess_code)

        game.attempts.append(attempt)

        self.game_repository.persist(game)

        return {
            'feedback': attempt.get_feedback(),
            'num_of_attempts': len(game.attempts)
        }
예제 #4
0
class GetGameHistoryUseCase(object):
    def __init__(self):
        self.game_repository = GameRepository()

    def get_history(self, game_id):
        game = self.game_repository.get_by_id(game_id=game_id)

        return {
            'num_of_attempts': len(game.attempts),
            'attempts': game.attempts
        }
예제 #5
0
 def __init__(self):
     self.game_repository = GameRepository()
예제 #6
0
 def __init__(self):
     self.game_factory = GameFactory()
     self.game_repository = GameRepository()
     self.board_factory = BoardFactory()
예제 #7
0
 def __init__(self):
     self.game_repository = GameRepository()
     self.attempt_factory = AttemptFactory()