You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
2.2 KiB
63 lines
2.2 KiB
from game.personnage import Personnage, ClassType, Item, Material
|
|
|
|
from graphics.layers import Sprite, PopUp
|
|
|
|
from random import randint
|
|
|
|
class Game:
|
|
def __init__(self):
|
|
self.personnage = None
|
|
self.ennemy = None
|
|
|
|
def late_init(self):
|
|
self.personnage = Personnage(" ", ClassType.GUERRIER, "player")
|
|
self.ennemy = self.rand_ennemy()
|
|
|
|
def rand_ennemy(self):
|
|
classes = ["GUERRIER", "MAGICIEN", "VOLEUR", "ELFE"]
|
|
noms = ["Bill Gates", "Dark Vador", "Gargamel", "G-Man"]
|
|
return Personnage(noms[randint(0, 3)], ClassType[classes[randint(0, 3)]], "opponant")
|
|
|
|
def init_personnage(self, nom, class_type):
|
|
self.personnage = Personnage(nom, ClassType[class_type], "player")
|
|
|
|
def attack(self, attacker, victim):
|
|
atk_jet = attacker.jet_attaque()
|
|
def_jet = victim.jet_defense()
|
|
if (atk_jet >= def_jet):
|
|
rand = randint(1, 8)
|
|
victim.change_hp(rand + rand * ((attacker.class_type.atkP + attacker.arme.stats.atkP)//100))
|
|
else:
|
|
rand = randint(1, 4)
|
|
attacker.change_hp(rand + rand * ((victim.class_type.defP + victim.arme.stats.defP)//100))
|
|
|
|
if self.personnage.get_hp() == 0:
|
|
for i in range(50):
|
|
PopUp(1, "Vous avez perdu! Relancez le jeu pour continuer...", True)
|
|
if self.ennemy.get_hp() == 0:
|
|
self.ennemy = self.rand_ennemy()
|
|
|
|
potions = ""
|
|
for i in range(randint(0, 3)):
|
|
random = randint(5, 25)
|
|
self.personnage.potions.append(Item(Material.POTION, random))
|
|
potions += f"- Potion de {random}HP\n"
|
|
|
|
random = randint(0, 4)
|
|
arme = ""
|
|
stat = randint(1, 4)
|
|
stats = self.personnage.arme.stats
|
|
if random == 0:
|
|
stats.hp += stat
|
|
arme = f"+ {stat} HP"
|
|
elif random == 1:
|
|
stats.atkP += stat
|
|
arme = f"+ {stat} ATK%"
|
|
elif random == 2:
|
|
stats.defP += stat
|
|
arme = f"+ {stat} DEF%"
|
|
elif random == 3:
|
|
stats.initiative += stat
|
|
arme = f"+ {stat} INITIATIVE"
|
|
|
|
PopUp(1, f"Ennemi vaincu!\n{potions}\n{arme}")
|