Compare commits

...

2 commits

Author SHA1 Message Date
9e8b7a3e40
Change witch function 2025-09-04 23:17:30 +02:00
28aeb84c50
Change choose system for the witch and revert commit c55315fa3e 2025-09-04 22:53:58 +02:00
3 changed files with 62 additions and 30 deletions

2
.gitignore vendored
View file

@ -199,7 +199,7 @@ cython_debug/
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
# and can be added to the global gitignore or merged into this file. However, if you prefer,
# you could uncomment the following to ignore the entire vscode folder
.vscode/
# .vscode/
# Ruff stuff:
.ruff_cache/

5
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,5 @@
{
"cSpell.words": [
"potionchoice"
]
}

85
main.py
View file

@ -23,7 +23,7 @@ class Game:
# Dead this night
self.dead_this_night: [List[str]] = []
# Used potions
self.used_potions: [list[str]] = []
# -------------------------
@ -120,6 +120,31 @@ class Game:
log.debug("Fuzz score: %s" % fuzz_score)
return fuzz_player
def choose_between(self, options):
#Prompt the user to choose between options until a valid one is entered
options_available = ', '.join(map(str, options))
#Make a prompt with a list of options, accepting either a list or a tuple.
prompt = f"Choose between {options_available}: "
while True:
selected = input(prompt)
if selected in options:
return selected
# fuzzy matching
match = process.extract(selected, options, limit=1)
log.debug(match)
if match:
fuzz_option, fuzz_score = match[0][0], match[0][1] #options, score
log.debug(fuzz_option)
log.debug(fuzz_score)
if fuzz_score >= 60:
log.info("You meant %s!", fuzz_option)
log.debug("Fuzz score: %s" % fuzz_score)
return fuzz_option
# -------------------------
# game actions
# -------------------------
@ -248,35 +273,37 @@ class Game:
@role
def witch(self) -> None:
"""Interactively choose to kill or revive someone"""
log.info("Choose if you want to use your revive potion")
print(self.players)
while True:
potionchoice = input("What do you want to use Revive or Death potion: ")
if potionchoice == "Revive" and "Revive" not in self.used_potions:
player = self.select_someone()
if player in self.dead_this_night:
self.used_potions.append("Revive")
self.revive(player)
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.")
if len(self.used_potions) == 2:
log.info("You already used all of your potions. ")
else:
while True:
options = ("Death", "Revive", "Nothing")
potionchoice = self.choose_between(options)
if potionchoice == "Revive" and "Revive" not in self.used_potions:
player = self.select_someone()
if player in self.dead_this_night:
self.used_potions.append("Revive")
self.revive(player)
return
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.")
else:
log.info("This player is not dead.")
elif potionchoice == "Death" and "Death" not in self.used_potions:
player = self.select_someone()
if self.players[player].alive:
self.used_potions.append("Death")
self.kill(player)
return
elif not self.players[player].alive:
self.used_potions.append("Death")
return
elif potionchoice == "Nothing":
log.info("You are not doing anything tonight.")
return
elif player not in self.dead_this_night:
log.info("This player didn't died this night.")
elif "Revive" not in self.used_potions:
log.info("This potion is already used.")
elif potionchoice == "Death" and "Death" not in self.used_potions:
player = self.select_someone()
if self.players[player]:
self.used_potions.append("Death")
self.kill(player)
return
elif not self.players[player]:
self.used_potions.append("Death")
return
elif potionchoice in self.used_potions:
log.info("You already used all of your potions")
return
else:
log.info("Please write Revive or Death")
elif potionchoice in self.used_potions:
log.info("You already used this potion.")
# -------------------------
# game flow