diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml index 105ce2d..dd4c951 100644 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -1,5 +1,6 @@ + diff --git a/classes.py b/classes.py index 7db0ca1..a2117c4 100644 --- a/classes.py +++ b/classes.py @@ -1,4 +1,4 @@ -from helper import generate2 +from helper import generate2, fight class Game: @@ -51,7 +51,7 @@ def new_tile_event(self): tile_type = self.grid.grid[self.player1.coordinates[1] - 1][self.player1.coordinates[0] - 1].tile_type if tile_type == 'fight': - raise NotImplementedError('Not implemented yet, sorry for the inconvenience') + fight() elif tile_type == 'loot': raise NotImplementedError('Not implemented yet, sorry for the inconvenience') @@ -189,3 +189,20 @@ def earn_money(self) -> float: total_earnings = base_earnings + base_earnings * (self.luck / 10) self.balance += total_earnings return total_earnings + + def attacks(self, target) -> int: + + if bool(generate2(choice=[True, False], weight=[(1*target.luck), 1])): # True if the enemy avoid the attack + return 0 + + else: + + if generate2(choice=[True, False], weight=[(1*self.luck), 4]): # Critical Hit + + target.health -= self.attack * 2 + return self.attack * 2 + + else: # Regular hit + + target.health -= self.attack + return self.attack diff --git a/helper.py b/helper.py index bd5ab55..d113d7c 100644 --- a/helper.py +++ b/helper.py @@ -1,4 +1,7 @@ +import random import random as r +from main import game1 as g +from classes import Item def generate(choice: list, weight: list) -> str: @@ -30,9 +33,64 @@ def generate2(choice: list, weight: list) -> str: def fight(): - pass + hit_list = [ + 'fait griffé la jambe', + 'fait attrapé le bras', + 'blessé sur un piège', + 'pris un mur' + ] + enemy = g.grid.grid[g.player1.coordinates[1]][g.player1.coordinates[0]].tile.entity + if input(f""" +========================================================================================= +Mince ! Vous tombez sur un ennemi ! +Vous pourriez peut-être courir vers une autre salle... +Pour rappel votre vie est de {g.player1.health} HP. +Voulez-vous combattre ? +""") == 'Y': # Fight case + while g.player1.health > 0 or enemy.health > 0: + # Player1 attack first + result = g.player1.attacks(enemy) + print(f""" +⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔ +Vous infligez -{result}HP à l'ennemi. Sa vie est d'a présent de {enemy.health}HP. +""") + result = enemy.attacks(g.player1) + print(f""" +⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔⚔ +L'ennemi vous attaque ! Vous vous faites {random.choices(hit_list)} et vous subissez -{result}HP. +Votre vie s'élève à présent à {g.player1.health}HP. +""") + + else: # Fleeing case + + if bool(generate2(choice=[True, False], weight=[1, (1 * g.player1.luck)])): + # Test of the success of the extraction + result = enemy.attacks(g.player1) + print(f""" +========================================================================================= +Malheureusement vous vous êtes {random.choices(hit_list)}. Vous subissez {result} dégâts. +""") + + if Item in g.player1.inv: # Verification de l'inventaire + for i in range(len(g.player1.inv)): + if g.player1.inv[i].category == 'potion': + if g.player1.health < 25: + if input(""" +========================================================================================= +Vous êtes à l'abri, voulez-vous vous soigner (Y/N)? +""") == 'Y': + g.player1.heal() + if g.player1.inv[i].category == 'weapon': + if input(""" + ========================================================================================= + Vous êtes à l'abri, vous avez trouvé un arme. Voulez-vous l'équiper (Y/N)? + """) == 'Y': + g.player1.attack += g.player1.inv[i].attack + + +# wondering about moving this to Grid class ? def print_grid(grid) -> None: for i in range(len(grid)): print(("┌───┐\n│ │\n└───┘\n" * len(grid[i])), sep=' ') diff --git a/main.py b/main.py index 7a23678..8fb6ce9 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,5 @@ from classes import * -from helper import print_grid +# from helper import print_grid "⚔💰🌀👑" """ @@ -16,4 +16,3 @@ while game1.player1.health > 0 or game1.player1.coordinates != game1.grid.issue_pos: game1.ask_next_move() game1.new_tile_event() -