105k views
2 votes
Write a function fight(first_pokemon, second_pokemon) that takes the dictionaries for two pokemon and computes the winner of a fight. The winner of the fight must be the pokemon with the greatest sum of all stats. You must also write a stats(pokemon) function that takes a pokemon's dictionary and returns an integer representing the sum of that pokemon's stats.

2 Answers

3 votes

Answer:

import random

class Pokemon:

"""Blueprint for turn based Pokemon battle"""

def __init__(self, attack_choice):

self.__attack_choice = attack_choice

def attack(self):

if self.__attack_choice == 1:

attack_points = random.randint(18,25)

return attack_points

elif self.__attack_choice == 2:

attack_points = random.randint(10,35)

return attack_points

else:

print("That is not a selection. You lost your turn!")

def heal(self):

heal_points = random.randint(18,25)

return heal_points

###########################################################################

user_health = 100

mew_health = 100

battle_continue = True

while battle_continue == True:

print("\\ATTACK CHOICES\\1. Close range attack\\2. Far range attack\\3. Heal")

attack_choice = eval(input("\\Select an attack: "))

# Mew selects an attack, but focuses on attacking if health is full.

if mew_health == 100:

mew_choice = random.randint(1,2)

else:

mew_choice = random.randint(1,3)

mew = Pokemon(mew_choice)

user_pokemon = Pokemon(attack_choice)

# Attacks by user and Mew are done simultaneously.

if attack_choice == 1 or attack_choice == 2:

damage_to_mew = user_pokemon.attack()

heal_self = 0

print("You dealt",damage_to_mew,"damage.")

if mew_choice == 1 or mew_choice ==2:

damage_to_user = mew.attack()

heal_mew = 0

print("Mew dealt", damage_to_user, "damage.")

if attack_choice == 3:

heal_self = user_pokemon.heal()

damage_to_mew = 0

print("You healed",heal_self,"health points.")

if mew_choice == 3:

heal_mew = mew.heal()

damage_to_user = 0

print("Mew healed", heal_mew, "health points.")

user_health = user_health - damage_to_user + heal_self

mew_health = mew_health - damage_to_mew + heal_mew

# Pokemon health points are limited by a min of 0 and a max of 100.

if user_health > 100:

user_health = 100

elif user_health <= 0:

user_health = 0

battle_continue = False

if mew_health > 100:

mew_health = 100

elif mew_health <= 0:

mew_health = 0

battle_continue = False

print("Your current health is", user_health)

print("Mew's current health is", mew_health)

print("Your final health is", user_health)

print("Mew's final health is", mew_health)

if user_health < mew_health:

print("\\You lost! Better luck next time!")

else:

print("\\You won against Mew!")

Step-by-step explanation:

User Rick Donnelly
by
5.0k points
4 votes

Answer: provided in the explanation section

Step-by-step explanation:

This is actually quite easy to go,i ask that you follow it carefully.

CODE is meant for python3+

CODE

def stats(pokemon):

total=0

#loops over the stats list

for stat in pokemon["stats"]:

# adds the stat to the total

total+=stat["base_stat"]

return total

def fight(first_pokemon,second_pokemon):

#prints the first statemetn

print(first_pokemon["name"],"has",stats(first_pokemon),"combined stats.",second_pokemon["name"],"has",stats(second_pokemon),"combined stats.")

#checks if the first_pokemon wins

if(stats(first_pokemon)>stats(second_pokemon)):

print(first_pokemon["name"],"wins!")

#checks if the second_pokemon wins

elif(stats(first_pokemon)<stats(second_pokemon)):

print(second_pokemon["name"],"wins!")

# it is a draw

else:

print("It is a draw")

cheers i hoped this helped !!!

User Jsgroove
by
5.5k points