Need help with my code. multiple classes

Need help with my code. multiple classes
0

honestly, i don’t even know how to word this. essential following a tutorial on building a basic text game to learn python. added items as a choice for the players and now i am having issues

from classes.game import Person, bcolors
from classes.magic import Spell
from classes.Tech import Tech
from classes.Items import Item

#
fire = Spell("Fire", 10, 120, "Natural")
ice = Spell("Ice", 10, 120, "Natural")
bolt = Spell("Bolt", 10, 120, "Natural")

# Unnatural
fire_b = Spell("Black Fire", 20, 230, "Unnatural")
ice_v = Spell("Void Freeze", 20, 230, "Unnatural")

# Support
def_up = Spell("Barrier", 8, 320, "Support")
cure = Spell("Heal", 4, 120, "Support")
cura = Spell("Cura", 12, 200, "Support")

# Items
potion = Item("Potion", "potion", "Heals 100 HP", 100)
hi_potion = Item("Hi-Potion", "potion", "Heals for 150 HP", 150)
S_potion = Item("Super Potion", "potion", "Heals for 150 HP", 600)
elixer = Item("Elixer", "elixer", "fully restores hp/mp of one member", 9999)
Sticky_icky = Item("Bud", "smoke", "the stickiest of the icky", 9999)

grenade = Item("Grenade", "attack", "Deals 500 damage", 500)

# Sword
slash = Tech("Slash", 6, 115, "Sword")

player_items = [potion, hi_potion, S_potion, elixer, Sticky_icky, grenade]
player_spells = [fire, ice, bolt, cure, cura]
enemy_spells = [fire_b, ice_v]

player = Person(500, 220, 210, 70, 45, player_items, player_spells, [slash])

enemy = Person(4200, 765, 345, 85, 70, enemy_spells, [slash], [])

running = True
i = 0

print(bcolors.FAIL
      + bcolors.BOLD
      + "The Clapper Attacks!"
      + bcolors.ENDC)

while running:
    print("=======================")
    player.choose_action()
    choice = input("Choose action ")
    index = int(choice) - 1

    if index == 0:
        dmg = player.generate_damage()
        enemy.take_damage(dmg)
        print("You attacked for ",
              dmg, "points of damage. ")

    elif index == 1:
        player.choose_magic()
        magic_choice = int(input("choose magic ")) - 1

        spell = player.magic[magic_choice]
        magic_dmg = spell.generate_damage()

        magic_dmg = player.magic[magic_choice].generate_damage()
        current_mp = player.get_mp()

        if spell.cost > current_mp:
            print(bcolors.FAIL + "\nNot enough mp\n" + bcolors.ENDC)
            continue

        if spell.type == "Support":
            player.reduce_mp(spell.cost)
            player.heal(magic_dmg)
            print(bcolors.OKBLUE + "\n"
                  + spell.name + " heals for",
                  str(magic_dmg), "HP."
                  + bcolors.ENDC)

        elif spell.type == "Natural":
            player.reduce_mp(spell.cost)
            enemy.take_damage(magic_dmg)
            print(bcolors.OKBLUE
                  + "\n"
                  + spell.name
                  + " deals", str(magic_dmg), "points of damage"
                  + bcolors.ENDC)

        elif spell.type == "Unnatural":
            player.reduce_mp(spell.cost)
            enemy.take_damage(magic_dmg)
            print(bcolors.OKBLUE
                  + "\n"
                  + spell.name
                  + " deals", str(magic_dmg), "points of damage"
                  + bcolors.ENDC)

    elif index == 2:
        player.choose_skill()
        skill_choice = int(input("choose skill ")) - 1

        tech = player.skills[skill_choice]
        skill_dmg = tech.generate_damage()

        skill_dmg = player.skills[skill_choice].generate_damage()
        current_sp = player.get_sp()

        current_sp = player.get_sp()

        if tech.cost > current_sp:
            print(bcolors.FAIL + "\nNot enough sp\n" + bcolors.ENDC)
            continue

        player.reduce_sp(tech.cost)
        enemy.take_damage(skill_dmg)
        print(bcolors.OKBLUE
              + "\n"
              + tech.name
              + " deals", str(skill_dmg), "points of damage"
              + bcolors.ENDC)

    elif index == 3:
        player.choose_item()
        item_choice = int(input("choose item ")) - 1
        item = player.items[item_choice]

    enemy_choice = 1

    enemy_dmg = enemy.generate_damage()
    player.take_damage(enemy_dmg)
    print("The Clapper attacks for",
          enemy_dmg)

    print("----------------------------")
    print("Enemy HP:", bcolors.FAIL
          + str(enemy.get_hp()) + "/"
          + str(enemy.get_max_hp())
          + bcolors.ENDC + "\n")

    print("Player HP:", bcolors.OKGREEN
          + str(player.get_hp()) + "/"
          + str(player.get_max_hp())
          + bcolors.ENDC)

    print("Player MP:", bcolors.OKBLUE
          + str(player.get_mp()) + "/"
          + str(player.get_max_mp())
          + bcolors.ENDC)

    print("Player SP:", bcolors.WARNING
          + str(player.get_sp()) + "/"
          + str(player.get_max_sp())
          + bcolors.ENDC + "\n")

    if enemy.get_hp() == 0:
        print(bcolors.OKGREEN
              + "You Clapped the Clapper!"
              + bcolors.ENDC)
        running = False
    elif player.get_hp() == 0:
        print("You got Clapped, "
              + bcolors.FAIL
              + bcolors.UNDERLINE
              + "Bitch boy!"
              + bcolors.ENDC)
        running = False

classes (game, magic, tech, Items) 

import random



class bcolors:
    HEADER = '\033[95m'
    OKBLUE = '\033[94m'
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'
    BOLD = '\033[1m'
    UNDERLINE = '\033[4m'


class Person:
    def __init__(self, hp, mp, sp, atk, df, magic, skills, items):
        self.maxhp = hp
        self.hp = hp
        self.maxmp = mp
        self.mp = mp
        self.maxsp = sp
        self.sp = sp
        self.atkL = atk - 10
        self.atkH = atk + 20
        self.df = df
        self.magic = magic
        self.items = items
        self.skills = skills
        self.actions = ["Attack", "Magic", "Skills", "Items"]

    def generate_damage(self):
        return random.randrange(self.atkL, self.atkH)

    def take_damage(self, dmg):
        self.hp -= dmg
        if self.hp < 0:
            self.hp = 0
        return self.hp

    def heal(self, restore):
        self.hp += restore
        if self.hp > self.maxhp:
            self.hp = self.maxhp
        return self.hp

    def get_hp(self):
        return self.hp

    def get_max_hp(self):
        return self.maxhp

    def get_mp(self):
        return self.mp

    def get_max_mp(self):
        return self.maxmp

    def get_sp(self):
        return self.sp

    def get_max_sp(self):
        return self.maxsp

    def reduce_mp(self, cost):
        self.mp -= cost

    def reduce_sp(self, cost_2):
        self.sp -= cost_2

    def choose_action(self):
        i = 1
        print(bcolors.OKBLUE
              + bcolors.BOLD + "Actions"
              + bcolors.ENDC)
        for item in self.actions:
            print(str(i) + ":", item)
            i += 1

    def choose_magic(self):
        i = 1

        print(bcolors.OKBLUE
              + bcolors.BOLD + "Magic"
              + bcolors.ENDC)
        for spell in self.magic:
            print(str(i)
                  + ".", spell.name,
                  ":", str(spell.cost) + ")")
            i += 1

    def choose_skill(self):
        i = 1

        print(bcolors.WARNING
              + bcolors.BOLD + "Skills"
              + bcolors.ENDC)
        for tech in self.skills:
            print(str(i)
                  + ".", tech.name,
                  ":", str(tech.cost) + ")")
            i += 1

    def choose_item(self):
        i = 1

        print(bcolors.OKGREEN
              + bcolors.BOLD + "Items"
              + bcolors.ENDC)
        for item in self.items:
            print(str(i)
                  + ".", item.name,
                  ":", item.description, " (x5)")
            i += 1

import random

class Spell:
    def __init__(self, name, cost, dmg, type):
        self.name = name
        self.cost = cost
        self.dmg = dmg
        self.type = type

    def generate_damage(self):
        low = self.dmg - 15
        high = self.dmg + 15
        return random.randrange(low, high)

import random


class Tech:
    def __init__(self, name, cost, dmg, type):
        self.name = name
        self.cost = cost
        self.dmg = dmg
        self.type = type
        # self.description = description

    def generate_damage(self):
            low = self.dmg - 15
            high = self.dmg + 15
            return random.randrange(low, high)



class Item:
    def __init__(self, name, type, description, prop):
        self.name = name
        self.type = type
        self.description = description
        self.prop = prop

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

1 Like