Refactor witch function

This commit is contained in:
yoxu 2025-09-06 20:05:20 +02:00
commit a857221bed
Signed by: yoxu
GPG key ID: CC1DC0EBE5E7D4E8

12
main.py
View file

@ -275,12 +275,12 @@ class Game:
"""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))) 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. ")
elif len(self.used_potions) != 2: else:
while True: while True:
options = ("Death", "Revive", "Nothing") options = ("Death", "Revive", "Nothing")
potionchoice = self.choose_between(options).capitalise() potionchoice = self.choose_between(options).capitalize()
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:
@ -289,7 +289,7 @@ 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.")
elif elif self.players[player].alive:
log.info("This player is not dead.") log.info("This player is not dead.")
else: else:
log.info("Unknown error: Invalid player choice") log.info("Unknown error: Invalid player choice")
@ -313,10 +313,6 @@ class Game:
else: else:
log.critical("Unknown error: Invalid potion choice.") log.critical("Unknown error: Invalid potion choice.")
return return
else:
log.critical("Unknown error: Invalid check")
# ------------------------- # -------------------------
# game flow # game flow