Je code un jeu pour m'amuser, mais ma boucle principale à la fin du code ne fonctionne plus (alors qu'elle fonctionnait à un moment). En tout cas, c'est ce que je pense, car au moment de l'exécution la boucle ne fonctionne pas et me demande un input ce qui n'a aucun sens,
Voici le code (c'est normal si des choses n'ont aucun sens il est pas terminé):
from random import *
game = True
class Weapon:
def __init__ (self, name, damage):
self.name = name
self.damage = damage
class Lame(Weapon):
def __init__(self, name, damage, penetration):
super().__init__(name, damage)
self.penetration = penetration
class Shield(Weapon):
def __init__(self, name, damage, shield):
super().__init__(name, damage)
self.shield = shield
class Wand(Weapon):
def __init__(self, name, damage, mana):
super().__init__(name, damage)
self.mana = mana
class HealingWand(Wand):
def __init__(self, name, damage, mana, heal):
super().__init__(name, damage, mana)
self.heal = heal
dagger = Lame("dagger", randint(10, 13), 11)
broadsword = Lame("broadsword", randint(21, 25), 20)
katana = Lame("katana", randint(27, 33), 37)
scutum = Shield("scutum", randint(11, 15), 45)
def destroy_target(target):
del target
class Player:
def __init__ (self, name, health, weapon, speed):
self.name = name
self.health = health
self.weapon = weapon
self.speed = speed
self.level = 1
self.xp = 0
self.active = True
print("Player :", self.name, "| health :", self.health, "| weapon :", self.weapon.name, "| speed =", self.speed)
allies.append(self)
def damage(self, damage_amount):
if self.health > 0:
if self.health < damage_amount:
diff = damage_amount - self.health
self.health -= damage_amount
self.health += diff
else:
self.health -= damage_amount
if self.health == 0:
self.active = False
destroy_target(self)
def attack_player(self, target):
target.damage(self.weapon.damage)
class Enemy:
def __init__ (self, name, health, damage, speed):
self.name = name
self.health = health
self.damage = damage
self.speed = speed
self.active = True
enemies.append(self)
print("A wolf appeared")
print("Enemy :", self.name, "| health :", self.health, "| damage :", self.damage, "| speed :", self.speed)
def __del__(self):
position = enemies.index(self)
del enemies[position]
def damage(self, damage_amount):
if self.health > 0:
if self.health < damage_amount:
diff = damage_amount - self.health
self.health -= damage_amount
self.health += diff
else:
self.health -= damage_amount
if self.health == 0:
self.active = False
enemies = []
allies = []
player1 = Player("ElPapriko", 100, katana, 6)
player2 = Player("Sxbito", 150, dagger, 7)
player3 = Player("Color4x", 100, scutum, 2)
player4 = Player("Cornichon", 125, broadsword, 4)
def check():
for allie in allies:
if allie.active == True:
continue
else:
position = allies.index(allie)
del allies[position]
def print_health_wplayer(target):
print(target.name + "'s health :", str(target.health))
def print_list(list):
global enemies, allies
step = 0
if list == enemies:
print("Enemies :", end=" ")
else:
print("Allies :", end=" ")
while step != len(list):
step += 1
if len(list) > step:
print(list[step-1].name, end=", ")
else:
print(list[step-1].name)
def spawn_enemy():
step = len(enemies)
if step == 1:
enemy1 = Enemy("wolf", 99, 40, 5)
elif step == 2:
enemy2 = Enemy("wolf", 99, 40, 5)
elif step == 3:
enemy3 = Enemy("wolf", 99, 40, 5)
else:
enemy4 = Enemy("wolf", 99, 40, 5)
def attack_all():
step2 = 0
step = 0
all_values = []
turn_order = []
temporary_speed = 0
allies_speed = {}
enemies_speed = {}
for allie in allies:
allies_speed[allie] = allie.speed
for enemy in enemies:
enemies_speed[enemy] = enemy.speed
all_speed = {**allies_speed, **enemies_speed}
for mob in all_speed:
all_values.append(mob.speed)
while step != len(all_speed):
temporary_speed +=1
if temporary_speed in all_values:
for mob in all_speed:
if temporary_speed == mob.speed:
turn_order.insert(0, mob)
print(turn_order)
while game == True:
print("")
dice = randint(1,6)
if dice == 1:
spawn_enemy()
elif dice == 2:
print("Nothing happened")
elif dice == 3:
print("Nothing happened")
elif dice == 4:
print("Nothing happened")
elif dice == 5:
print("Nothing happened")
else:
print("Nothing happened")
attack_all()
print_health_wplayer(player2)
check()
print_list(allies)
print_list(enemies)
player1.attack_player(player2)
print("")