Compare commits
2 Commits
052582a0e1
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 15c63ae797 | |||
| bc43162d77 |
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Hector",
|
"name": "Hector",
|
||||||
"max_pv": 20,
|
"max_pv": 25,
|
||||||
"current_pv": 20,
|
"current_pv": 20,
|
||||||
"strength": 5,
|
"strength": 5,
|
||||||
"protection": 3,
|
"protection": 3,
|
||||||
|
|||||||
@@ -1,105 +1,58 @@
|
|||||||
import os
|
|
||||||
import sys
|
|
||||||
from enum import Enum
|
|
||||||
|
|
||||||
from base_mob import BaseMob
|
|
||||||
from character_builder import CharacterBuilder
|
from character_builder import CharacterBuilder
|
||||||
from level import Level
|
from level_one import Level
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
class Action(Enum):
|
def action_menu():
|
||||||
PIECE_SUIVANTE = (1, "Pièce suivante")
|
""" Menu Action du niveau """
|
||||||
COMBAT = (2, "Combat")
|
print("\n------ Menu Action ------\n")
|
||||||
FUIR = (3, "Fuir")
|
print("Pièce Suivante :\t 1")
|
||||||
QUITTER = (4, "Quitter")
|
print("Combat : \t\t\t 2")
|
||||||
|
print("Fuir : \t\t\t\t 3")
|
||||||
@property
|
print("Quitter :\t\t\t 4")
|
||||||
def code(self):
|
return int(input("\nChoix : "))
|
||||||
return self.value[0]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def libelle(self):
|
|
||||||
return self.value[1]
|
|
||||||
|
|
||||||
|
|
||||||
def clear_console() -> None:
|
|
||||||
os.system('cls' if os.name == 'nt' else 'clear')
|
|
||||||
|
|
||||||
|
|
||||||
def action_menu(actions_autorisees: list[Action] = None) -> Action:
|
|
||||||
"""Affiche le menu et retourne une action valide."""
|
|
||||||
|
|
||||||
actions_autorisees = list(Action) if actions_autorisees is None else actions_autorisees
|
|
||||||
|
|
||||||
while True:
|
|
||||||
print("\n------ Menu Action ------\n")
|
|
||||||
|
|
||||||
for action in actions_autorisees:
|
|
||||||
print(f"{action.libelle:<20} : {action.code}")
|
|
||||||
|
|
||||||
try:
|
|
||||||
choix = int(input("\nChoix : "))
|
|
||||||
clear_console()
|
|
||||||
for action in actions_autorisees:
|
|
||||||
if action.code == choix:
|
|
||||||
return action
|
|
||||||
|
|
||||||
print("Mauvais choix")
|
|
||||||
except ValueError:
|
|
||||||
clear_console()
|
|
||||||
print("Veuillez saisir un nombre.")
|
|
||||||
|
|
||||||
|
|
||||||
def play_room(room: list[BaseMob], level: Level) -> int:
|
|
||||||
if room is None:
|
|
||||||
print("\n ------ Pièce vide ------ \n")
|
|
||||||
return 1
|
|
||||||
|
|
||||||
for mob in room:
|
|
||||||
print(f"Un {mob.name} est devant toi !")
|
|
||||||
match action_menu([Action.COMBAT, Action.FUIR]):
|
|
||||||
case Action.COMBAT:
|
|
||||||
level.combat(mob, level.player)
|
|
||||||
if level.player.current_pv <= 0:
|
|
||||||
print("!!!!!!!!! Joueur mort !!!!!!!!!!")
|
|
||||||
sys.exit(0)
|
|
||||||
if mob.current_pv == 0:
|
|
||||||
print(f"Le {mob.name} est mort !!")
|
|
||||||
case Action.FUIR:
|
|
||||||
print("Tu fuis la pièce")
|
|
||||||
return 0
|
|
||||||
|
|
||||||
return 1
|
|
||||||
|
|
||||||
|
|
||||||
def play_donjon(level: Level) -> None:
|
|
||||||
while level.exit_level:
|
|
||||||
print(f"Pièce actuelle : {level.current_room_index}")
|
|
||||||
match action_menu([Action.PIECE_SUIVANTE, Action.QUITTER]):
|
|
||||||
case Action.PIECE_SUIVANTE:
|
|
||||||
if level.current_room_index >= len(level.rooms):
|
|
||||||
print("fin du donjon !")
|
|
||||||
break
|
|
||||||
level.current_room_index += play_room(level.rooms[level.current_room_index], level)
|
|
||||||
level.player.current_pv = level.player.max_pv
|
|
||||||
case Action.QUITTER:
|
|
||||||
level.exit_level = False
|
|
||||||
print(f"Au revoir {level.player.name} !")
|
|
||||||
|
|
||||||
|
|
||||||
def app(character_name: str) -> None:
|
|
||||||
loaded_character = CharacterBuilder.load_character(character_name)
|
|
||||||
if not loaded_character:
|
|
||||||
sys.exit(-1)
|
|
||||||
|
|
||||||
print(loaded_character)
|
|
||||||
|
|
||||||
level = Level(2, loaded_character)
|
|
||||||
print(f"Nombre de pièce dans le donjon : {len(level.rooms)}")
|
|
||||||
|
|
||||||
play_donjon(level)
|
|
||||||
|
|
||||||
|
|
||||||
# Exemple d'utilisation
|
# Exemple d'utilisation
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app(character_name=sys.argv[1] if len(sys.argv) > 1 else "Jamin")
|
loaded_character = CharacterBuilder.load_character("Jamin")
|
||||||
|
if loaded_character:
|
||||||
|
print(loaded_character)
|
||||||
|
|
||||||
|
level = Level(2, CharacterBuilder.load_character("Jamin"))
|
||||||
|
player = level.player
|
||||||
|
rooms = level.rooms
|
||||||
|
number_room = len(rooms)
|
||||||
|
print(f"Nombre de pièce dans le donjon : {number_room}")
|
||||||
|
|
||||||
|
while level.exit_level:
|
||||||
|
os.system('cls' if os.name == 'nt' else 'clear')
|
||||||
|
match action_menu():
|
||||||
|
case 1:
|
||||||
|
if level.current_room_index >= number_room:
|
||||||
|
print("fin du donjon !")
|
||||||
|
break
|
||||||
|
room = rooms[level.current_room_index]
|
||||||
|
print(f"Pièce actuelle : {level.current_room_index}")
|
||||||
|
if room is not None:
|
||||||
|
for mob in room:
|
||||||
|
print(f"Un {mob.name} est devant toi !")
|
||||||
|
match action_menu():
|
||||||
|
case 2:
|
||||||
|
level.combat(mob, player)
|
||||||
|
if player.current_pv <= 0:
|
||||||
|
print("!!!!!!!!! Joueur mort !!!!!!!!!!")
|
||||||
|
break
|
||||||
|
if mob.current_pv == 0:
|
||||||
|
print(f"Le {mob.name} est mort !!")
|
||||||
|
case 3:
|
||||||
|
print("Tu fuis la pièce")
|
||||||
|
else:
|
||||||
|
print("\n ------ Pièce vide ------ \n")
|
||||||
|
player.current_pv = player.max_pv
|
||||||
|
level.current_room_index += 1
|
||||||
|
case 4:
|
||||||
|
level.exit_level = False
|
||||||
|
print(f"Au revoir {player.name} !")
|
||||||
|
case _:
|
||||||
|
print("Mauvais choix")
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
""" Class Level """
|
|
||||||
import random
|
|
||||||
|
|
||||||
import mobs_utils
|
|
||||||
|
|
||||||
|
|
||||||
class Level:
|
|
||||||
""" Class Level """
|
|
||||||
|
|
||||||
def __init__(self, difficulty, player):
|
|
||||||
""" Chargement du niveau """
|
|
||||||
print("Loading Level")
|
|
||||||
self.mobs_in_level = mobs_utils.generate_random_mob_list(random.randint(2, difficulty))
|
|
||||||
self.exit_level = True
|
|
||||||
self.player = player
|
|
||||||
self.rooms = mobs_utils.generate_random_rooms(self.mobs_in_level, difficulty) # Liste des pièces du niveau
|
|
||||||
self.current_room_index = 0 # Index de la pièce actuelle
|
|
||||||
|
|
||||||
print("Level Loaded")
|
|
||||||
|
|
||||||
def combat(self, mob, player):
|
|
||||||
while mob.current_pv > 0 and player.current_pv > 0:
|
|
||||||
if mob.speed > player.speed:
|
|
||||||
mob.perform_attack(player)
|
|
||||||
player.perform_attack(mob)
|
|
||||||
else:
|
|
||||||
player.perform_attack(mob)
|
|
||||||
mob.perform_attack(player)
|
|
||||||
print(f"{player.name} - {player.current_pv} PV")
|
|
||||||
print(f"{mob.name} - {mob.current_pv} PV")
|
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
""" Class Level """
|
||||||
|
import random
|
||||||
|
import mobs_utils
|
||||||
|
from character_builder import CharacterBuilder
|
||||||
|
|
||||||
|
|
||||||
|
class Level():
|
||||||
|
""" Class Level """
|
||||||
|
|
||||||
|
def __init__(self, difficulty, player):
|
||||||
|
""" Chargement du niveau """
|
||||||
|
print("Loading Level")
|
||||||
|
self.mobs_in_level = mobs_utils.generate_random_mob_list(
|
||||||
|
random.randint(2, difficulty))
|
||||||
|
self.exit_level = True
|
||||||
|
self.player = player
|
||||||
|
self.rooms = mobs_utils.generate_random_rooms(
|
||||||
|
self.mobs_in_level, difficulty) # Liste des pièces du niveau
|
||||||
|
self.current_room_index = 0 # Index de la pièce actuelle
|
||||||
|
|
||||||
|
print("Level Loaded")
|
||||||
|
|
||||||
|
def combat(self, mob, player):
|
||||||
|
while (mob.current_pv > 0 and player.current_pv > 0):
|
||||||
|
if mob.speed > player.speed:
|
||||||
|
mob.perform_attack(player)
|
||||||
|
player.perform_attack(mob)
|
||||||
|
else:
|
||||||
|
player.perform_attack(mob)
|
||||||
|
mob.perform_attack(player)
|
||||||
|
print(f"{player.name} - {player.current_pv} PV")
|
||||||
|
print(f"{mob.name} - {mob.current_pv} PV")
|
||||||
|
|
||||||
|
|
||||||
|
def action_menu():
|
||||||
|
""" Menu Action du niveau """
|
||||||
|
print("Pièce Suivante :\t1")
|
||||||
|
print("Quitter :\t\t4")
|
||||||
|
return int(input("Choix : "))
|
||||||
|
|
||||||
|
# Exemple d'utilisation
|
||||||
|
if __name__ == "__main__":
|
||||||
|
level = Level(2, CharacterBuilder.load_character("Jamin"))
|
||||||
|
player = level.player
|
||||||
|
rooms = level.rooms
|
||||||
|
number_room = len(rooms)
|
||||||
|
print(f"Nombre de pièce dans le donjon : {number_room}")
|
||||||
|
|
||||||
|
while level.exit_level:
|
||||||
|
match action_menu():
|
||||||
|
case 1:
|
||||||
|
if level.current_room_index >= number_room:
|
||||||
|
print("fin du donjon !")
|
||||||
|
break
|
||||||
|
room = rooms[level.current_room_index]
|
||||||
|
print(f"Pièce actuelle : {level.current_room_index}")
|
||||||
|
if room:
|
||||||
|
for mob in room:
|
||||||
|
level.combat(mob, player)
|
||||||
|
if player.current_pv <= 0:
|
||||||
|
print("!!!!!!!!! Joueur mort !!!!!!!!!!")
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print("Pièce vide")
|
||||||
|
player.current_pv = player.max_pv
|
||||||
|
level.current_room_index += 1
|
||||||
|
case 4:
|
||||||
|
level.exit_level = False
|
||||||
|
print(f"Au revoir {player.name} !")
|
||||||
|
case _:
|
||||||
|
print("Mauvais choix")
|
||||||
Reference in New Issue
Block a user