Browse Source

CA MARCHE PRESQUE

old
Kalyax 2 years ago
parent
commit
574bede774
  1. 4
      game/core.py
  2. 29
      game/inventaire.py
  3. 40
      game/personnage.py
  4. 43
      graphics/layers.py
  5. 2
      main.py

4
game/core.py

@ -26,10 +26,10 @@ class Game:
def_jet = victim.jet_defense() def_jet = victim.jet_defense()
if (atk_jet >= def_jet): if (atk_jet >= def_jet):
rand = randint(1, 8) rand = randint(1, 8)
victim.change_hp(rand + rand * ((attacker.class_type.atkP + attacker.stats.atkP)//100)) victim.change_hp(rand + rand * ((attacker.class_type.atkP + attacker.arme.stats.atkP)//100))
else: else:
rand = randint(1, 4) rand = randint(1, 4)
attacker.change_hp(rand + rand * ((victim.class_type.defP + victim.stats.defP)//100)) attacker.change_hp(rand + rand * ((victim.class_type.defP + victim.arme.stats.defP)//100))
if self.personnage.get_hp() == 0: if self.personnage.get_hp() == 0:
for i in range(50): for i in range(50):

29
game/inventaire.py

@ -1,29 +0,0 @@
class Item:
def __init__(self, name):
self.name = name
class Arme(Item):
def __init__(self, name, stats_set):
super().__init__(name)
self.stats_set = stats_set
def equip():
pass
class Inventaire:
def __init__(self):
self.__content = []
def get_content(self):
return self.__content
def add_item(self, item):
if isinstance(Item, item):
self.__content.append(item)
return self
else:
raise ValueError("item attends un objet Item")
def remove_item(self, index):
self.__content.pop(index)
return self

40
game/personnage.py

@ -13,14 +13,12 @@ class StatsSet:
self.initiative = initiative self.initiative = initiative
self.xpcoef = xpcoef self.xpcoef = xpcoef
class ClassType(Enum): class ClassType(Enum):
GUERRIER = StatsSet(20, 10, 15, 5, 8) GUERRIER = StatsSet(20, 10, 15, 5, 8)
MAGICIEN = StatsSet(15, 15, 6, 5, 7) MAGICIEN = StatsSet(15, 15, 6, 5, 7)
VOLEUR = StatsSet(17, 22, 9, 7, 9) VOLEUR = StatsSet(17, 22, 9, 7, 9)
ELFE = StatsSet(12, 30, 1, 5, 10) ELFE = StatsSet(12, 30, 1, 5, 10)
class Personnage: class Personnage:
def __init__(self, nom, class_type, place): def __init__(self, nom, class_type, place):
self.nom = nom self.nom = nom
@ -28,21 +26,22 @@ class Personnage:
self.class_type = class_type.value self.class_type = class_type.value
self.__hp = self.class_type.hp self.__hp = self.class_type.hp
self.stats = StatsSet(0, 0, 0, 0, 0)
self.__xp = 1 self.__xp = 1
self.potions = [Item(Material.POTION, 10)]
self.arme = Item(Material.EPEE, StatsSet(5, 5, 5, 5, 0))
Sprite(3, self.class_name, place) Sprite(3, self.class_name, place)
#self.inventaire =
def jet_attaque(self): def jet_attaque(self):
damage = randint(1, 20) damage = randint(1, 20)
self.change_exp(self.class_type.xpcoef * self.__xp) self.change_exp(self.class_type.xpcoef * self.__xp)
return damage + self.class_type.initiative + self.stats.initiative return damage + self.class_type.initiative + self.arme.stats.initiative
def jet_defense(self): def jet_defense(self):
damage = randint(1, 20) damage = randint(1, 20)
self.change_exp(self.class_type.xpcoef * self.__xp) self.change_exp(self.class_type.xpcoef * self.__xp)
return damage + self.class_type.initiative + self.stats.initiative return damage + self.class_type.initiative + self.arme.stats.initiative
def get_hp(self): def get_hp(self):
return self.__hp return self.__hp
@ -66,11 +65,11 @@ class Personnage:
f"Vie: {self.__hp}", f"Vie: {self.__hp}",
f"Expérience: {self.__xp}", f"Expérience: {self.__xp}",
"Stats (classe + inventaire):", "Stats (classe + inventaire):",
f"- HP: {self.class_type.hp} + {self.stats.hp}", f"- HP: {self.class_type.hp} + {self.arme.stats.hp}",
f"- ATK%: {self.class_type.atkP} + {self.stats.atkP}", f"- ATK%: {self.class_type.atkP} + {self.arme.stats.atkP}",
f"- DEF%: {self.class_type.defP} + {self.stats.defP}", f"- DEF%: {self.class_type.defP} + {self.arme.stats.defP}",
f"- INITIATIVE: {self.class_type.initiative} + {self.stats.initiative}", f"- INITIATIVE: {self.class_type.initiative} + {self.arme.stats.initiative}",
f"- XPCOEF: {self.class_type.xpcoef} + {self.stats.xpcoef}" f"- XPCOEF: {self.class_type.xpcoef} + {self.arme.stats.xpcoef}"
) )
def reduced_stats(self): def reduced_stats(self):
@ -78,3 +77,22 @@ class Personnage:
f"Type: {self.class_name}", f"Type: {self.class_name}",
f"Vie: {self.__hp}", f"Vie: {self.__hp}",
) )
class Item():
def __init__(self, material, stats: int | StatsSet, meta=None):
self.material = material
self.meta = material.value if meta == None else meta
self.stats = stats
class ItemMeta:
def __init__(self, name, description):
self.name = name
self.description = description
class Material(Enum):
POTION = ItemMeta("Potion", "TODO")
EPEE = ItemMeta("Épée", "TODO")
BATON = ItemMeta("Bâton", "TODO")
DAGUE = ItemMeta("Dague", "TODO")
ARC = ItemMeta("Arc", "TODO")

43
graphics/layers.py

@ -8,18 +8,21 @@ from re import match
class GUI(Layer): class GUI(Layer):
"""Calque du menu principal""" """Calque du menu principal"""
def __init__(self, z_index, buttons): def __init__(self, z_index):
super().__init__(z_index, "gui") super().__init__(z_index, "gui")
self.buttons = buttons self.__current = 0
self.current = 0 self.__buttons = ["Attaquer", "Inventaire"]
self.__inventaire = False
self.handle_keys = False self.handle_keys = False
self.__page = 1
def draw(self): def draw(self):
super().draw() super().draw()
if self.__inventaire == False:
x = 1 x = 1
for button in self.buttons: for button in self.__buttons:
color = (Colors.REDBG, Colors.BLACK) if self.buttons[self.current] == button else (Colors.WHITEBG, Colors.BLACK) color = (Colors.REDBG, Colors.BLACK) if self.__buttons[self.__current] == button else (Colors.WHITEBG, Colors.BLACK)
self.put_string(button, x, self.y-10, color) self.put_string(button, x, self.y-10, color)
x += len(button)+1 x += len(button)+1
@ -33,17 +36,35 @@ class GUI(Layer):
for i in range(3): for i in range(3):
self.put_string(ennemy_stats[i], self.x-(self.x-2)//3, self.y-8+i, [Colors.BLUE2]) self.put_string(ennemy_stats[i], self.x-(self.x-2)//3, self.y-8+i, [Colors.BLUE2])
else:
x = 1
for button in self.__buttons:
color = (Colors.REDBG, Colors.BLACK) if self.__buttons[self.__current] == button else (Colors.WHITEBG, Colors.BLACK)
self.put_string(button, x, self.y-10, color)
x += len(button)+1
return self return self
def key_handler(self, key): def key_handler(self, key):
if key == keys.RIGHT and self.current < len(self.buttons)-1: if key == keys.RIGHT and self.__current < len(self.__buttons)-1:
self.current += 1 self.__current += 1
elif key == keys.LEFT and self.current > 0: elif key == keys.LEFT and self.__current > 0:
self.current -= 1 self.__current -= 1
elif key == keys.ENTER and self.current == 0: elif key == keys.ENTER:
if self.__inventaire == False:
if self.__current == 0:
attacker = Screen.instance.game.personnage attacker = Screen.instance.game.personnage
victim = Screen.instance.game.ennemy victim = Screen.instance.game.ennemy
Screen.instance.game.attack(attacker, victim) Screen.instance.game.attack(attacker, victim)
elif self.__current == 1:
self.__inventaire = True
self.__current = 0
self.__buttons = ["Retour", "Potion", Screen.instance.game.personnage.arme.meta.name]
else:
if self.__current == 0:
self.__inventaire = False
self.__buttons = ["Attaquer", "Inventaire"]
class StartPopUp(Layer): class StartPopUp(Layer):

2
main.py

@ -12,7 +12,7 @@ if __name__ == "__main__":
game = Game() game = Game()
screen = Screen(game) screen = Screen(game)
layers.StartPopUp(1) layers.StartPopUp(1)
layers.GUI(2, ["Attaquer", "Inventaire"]) layers.GUI(2)
listener.build_thread(screen).start() listener.build_thread(screen).start()

Loading…
Cancel
Save