Skip to content

Commit

Permalink
move and update 'engine.py'
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorVangeli committed Oct 8, 2024
1 parent 3143f11 commit cc71257
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions brain_games/games/engine.py → brain_games/engine.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from brain_games.const import ENTER_NAME, GREETING_MESSAGE, ROUNDS_NUMBERS


def play_game(game_round, game_rules: str):
def play_game(get_question_and_answer, game_rules: str):
"""
The logic of the game, which repeats the questions until the user answers
correctly several times in a row
Args:
game_round (Callable): A function that describes one round of the game.
get_question_and_answer (Callable): A function that describes one round
of the game.
game_rules (str): The rules of the game that will be displayed before
the start
"""
Expand All @@ -17,7 +18,7 @@ def play_game(game_round, game_rules: str):
print(game_rules)

for _ in range(ROUNDS_NUMBERS):
question, correct_answer = game_round()
question, correct_answer = get_question_and_answer()
print(f"Question: {question}")
answer = input("Your answer: ").strip().lower()

Expand All @@ -27,8 +28,7 @@ def play_game(game_round, game_rules: str):
print(
f'"{answer}" is wrong answer ;(. '
f'Correct answer was "{correct_answer}".'
)
print(f"Let's try again, {username}!")
f'Let\'s try again, {username}!')
return

print(f"Congratulations, {username}!")
Binary file not shown.
2 changes: 1 addition & 1 deletion brain_games/games/calc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import random

from brain_games.const import CALC_RULES
from brain_games.games.engine import play_game
from brain_games.engine import play_game
from brain_games.utils import get_random_number


Expand Down
2 changes: 1 addition & 1 deletion brain_games/games/even.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from brain_games.const import EVEN_RULES
from brain_games.games.engine import play_game
from brain_games.engine import play_game
from brain_games.utils import get_random_number


Expand Down
2 changes: 1 addition & 1 deletion brain_games/games/gcd.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import math

from brain_games.const import GCD_RULES
from brain_games.games.engine import play_game
from brain_games.engine import play_game
from brain_games.utils import get_random_number


Expand Down
2 changes: 1 addition & 1 deletion brain_games/games/prime.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from brain_games.const import PRIME_RULES
from brain_games.games.engine import play_game
from brain_games.engine import play_game
from brain_games.utils import get_random_number


Expand Down
2 changes: 1 addition & 1 deletion brain_games/games/progression.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from brain_games.const import PROGRESSION_RULES
from brain_games.games.engine import play_game
from brain_games.engine import play_game
from brain_games.utils import get_random_number


Expand Down

0 comments on commit cc71257

Please sign in to comment.