Fix witch function

This commit is contained in:
yoxu 2025-09-06 15:40:24 +02:00
commit ce60013fbd

21
main.py
View file

@ -274,12 +274,13 @@ class Game:
def witch(self) -> None: def witch(self) -> None:
"""Interactively choose to kill or revive someone""" """Interactively choose to kill or revive someone"""
log.info("With the Revive Potion, you can revive someone, and with the Death Potion, you can kill someone. You can only use each potion once, and you can also choose to do nothing.") log.info("With the Revive Potion, you can revive someone, and with the Death Potion, you can kill someone. You can only use each potion once, and you can also choose to do nothing.")
log.info("Players who might die are %s", ' '.join(map(str, self.dead_this_night)))
if len(self.used_potions) == 2: if len(self.used_potions) == 2:
log.info("You already used all of your potions. ") log.info("You already used all of your potions. ")
else: elif len(self.used_potions) != 2:
while True: while True:
options = ("Death", "Revive", "Nothing") options = ("Death", "Revive", "Nothing")
potionchoice = self.choose_between(options) potionchoice = self.choose_between(options).capitalise()
if potionchoice == "Revive" and "Revive" not in self.used_potions: if potionchoice == "Revive" and "Revive" not in self.used_potions:
player = self.select_someone() player = self.select_someone()
if player in self.dead_this_night: if player in self.dead_this_night:
@ -288,8 +289,11 @@ class Game:
return return
elif player not in self.dead_this_night and not self.players[player].alive: elif player not in self.dead_this_night and not self.players[player].alive:
log.info("You cannot bring this person back to life because they have been buried.") log.info("You cannot bring this person back to life because they have been buried.")
else: elif
log.info("This player is not dead.") log.info("This player is not dead.")
else:
log.info("Unknown error: Invalid player choice")
return
elif potionchoice == "Death" and "Death" not in self.used_potions: elif potionchoice == "Death" and "Death" not in self.used_potions:
player = self.select_someone() player = self.select_someone()
if self.players[player].alive: if self.players[player].alive:
@ -297,13 +301,22 @@ class Game:
self.kill(player) self.kill(player)
return return
elif not self.players[player].alive: elif not self.players[player].alive:
self.used_potions.append("Death") log.info("This player is already dead.")
else:
log.info("Unknown error: Invalid player choice")
return return
elif potionchoice == "Nothing": elif potionchoice == "Nothing":
log.info("You are not doing anything tonight.") log.info("You are not doing anything tonight.")
return return
elif potionchoice in self.used_potions: elif potionchoice in self.used_potions:
log.info("You already used this potion.") log.info("You already used this potion.")
else:
log.critical("Unknown error: Invalid potion choice.")
return
else:
log.critical("Unknown error: Invalid check")
# ------------------------- # -------------------------
# game flow # game flow