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)
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) }
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 }
def __init__(self): self.game_repository = GameRepository()
def __init__(self): self.game_factory = GameFactory() self.game_repository = GameRepository() self.board_factory = BoardFactory()
def __init__(self): self.game_repository = GameRepository() self.attempt_factory = AttemptFactory()