self.x-=1; self.y-=1; self.direction="Sud"
elif self.direction=="Sud":
self.x-=1;self.y+=1; self.direction="Ouest"
else:
self.x+=1; self.y+=1;self.direction="Nord"
return self
def __str__(self):
return "le robot: "+ str(self.nom)+ " est à la position: ("+str(self.x)+","+str(self.y)+") et la
direction :"+str(self.direction)
robot=Robot("kingi",5,2,"Nord")
print(robot)
print(robot.avance())
print(robot.droite())
class RobotNG:
turbo=True #un attribut de classe pour l'utiliser on utilise le nom de la classe : RobotNG.turbo
def __init__(self, nom, x=0,y=0,direction="Est"):
self.nom=nom
self.x=x
self.y=y
self.direction=direction
def avance(self,n):
self.x+=n
if RobotNG.turbo==True: self.x*=3
return self
def droite(self):
if self.direction=="Nord":
self.x+=1; self.y-=1; self.direction="Est"
elif self.direction=="Est":
self.x-=1; self.y-=1; self.direction="Sud"
elif self.direction=="Sud":
self.x-=1;self.y+=1; self.direction="Ouest"
else:
self.x+=1; self.y+=1;self.direction="Nord"
return self
def gauche(self):
if self.direction=="Nord":
self.x-=1; self.y-=1; self.direction="Ouest"
elif self.direction=="Est":
self.x-=1; self.y+=1; self.direction="Nord"
elif self.direction=="Sud":
self.x+=1;self.y+=1; self.direction="Est"
else:
self.x+=1; self.y-=1;self.direction="Sud"
return self
def demiTour(self):
return self.gauche().gauche()
3