Smipple is shutting down Nov 30, 2017. Some features are currently disabled.
Profile image for Thomas Simonsen simoth00
Roboter Game
Language
Python
Tags
objects

Objects Roboter Game

1 import random 2 3 4 5 class Roboter(object): 6 7 def __init__(self, name, level): 8 self.name = name 9 self.level = level 10 11 def getName(self): 12 print(self.name) 13 14 def getLevel(self): 15 print(self.level) 16 17 def addLevel(self): 18 self.level += 1 19 20 def fight(self, Roboter): 21 rivalScore = Roboter.level * random.randint(1,6) 22 myScore = self.level * random.randint(1,6) 23 24 if myScore <= rivalScore: 25 print("Dein Roboter hat VERLOREN") 26 else: 27 print("Dein Roboter hat GEWONNEN") 28 29 30 class SubRoboter(Roboter): 31 def __init__(self, name, level): 32 Roboter.__init__(self, name, level) 33 34 def fight(self, Roboter): 35 print("Dein Roboter hat gewonnen") 36 37 38 if __name__ == "__main__": 39 40 x = Roboter("R2D2", 2) 41 y = Roboter("R3D3", 4) 42 z = SubRoboter("R4D4", 1) 43 44 x.getName() 45 x.addLevel() 46 x.getLevel() 47 y.fight(x) 48 49 z.fight(x)

Comments