WIP: Add new role witch #2
1 changed files with 56 additions and 29 deletions
Change witch function
commit
9e8b7a3e40
55
main.py
55
main.py
|
|
@ -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"""
|
||||
|
yoxu marked this conversation as resolved
|
||||
log.info("Choose if you want to use your revive potion")
|
||||
print(self.players)
|
||||
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:
|
||||
potionchoice = input("What do you want to use Revive or Death potion: ")
|
||||
options = ("Death", "Revive", "Nothing")
|
||||
potionchoice = self.choose_between(options)
|
||||
|
anavoi marked this conversation as resolved
anavoi
commented
`potionchoice = self.choose_between(options).capitalise()`
|
||||
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:
|
||||
log.info("This player didn't died this night.")
|
||||
elif "Revive" not in self.used_potions:
|
||||
log.info("This potion is already used.")
|
||||
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]:
|
||||
if self.players[player].alive:
|
||||
self.used_potions.append("Death")
|
||||
self.kill(player)
|
||||
return
|
||||
elif not self.players[player]:
|
||||
elif not self.players[player].alive:
|
||||
self.used_potions.append("Death")
|
||||
return
|
||||
elif potionchoice in self.used_potions:
|
||||
log.info("You already used all of your potions")
|
||||
elif potionchoice == "Nothing":
|
||||
log.info("You are not doing anything tonight.")
|
||||
return
|
||||
else:
|
||||
log.info("Please write Revive or Death")
|
||||
|
||||
elif potionchoice in self.used_potions:
|
||||
log.info("You already used this potion.")
|
||||
|
||||
# -------------------------
|
||||
# game flow
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue
So we first ask the user to choose a potion then we tell them that they have no choice.
Would you mind adding a check before asking?