Skip to content

Instantly share code, notes, and snippets.

@Alexei-Kornienko
Created March 26, 2019 18:48
Show Gist options
  • Save Alexei-Kornienko/1562a9715f44fcd6d083a61015ac9110 to your computer and use it in GitHub Desktop.
Save Alexei-Kornienko/1562a9715f44fcd6d083a61015ac9110 to your computer and use it in GitHub Desktop.
class GameObject():
def __init__(self,name,level,race):
self.name = name
self.level = level
self.race = race
self.health = 0
def __repr__(self):
return "<%s Level: %s, Country: %s, Health: %s>" % (self.name, self.level, self.race, self.health)
def level_up(self):
if self.level > 10:
self.level += 1
class Bmp(GameObject):
def __init__(self, name, level, race):
super(Bmp, self).__init__(name, level, race)
self.health = 100
self.bullet = 300
self.position = (0, 0)
def move(self, x, y):
print("Hero %s start moving to %s, %s" % (self.name, x, y))
def hit_by(self, bullet):
print("Hit by something!!!")
self.health -= bullet.get_damage()
if self.health <= 0:
self._blow_up()
def _blow_up(self):
print('BOOM!!! We`re all dead')
class Rocket(GameObject):
def __init__(self,name,level,race):
super(Rocket, self).__init__(name, level, race)
self.health = 100
self.bullet = 3
def move(self):
print ("Hero " + self.name + " start moving ")
def get_damage(self):
return 10
tank1 = Bmp("BMP",12,"Germany")
rocket = Rocket("Konkurs",7,"Ukraine")
print(tank1)
print(rocket)
tank1.level_up()
tank1.move(10, 10)
for i in range(20):
tank1.hit_by(rocket)
#tank1.show_hero()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment