Merge branch 'dev'
This commit is contained in:
commit
b7276da8d8
2 changed files with 85 additions and 2 deletions
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"cSpell.words": [
|
||||
"potionchoice"
|
||||
]
|
||||
}
|
||||
82
main.py
82
main.py
|
|
@ -21,6 +21,11 @@ class Game:
|
|||
# lovers
|
||||
self.lovers: Optional[Tuple[str, str]] = None
|
||||
|
||||
# Dead this night
|
||||
self.dead_this_night: [List[str]] = []
|
||||
|
||||
# Used potions
|
||||
self.used_potions: [list[str]] = []
|
||||
# -------------------------
|
||||
# setup / I/O
|
||||
# -------------------------
|
||||
|
|
@ -95,7 +100,7 @@ class Game:
|
|||
Prompt the user to enter a player name until a valid one is entered.
|
||||
Returns None on EOF/KeyboardInterrupt.
|
||||
"""
|
||||
prompt = prompt or "Enter the name of the player: "
|
||||
prompt = prompt or "Enter the name of the player: "
|
||||
while True:
|
||||
selected = input(prompt).strip()
|
||||
|
||||
|
|
@ -115,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
|
||||
# -------------------------
|
||||
|
|
@ -157,15 +187,18 @@ class Game:
|
|||
for p in self.lovers:
|
||||
# kill them and their lover
|
||||
log.debug("Killed %s", p)
|
||||
self.dead_this_night.append(p)
|
||||
p.alive = False
|
||||
return
|
||||
|
||||
# else just kill them
|
||||
log.debug("Killed %s" % p)
|
||||
log.info("Killed %s" % player)
|
||||
self.dead_this_night.append(player)
|
||||
target.alive = False
|
||||
|
||||
def revive(self, player: str) -> None:
|
||||
"""Revive a player."""
|
||||
log.info("Players that will die this night are: %s", self.dead_this_night)
|
||||
if player not in self.players:
|
||||
log.error("Tried to revive unknown player: %s", player)
|
||||
return
|
||||
|
|
@ -237,6 +270,49 @@ class Game:
|
|||
self.players[protected].protected = True
|
||||
log.debug("Protected: %s", protected)
|
||||
|
||||
@role
|
||||
def witch(self) -> None:
|
||||
"""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("Players who might die are %s", ' '.join(map(str, self.dead_this_night)))
|
||||
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).capitalize()
|
||||
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.")
|
||||
elif self.players[player].alive:
|
||||
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:
|
||||
player = self.select_someone()
|
||||
if self.players[player].alive:
|
||||
self.used_potions.append("Death")
|
||||
self.kill(player)
|
||||
return
|
||||
elif not self.players[player].alive:
|
||||
log.info("This player is already dead.")
|
||||
else:
|
||||
log.info("Unknown error: Invalid player choice")
|
||||
return
|
||||
elif potionchoice == "Nothing":
|
||||
log.info("You are not doing anything tonight.")
|
||||
return
|
||||
elif potionchoice in self.used_potions:
|
||||
log.info("You already used this potion.")
|
||||
else:
|
||||
log.critical("Unknown error: Invalid potion choice.")
|
||||
return
|
||||
|
||||
# -------------------------
|
||||
# game flow
|
||||
|
|
@ -245,6 +321,8 @@ class Game:
|
|||
log.info("All the villagers fall asleep.")
|
||||
self.cupidon()
|
||||
self.savior()
|
||||
self.witch()
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue