voila le code khey
import random
class Player:
def __init__(self, name):
self.name = name
self.location = "cell"
self.has_key = False
class PrisonGame:
def __init__(self):
self.players = []
self.police_locations = ["corridor", "yard", "control_room"]
def add_player(self, player):
self.players.append(player)
def move_player(self, player, new_location):
player.location = new_location
def check_police_presence(self, player):
if player.location in self.police_locations:
return True
return False
def attempt_escape(self, player):
if player.has_key and player.location == "exit":
print(f"{player.name} a réussi à s'évader !")
else:
print(f"{player.name} s'est fait attraper par les flics !")
def main():
game = PrisonGame()
player1 = Player("Joueur 1")
player2 = Player("Joueur 2")
game.add_player(player1)
game.add_player(player2)
while True:
for player in game.players:
print(f"C'est au tour de {player.name}.")
print("1 - Se déplacer")
print("2 - Chercher une clé")
action = input("Que voulez-vous faire ? ")
if action == "1":
new_location = input("Où voulez-vous aller ? ")
game.move_player(player, new_location)
if game.check_police_presence(player):
print("Attention ! Les flics sont là.")
game.attempt_escape(player)
elif action == "2":
if player.location == "cell":
print(f"{player.name} a trouvé une clé !")
player.has_key = True
else:
print("Vous ne pouvez chercher une clé que dans votre cellule.")
if __name__ == "__main__":
main()