import turtle
import random 

class Circuito():
    corredores = []
    __posStartY = (-30, -10, 10, 30)
    __colorTurtle = ('red', 'blue', 'green', 'orange')
    
 #pantalla   
    def __init__(self, width, height):
        self.__screen = turtle.Screen()  #importa la pantalla del módulo #modo privado
        self.__screen.setup(width, height)
        self.__screen.bgcolor('lightgray')
        self.__starLine = -width/2 + 20    #Ancho es 640/2 + y - #Se le suma 20 para establecer un margen
        self.__finishLine = width/2 - 20
 
        self.__createRunners() #invoco a la función corredores
    
    #Grupo de las tortugas   
        
    def __createRunners(self):
        for i in range(4):
            new_turtle = turtle.Turtle()
            new_turtle.color(self.__colorTurtle[i])  
            new_turtle.shape('turtle')
            new_turtle.penup()
            new_turtle.setpos(self.__starLine, self.__posStartY[i])
        #Array de corredores
            self.corredores.append(new_turtle)  #las tortugas se añadiran a la lista  
        
    def competir(self):
        
        hayGanador = False
        
        while not hayGanador:
            for tortuga in self.corredores:
                avance = random.randint(1, 6)
                tortuga.forward(avance)
                
                if tortuga.position()[0] >= self.__finishLine:   #No se puede el operadr in al ser para iterables
                    hayGanador = True
                    print("La tortuga de color {} ha ganado".format(tortuga.color()[0]))
                    break

        
        
        
        
        
        
        
if __name__ == '__main__':
    circuito = Circuito(640, 480)
    circuito.competir()     #invoca la competición