1
0

Cast spells if one of two player fails to cast their spell. Adds player.cast_spell(): Not scripted yet, currently just a placeholder so that cast_spell() prints somethin when called! (and modifies health)

This commit is contained in:
Kwarde 2024-01-15 15:36:37 +01:00
parent 7f6ccb15ef
commit fd8b6567f7
3 changed files with 41 additions and 7 deletions

39
game.py
View File

@ -16,7 +16,7 @@ input_messages = (
def print_turn_message(player: Player): 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 = 0
def round_end(): 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
@ -30,9 +30,9 @@ def round_end():
) )
) )
def get_player_spell_from_input(): def get_player_spell_from_input(player: Player):
while True: while True:
player_input = input(print_turn_message(player1)) player_input = input(print_turn_message(player))
if not player_input: if not player_input:
return [random_combat_spell(), 0] return [random_combat_spell(), 0]
@ -122,13 +122,42 @@ try:
round_end() round_end()
print("== Round {round} ==".format(round=current_round)) print("== Round {round} ==".format(round=current_round))
player1_spell = get_player_spell_from_input() player1_spell, player1_spell_levenshtein_distance = get_player_spell_from_input(player1)
player2_spell = get_player_spell_from_input() player2_spell, player2_spell_levenshtein_distance = get_player_spell_from_input(player2)
# OUTCOME: SPELLS # OUTCOME: SPELLS
# > Get spell succes # > Get spell succes
player1_spell_succes = player1.get_spell_succes_rate(player1_spell) > random.random() * 100
player2_spell_succes = player2.get_spell_succes_rate(player2_spell) > random.random() * 100
print(player1.cast_spell_result(player1_spell, player1_spell_succes))
print(player2.cast_spell_result(player2_spell, player2_spell_succes))
# > Add health if defensive spell was lucky (partial heal, fully heal) # > Add health if defensive spell was lucky (partial heal, fully heal)
if player1_spell_succes and player1_spell.chance_heal_partly_succes():
player1.give_health(MAX_PLAYER_HEALTH * 0.05)
print("<!> {name} casted {spell} above expectations, and receives {hp} health!".format(name=player1.name, spell=player1_spell.name, hp=MAX_PLAYER_HEALTH*0.05))
elif player1_spell_succes and player1_spell.chance_heal_fully_succes() and player1.health < MAX_PLAYER_HEALTH:
player1.give_health(MAX_PLAYER_HEALTH)
print("<!> {name} casted {spell} outstanding! {name} now has full health!".format(name=player1.name, spell=player1_spell.name, hp=MAX_PLAYER_HEALTH*0.05))
#
if player2_spell_succes and player2_spell.chance_heal_partly_succes():
player2.give_health(MAX_PLAYER_HEALTH * 0.05)
print("<!> {name} casted {spell} above expectations, and receives {hp} health!".format(name=player2.name, spell=player2_spell.name, hp=MAX_PLAYER_HEALTH*0.05))
elif player2_spell_succes and player2_spell.chance_heal_fully_succes() and player2.health < MAX_PLAYER_HEALTH:
player2.give_health(MAX_PLAYER_HEALTH)
print("<!> {name} casted {spell} outstanding! {name} now has full health!".format(name=player2.name, spell=player2_spell.name, hp=MAX_PLAYER_HEALTH*0.05))
# > Determine instant winner or skip to next round # > Determine instant winner or skip to next round
if not player1_spell_succes and not player2_spell_succes:
continue
if not player1_spell_succes and player2_spell_succes:
player2.cast_spell(player2_spell, player1)
pass
elif player1_spell_succes and not player2_spell_succes:
player1.cast_spell(player1_spell, player2)
pass
# > Determine fastest spell # > Determine fastest spell
# <!> Spells with speed 100 will always be casted # <!> Spells with speed 100 will always be casted
# > Determine priority # > Determine priority

View File

@ -54,4 +54,9 @@ class Player:
elif (spell.type == SPELL_TYPE_USELESS): elif (spell.type == SPELL_TYPE_USELESS):
return "{name} must not be feeling well, since they casted a non existing spell. Cast FAILED!".format(name=self.name) return "{name} must not be feeling well, since they casted a non existing spell. Cast FAILED!".format(name=self.name)
else: message = "{name} tried to cast '{spell}' but mispronounced it. Cast FAILED!" else: message = "{name} tried to cast '{spell}' but mispronounced it. Cast FAILED!"
return message.format(name=self.name, spell=spell.name) return message.format(name=self.name, spell=spell.name)
def cast_spell(self, spell: Spell, opponent): #: Player ?
# Below is pretty much a placeholder and will be implemented after placing all cast_spell()s in game.py
print("> {} hits {} and does {} damage!".format(self.name, opponent.name, spell.damage))
opponent.health -= spell.damage

View File

@ -73,7 +73,7 @@ spell_lumos_solem = Spell("Lumos Solem", 100, 000, 60, "Blinds
spell_protego = Spell("Protego", 100, 000, 95, "Create a shield that blocks most attacks", SPELL_TYPE_DEFENSE) spell_protego = Spell("Protego", 100, 000, 95, "Create a shield that blocks most attacks", SPELL_TYPE_DEFENSE)
# 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("Reducto", 75, 150, 75, "Blast an object near your opponent")
spell_rictusempra = Spell("Rictusempra", 85, 90, 90, "Causes your opponent to curl up in laughter, tiring them out") 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")