예제 #1
0
파일: attack.py 프로젝트: mukolweke/attack
from classes.enemy import Enemy

enemy = Enemy(200, 60)
print("HP:", enemy.get_hp(), "MP:", enemy.get_mp())
예제 #2
0
from classes.enemy import Enemy         #imports the class 'Enemy' from the file 'enemy.py' in the directory 'classes'
                                        #because we imported the class 'Enemy' it can do be called out in this script

enemy = Enemy(200,60)                   #creates an object from the class of Enemy with 200hp and 60mp
print(enemy.get_hp())                   #prints out the hp
print(enemy.get_mp())                   #prints out the mp

'''
option 2
class Enemy:   #a class is a blueprint
    hp = 200   #now all enemys have 200hp

    def __init__(self, atklow, atkhigh):   #creates init function to input low and high attacks
        self.atklow = atklow
        self.atkhigh = atkhigh


    def getAtk(self):                    #function within a class will put 'self' as its parameter
        print("atk is", self.atklow)

    def getHP(self):
        print("HP is", self.hp)


enemy1 = Enemy(40, 49)                        #asign 'enemy1' as type of the class Enemy
enemy1.getAtk()                               #calls out the getAtk function
enemy1.getHP()                                #call out the getHP function

enemy2 = Enemy(75, 90)                        #repeat for 'enemy2'
enemy2.getAtk()
enemy2.getHP()