I am simulating a person running with an enemy chasing the person. I am struggling in finding the code for the movement of the enemy.
class Person ():
def __init__(self, limits, name)
self.row = 0
self.col = 0
def run(self, limits):
#movement code etc.
I want to be able to take the self.row coordinate from the Person, and be able to use that variable in class Enemy, to determine the movement of Enemy. Throughout the simulation I'll be changing the self.row and self.col of Person so I want the Enemy to be able to follow.
class Enemy ():
def __init__(self, limits, name)
self.row = 0
self.col = 0
def run(self, limits):
if self.row > #the Person's self.row
self.row -= 1
How can I use the variables from class Person and use them in class Enemy to determine the movement?
Edit: If I make an object under class Person, how do I access that object, specifically each self.row or self.col from class Enemy?
person = Person(20, 30)and then get the row by usingperson.rowEnemywould need to be given a specificPersoninstance whose location would direct its movement.PersonandEnemydo this kind of computation. They don't need to know about each other. You need a function (or a "Battlefield" class) to do this which uses both types of objects and understands how they interact.Personis not a kind ofBattlefield, or vice versa.Battlefieldwould CONTAINPersonandEnemyobjects.