Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion challenge_rst/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ def get_player_name():
return player_name


def add_score(points):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Це ж метод, для додавання балів.
Навіщо оці перекидання чисел туди-сюди?

def add_score(points: int) -> None:
    self.score += points

"""Adding extra scores"""
points += settings.EXTRA_SCORE_POINTS_ADD
return points


def play():
"""Playing engine"""
player_name = get_player_name()
Expand All @@ -26,7 +32,7 @@ def play():
player.attack(enemy)
player.defence(enemy)
except EnemyDown:
player.score_points += settings.EXTRA_SCORE_POINTS_ADD
player.score_points = add_score(player.score_points)
enemy = Enemy(enemy.level + 1)
except GameOver:
break
Expand Down
25 changes: 9 additions & 16 deletions challenge_rst/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ def fight_choice_select():
random_person = str(randint(1, 3))
return random_person

def decrease_health(self, score_down):
def decrease_health(self):
"""Decrease enemy health"""
self.health -= score_down
self.health -= settings.SCORE_ENEMY_DOWN
if self.health > 0:
return self.health
else:
Expand Down Expand Up @@ -68,10 +68,10 @@ def fight_choice_select():
)
return fight_choice

def decrease_health(self, score_down):
def decrease_health(self):
"""Decrease player health"""

self.health_points -= score_down
self.health_points -= settings.SCORE_PLAYER_DOWN
if self.health_points > 0:
return self.health_points
else:
Expand Down Expand Up @@ -110,12 +110,9 @@ def attack(self, enemy: Enemy):
defence_choice = enemy.select_defence()
fight_result = self.fight(attack_choice, defence_choice)
if fight_result == 'win':
try:
print('YOUR ATTACK IS SUCCESSFUL!')
self.score_points += settings.SCORE_PLAYER_ADD
enemy.decrease_health(settings.SCORE_ENEMY_DOWN)
except EnemyDown:
raise
print('YOUR ATTACK IS SUCCESSFUL!')
self.score_points += settings.SCORE_PLAYER_ADD
enemy.decrease_health()
elif fight_result == 'loss':
print('YOUR ATTACK IS FAILED!')
elif fight_result == 'draw':
Expand All @@ -128,13 +125,9 @@ def defence(self, enemy: Enemy):
attack_choice = enemy.select_defence()
fight_result = self.fight(attack_choice, defence_choice)
if fight_result == 'win':
try:
print('YOUR DEFENCE IS FAILED!')
self.decrease_health(settings.SCORE_PLAYER_DOWN)
except GameOver:
raise
print('YOUR DEFENCE IS FAILED!')
self.decrease_health()
elif fight_result == 'loss':
print('YOUR DEFENCE IS SUCCESSFUL!')

elif fight_result == 'draw':
print("IT'S A DRAW!")