1
0

Get player wands, intro to battle, adds spells.random_battle_spell()

This commit is contained in:
Kwarde 2024-01-15 14:56:20 +01:00
parent 7cbcf4dbf4
commit 885f407383
2 changed files with 80 additions and 8 deletions

72
game.py
View File

@ -17,7 +17,7 @@ def print_turn_message(player: Player):
return random.choice(input_messages).format(name=player.name) return random.choice(input_messages).format(name=player.name)
current_round = 1 current_round = 1
def round_end(player1: Player, player2: Player): def round_end():
if (player1.stunned_rounds > 0): player1.stunned_rounds -= 1 if (player1.stunned_rounds > 0): player1.stunned_rounds -= 1
if (player2.stunned_rounds > 0): player2.stunned_rounds -= 1 if (player2.stunned_rounds > 0): player2.stunned_rounds -= 1
@ -53,3 +53,73 @@ while True:
print("Welcome {p1_name} and {p2_name}! You're about to choose a wand to use in this duel! Available wands are:".format(p1_name=player1_name, p2_name=player2_name)) print("Welcome {p1_name} and {p2_name}! You're about to choose a wand to use in this duel! Available wands are:".format(p1_name=player1_name, p2_name=player2_name))
for i in Wand.wandList: for i in Wand.wandList:
print(i) print(i)
#Player 1
while (True):
try:
wand_input = int(input("What wand do you want {name}? (Enter one of the numbers): ".format(name=player1_name)))
except ValueError:
continue
if wand_input < 1 or wand_input > len(Wand.wandList):
continue
player1_wand = Wand.wandList[wand_input-1]
break
#Player 2
while (True):
try:
wand_input = int(input("What wand do you want {name}? (Enter one of the numbers): ".format(name=player2_name)))
except ValueError:
continue
if wand_input < 1 or wand_input > len(Wand.wandList):
continue
player2_wand = Wand.wandList[wand_input-1]
break
player1 = Player(player1_name, player1_wand)
player2 = Player(player2_name, player2_wand)
print()
print("{name} will be fighting with an {wood} wand with a {core} core".format(name=player1.name, wood=player1.wand.get_wand_wood().lower(), core=player1.wand.get_wand_core().lower()))
print("{name} will be fighting with an {wood} wand with a {core} core".format(name=player2.name, wood=player2.wand.get_wand_wood().lower(), core=player2.wand.get_wand_core().lower()))
print("<!> If you need a list of available spells, enter: help (this will not take away a move)")
print("<!> If you need information of a specific spell, enter: help SPELL_NAME")
print("<!> You can press enter (without typing a spell) to cast a random basic combat spell")
print()
print("Alright! Time to duel!")
game_running = True
try:
while (game_running):
current_round += 1
if (current_round != 1):
# Weird, right? To have round_end() at the start of a round.
# There will be multiple conditions where the current iteration will end.
# I'm lazy, hence why it's here :-)
round_end()
print("== Round {round} ==".format(round=current_round))
# INPUT: Player 1
# INPUT: Player 2
# OUTCOME: SPELLS
# > Get spell succes
# > Add health if defensive spell was lucky (partial heal, fully heal)
# > Determine instant winner or skip to next round
# > Determine fastest spell
# <!> Spells with speed 100 will always be casted
# > Determine priority
# 1. Unforgivables
# 2. Protego
# 3. (fastest_spell)
# 4. (other_player)
# CAST SPELLS
# >
except KeyboardInterrupt:
print()
print("<!> Duel ended because both {} and {} suddenly decided to test out their apparition skill!".format(player1.name, player2.name))

View File

@ -1,4 +1,4 @@
from random import random import random
from Levenshtein import distance from Levenshtein import distance
SPELL_TYPE_USELESS = 0 SPELL_TYPE_USELESS = 0
@ -26,8 +26,7 @@ class Spell:
#Class special methods #Class special methods
""" """
name (str) Name of the spell as used in combat name (str) Name of the spell as used in combat
speed (int) Speed of the spell. This will determine what spell hits who in a single move. The spell of the wizard with the lowest spell speed won't hit the player. speed (int) Speed of the spell. This will determine what spell is casted first.
If spells have the same speed, both will be executed
damage (int) Damage that the spell does. damage (int) Damage that the spell does.
<!> Negative damage takes away moves from opponent (eg -2 = cancel 2 moves of opponent) <!> Negative damage takes away moves from opponent (eg -2 = cancel 2 moves of opponent)
succes_rate (int) How much chance for the spell to be succesfully cast. If it fails, spell won't be cast (thus spells with a succes_rate of 0 would never be executed, and 100=always succes) succes_rate (int) How much chance for the spell to be succesfully cast. If it fails, spell won't be cast (thus spells with a succes_rate of 0 would never be executed, and 100=always succes)
@ -75,7 +74,7 @@ spell_protego = Spell("Protego", 100, 000, 95, "Create
# Common combat spells. High chance of succes, deals some damage # Common combat spells. High chance of succes, deals some damage
spell_reducto = Spell("Reduto", 75, 150, 75, "Blast an object near your opponent") spell_reducto = Spell("Reduto", 75, 150, 75, "Blast an object near your opponent")
spell_rictusempra = Spell("Rictusempra", 85, 90, 90, "Causes your opponent to curl up in laughter, making them tired") spell_rictusempra = Spell("Rictusempra", 85, 90, 90, "Causes your opponent to curl up in laughter, tiring them out")
spell_stupefy = Spell("Stupefy", 95, 75, 95, "Knock over your opponent") spell_stupefy = Spell("Stupefy", 95, 75, 95, "Knock over your opponent")
# Powerful combat spells. Medium chance of succes, deals more damage or stuns opponents # Powerful combat spells. Medium chance of succes, deals more damage or stuns opponents
@ -86,16 +85,19 @@ spell_sectusempra = Spell("Sectusempra", 90, 400, 40, "Slices
spell_silencio = Spell("Silencio", 35, -3, 20, "Silences your opponent, causing them unable to cast spells for 3 moves", SPELL_TYPE_POWERFUL) spell_silencio = Spell("Silencio", 35, -3, 20, "Silences your opponent, causing them unable to cast spells for 3 moves", SPELL_TYPE_POWERFUL)
# Unforgivable spells. Very low chance of success, instantly kills or deals alot of damage/stun amount # Unforgivable spells. Very low chance of success, instantly kills or deals alot of damage/stun amount
spell_avada_kedavra = Spell("Avada Kedavra", 100, 9999, 2, "Instantly end your opponent", SPELL_TYPE_UNFORGIVABLE) spell_avada_kedavra = Spell("Avada Kedavra", 100, 999, 2, "Instantly end your opponent", SPELL_TYPE_UNFORGIVABLE)
spell_crucio = Spell("Crucio", 100, 500, 5, "Cause excruciating pain to your opponent, causing alot of damage and making them unable to cast spells for 5 moves", SPELL_TYPE_UNFORGIVABLE) spell_crucio = Spell("Crucio", 100, 500, 5, "Cause excruciating pain to your opponent, causing alot of damage and making them unable to cast spells for 5 moves", SPELL_TYPE_UNFORGIVABLE)
spell_imperio = Spell("Imperio", 100, -1, 3, "Muddle with your opponent's mind, convincing them to stop casting spells for 10 moves", SPELL_TYPE_UNFORGIVABLE) spell_imperio = Spell("Imperio", 100, -1, 3, "Muddle with your opponent's mind, convincing them to stop casting spells for 10 moves", SPELL_TYPE_UNFORGIVABLE)
# spell_none, used as a fallback if an invalid spell was cast ('no object'.method/attribute) # spell_none, used as a fallback if an invalid spell was casted
spell_none = Spell(__INVALID_SPELL, 0, 0, 0, "(internal) invalid spell", SPELL_TYPE_USELESS) spell_none = Spell(__INVALID_SPELL, 0, 0, 0, "(internal) invalid spell", SPELL_TYPE_USELESS)
## ##
## Standalone spell functions ## Standalone spell functions
## ##
def random_combat_spell():
return random.choice([i for i in Spell.spellList if i.type == SPELL_TYPE_COMMON])
def find_spell_by_name(input: str): # Returns a list with: [spell_object, levenshtein_distance]. If distance is greater than 0 (typos were made), damage goes down def find_spell_by_name(input: str): # Returns a list with: [spell_object, levenshtein_distance]. If distance is greater than 0 (typos were made), damage goes down
for i in Spell.spellList: for i in Spell.spellList:
if input.title() == i.name.title(): if input.title() == i.name.title():