Why does it say that my method cant be combined with an int

Viewed 29

Been trying to make a RPG game based around text as my first real project, When I try and code in the attack feature it says that my method (enemy.damage_taken) cant use the operand -= I've tried to learn programming in alot of languages but it wouldnt stick for me, been coding in python for around 5 days now

Code for how the logic and putting everything together

#Imports

from player import Player
from items import Item
from spells import Spells
from monsters import Monster
from gameplay import Fight
#Creating spells
# Type, Name, Damage, Cost
#Below are buff spells
buff_A = Spells("buff", "Buff", 1.1, 5)
buff_B = Spells("buff", "Stronger Buff", 1.3, 15)
buff_C = Spells("buff", "Strongest Buff", 1.5, 50)
#Below Are heal spells
heal_A = Spells("heal", "Heal", 5, 10)
heal_B = Spells("heal", "Stronger Heal", 20, 30)
heal_C = Spells("heal", "Strongest Heal", 50, 100)
#Creating Items
#Type, Name, Description, Amount
potion = Item("potion", "Health Potion", "Heals you for 10 HP", 10)
elixir = Item("elixir", "Mana Potion", "Regains 15 MP", 15)
#Assiging Variables For Player
player_spells = [buff_A, heal_A]
player_items = [potion, elixir]
#Creating player
#NAME, HP, MP, ATK, DEF, SPELLS, ITEMS
player = Player("Nathan", 10, 20, 5, 5, player_spells, player_items)
#Creating monster
cricket = Monster("Cricket", 3, 3, 7)
enemies = [cricket]
#Fight Setup
fighting = True
#gameplay
fight1 = Fight(player, cricket)
running = True
#action = input("Please select an action, Attack, Magic, Items ")
while running:
  print("1 for attack etc.")
  choice = input(player.actions)
  list_chooser = int(choice) - 1

  if list_chooser == 0:
    dmg = player.generate_dmg
    enemies[0].damage_taken(dmg)      # Problem is on this line
    print("You did " + dmg + "damage")

Player file

# IMPORTS

import random

#CLASS PLAYER

class Player():
  def __init__(self, name, hp, mp, atk, df, magic, items):
    self.maxhp = hp
    self.hp = hp
    self.maxmp = mp
    self.mp = mp
    self.atklow = atk - 2
    self.atkhigh = atk + 2
    self.df = df - 100
    self.dfc = df / 100
    self.magic = magic
    self.items = items
    self.actions = ["Attack", "Magic", "Items", "Stats"]
    self.name = name

#Dealing Damage
    
  def generate_dmg(self):  
    return random.randrange(self.atklow, self.atkhigh)
    
#Taking Damage
    
  def take_dmg(self, dmg):
    self.hp -= dmg * self.dfc
    if self.hp < 0:
      self.hp = 0
    return self.hp

  #Healing

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

  #Returning HP Values

  def get_hp(self):
    return self.hp

  def get_maxhp(self):
    return self.maxhp

  #Mana Cost Logic

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

  #Actions
  def get_stats(self):
    print("HP")
    print(self.hp)
    print("--")
    print(self.maxhp)
    print("")
    print("MP")
    print(self.mp)
    print("--")
    print(self.maxmp)
    print("")
    print("ATK")
    print(self.atklow + self.atkhigh)
    print("DEF")
    print(self.dfc)
    

#Monster File

import random
class Monster:
  def __init__(self, name, atk, df, hp):
    self.name = name
    self.atk = atk
    self.hp = hp
    self.maxhp = hp
    self.atklow = self.atk - 2
    self.atkhigh = self.atk + 2
  def damage_dealt(self):
    return random.randrange(self.atklow, self.atkhigh)
  def damage_taken(self, dmg):
    self.hp -= dmg  
    if self.hp < 0:
      self.hp = 0
    return self.hp
  def get_hp(self):
    return self.hp
  def get_maxhp(self):
    return self.maxhp
    
0 Answers
Related