Skip to content

Commit

Permalink
Changelist :
Browse files Browse the repository at this point in the history
- added fight
- added Character.attacks()
  • Loading branch information
gb85150 committed Oct 29, 2021
1 parent ce68ac5 commit 20234ad
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 5 deletions.
1 change: 1 addition & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions classes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from helper import generate2
from helper import generate2, fight


class Game:
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
60 changes: 59 additions & 1 deletion helper.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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=' ')
Expand Down
3 changes: 1 addition & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from classes import *
from helper import print_grid
# from helper import print_grid

"⚔💰🌀👑"
"""
Expand All @@ -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()

0 comments on commit 20234ad

Please sign in to comment.