首页 > 解决方案 > How do I implement base power in a Python Pokemon game?

问题描述

I have problems implementing the base power code on my Pokemon battle game on Python. Thanks if you wanna help.

Here's my code:

import time
import numpy as np
import sys

# Delay printing
def delay_print(s):
    # print one character at a time
    for c in s:
        sys.stdout.write(c)
        sys.stdout.flush()
        time.sleep(0.05)
        


# Create the class
class Pokemon:
    def __init__(self, name, types, moves, EVs, health='==================='):
        # save variables as attributes
        self.name = name
        self.types = types
        self.moves = moves
        self.attack = EVs['ATTACK']
        self.defense = EVs['DEFENSE']
        self.health = health
        self.bars = 20  # Amount of health bars

    

    def fight(self, Pokemon2):
        print("POKEMON BATTLE WOOOOOOOOOOOO!!!!!!")
        
        print(f"\n{self.name}")
        
        print("TYPE/", self.types)
        
        print("ATTACK/", self.attack)
        
        print("DEFENSE/", self.defense)
        
        print("LVL/", 3 * (1 + np.mean([self.attack, self.defense])))
        
        print("\nVS")
        
        print(f"\n{Pokemon2.name}")
        
        print("TYPE/", Pokemon2.types)
        
        print("ATTACK/", Pokemon2.attack)
        
        print("DEFENSE/", Pokemon2.defense)
        
        print("LVL/", 3 * (1 + np.mean([Pokemon2.attack, Pokemon2.defense])))

        time.sleep(2)

        # Consider type advantages
        version = ['Fire', 'Water', 'Grass']
        for i, k in enumerate(version):
            if self.types == k:
                # Both are same type
                if Pokemon2.types == k:
                    string_1_attack = '\nIts not very effective...'
                    string_2_attack = '\nIts not very effective...'

                # Pokemon2 is STRONG
                if Pokemon2.types == version[(i + 1) % 3]:
                    Pokemon2.attack *= 2
                    Pokemon2.defense *= 2
                    self.attack /= 2
                    self.defense /= 2
                    string_1_attack = '\nIts not very effective...'
                    string_2_attack = '\nIts super effective!'


                # Pokemon2 is WEAK

                if Pokemon2.types == version[(i + 2) % 3]:
                    self.attack *= 2
                    self.defense *= 2
                    Pokemon2.attack /= 2
                    Pokemon2.defense /= 2
                    string_1_attack = '\nIts super effective!'
                    string_2_attack = '\nIts not very effective...'
            

                # Now for the actual fighting...
                # Continue while pokemon still have health

                while (self.bars > 0) and (Pokemon2.bars > 0):
                    # Print the health of each pokemon
                    print(f"\n{self.name}\t\tHLTH\t{self.health}")
                    print(f"{Pokemon2.name}\t\tHLTH\t{Pokemon2.health}\n")


                print(f"{self.name}, I choose you!")
                for i, x in enumerate(self.moves):
                    print(f"{i + 1}.", x)
                index = int(input('Pick a move: '))
                delay_print(f"\n{self.name} used {self.moves[index - 1]}!")
                time.sleep(1)
                delay_print(string_1_attack)


                # Determine damage
                Pokemon2.bars -= self.attack
                Pokemon2.health = ""


                # Add back bars plus defense boost

                for j in range(int(Pokemon2.bars + .1 * Pokemon2.defense)):
                    Pokemon2.health += "="


                time.sleep(1)
                print(f"\n{self.name}\t\tHLTH\t{self.health}")
                print(f"{Pokemon2.name}\t\tHLTH\t{Pokemon2.health}\n")
                time.sleep(.5)


                # Check to see if Pokemon fainted

                if Pokemon2.bars <= 0:
                    delay_print("\n..." + Pokemon2.name + ' fainted. ' +
                                self.name + " won!")
                break


                # Pokemon2s turn

                print(f"Let's go, {Pokemon2.name}!")
                for i, x in enumerate(Pokemon2.moves):
                    print(f"{i + 1}.", x)
                index = int(input('Pick a move: '))
                delay_print(f"\n{Pokemon2.name} used {Pokemon2.moves[index - 1]}!")
                time.sleep(1)
                delay_print(string_2_attack)


                # Determine damage
                self.bars -= Pokemon2.attack
                self.health = ""


                # Add back bars plus defense boost

                for j in range(int(self.bars + .1 * self.defense)):
                    self.health += "="


                time.sleep(1)
                print(f"{self.name}\t\tHLTH\t{self.health}")
                print(f"{Pokemon2.name}\t\tHLTH\t{Pokemon2.health}\n")
                time.sleep(.5)


                # Check to see if Pokemon fainted;;

                if self.bars <= 0:
                    delay_print("\n..." + self.name + ' fainted. ' +
                                Pokemon2.name + " won!")
                    break


class moves:
    self.firemoves = ["Eruption", "Fire Blast", "Flamethrower", "Overheat"]
    self.watermoves = ["Razor Shell", "Scald", "Hydro Pump", "Surf"]
    self.grassmoves = ["Leaf Storm", "Energy Ball", "Giga Drain", "Solar Beam"]

    def BasePower():
        BasePower =

    def Damage():
        damage = ((2 * Level + 2) * Power * ATTACK / DEFENSE / 50 + 2)
        


money = np.random.choice(5000)
delay_print(f"\nOpponent paid you ${money}. Good luck in the future and win more batttles!\n")

if __name__ == '__main__':
    # Create Pokemon
    Typhlosion = Pokemon(
        'Typhlosion', 'Fire',
        ['Eruption: 150 Base Power, power decreases as health decreases',
         'Fire Blast: 110 Base Power, 10% chance to burn', 'FLamethrower: 90 Base Power, 10% chance to burn',
         'Overheat, 130 Base Power, lowers attack by 2'], {
            'ATTACK': 12,
            'DEFENSE': 8
        })
    Samurott = Pokemon('Samurott', 'Water',
                       ['Razor Shell: 75 Base Power', 'Scald: 80 Base Power', 'Hydro Pump: 120 Base Power',
                        'Surf: 90 Base Power'], {'ATTACK': 10, 'DEFENSE': 10
                                                 })
    Serperior = Pokemon(
        'Serperior', 'Grass',
        ['Leaf Storm: 130 Base Power, lowers attack by 2', 'Energy Ball: 90 Base Power',
         'Giga Drain: 75 Base Power, yo heal 50% of damage dealt',
         'Solar Beam: 120 Base Power, takes two turns to charge'], {
            'ATTACK': 19,
            'DEFENSE': 1
        })

    Typhlosion.fight(Samurott)  # Get them to fight'

So as you can see here, the moves such as Typhlosion's Eruption or Serperior's Leaf Storm doesn't have their base power, as Eruption supposedly have 150 base power in full health, and Leaf Storm should have 130 base power, while dropping your attack by two.

标签: python

解决方案


推荐阅读