Hello everyone!
Here is the thing. So I wanted at first to create Robot class, I want him to move around some board. Maybe 10x10 or something like that, then i wanted to invent a Robot fights class, I want to add class players (becuase i want to play between player 1 and player 2) but here it is what I have so much.
Lets focus on this code because I want it to make it much better then start to create robot fights!
class Robot: def __init__(self, name, place, start = (0,0), power = 9): self.name = name self.start = start self.place = place self.power = power def get_name(self): return self.name def get_start(self): return self.start def get_place(self): return self.place def get_power(self): return self.power def set_name(self, x): if isinstance(x, str): self.name = x else: raise TypeError("must be a string") def set_start(self, x): if isinstance(x, tuple): self.start = x else: raise TypeError("must be a tuple") def set_place(self, x): if isinstance(x, list): self.place = x else: raise TypeError("must be a list") def set_power(self, x): if isinstance(x, int): self.power = x else: raise TypeError("must a int") def check_power(self): if self.power <= 0: raise ValueError("No power") def left(self, value): self.check_power() self.power -= value if self.place[0] - value < 0: self.place[0] = self.place[0] - value + 8 else: self.place[0] = self.place[0] - value def up(self, value): self.check_power() self.power -= value if self.place[1] + value > 7: self.place[1] = self.place[1] + value - 8 else: self.place[1] = self.place[1] + value if self.place[1] == 5: self.power += 2 def __str__(self): return self.name, self.place, self.power
Also want I want to make better in this one. Well power will be important in the Robot fights, because if some robot from player 1 will be near to robot from player 2 I want them to you know, fight, so the power will be pretty good right there, if they will be near to each other the power will decrease until the robot is destroyed. But lets focus on above code to make it better.
Any tips how to make this SHORTER and more neat, closer to a advanced or just better solution will be definitely on point.
Have a great day!