#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 27 11:51:33 2021

@author: jb
"""

from turtle import Turtle, Screen
from random import randint

colours = ["red", "blue", "orange", "green", "purple", "yellow"]

screen = Screen()

screen.setup(width=500, height=400)


def create_turtles():
    
    turtle_list = []
    x_start = -230
    y_start = -100
    
    for colour in colours: 
        turt = Turtle()
        turt.shape("turtle")
        turt.color(colour)
        turt.penup()
        
        turt.goto(x_start,y_start)
        y_start = y_start + 50
        
        turtle_list.append(turt)
    
    return turtle_list
    
def show_text(title, prompt):
    user_bet = screen.textinput(title, prompt)
    return user_bet
    

def main():
    
    # Get the desired turtle bet from the user 
    user_bet = show_text("Turtle Race Tote", "Which colour turtle will win the race")
    
    # Init the race state by creating the turtles and placing them at the starting line
    turtle_list = create_turtles()
    
    # Used to keep the race moving until a turtle reaches the finish line
    control = False
    
    winner = ""
    
    while (control == False):
        
        # Loop through the turtle list to move the turtles along the racetrack 
        for turtle in turtle_list:
            
            # Generate a random integer that the turtle moves foward
            x_movement = randint(0, 20)
            turtle.forward(x_movement)
            
            current_pos = turtle.pos()
            
            # If a turtle has reached the finish line, end the race by stopping the while loop
            if (current_pos[0] >=  250): 
                control = True 
                winner = turtle.color()[0]
    
    
    
    if(user_bet == winner): 
        print("Congratulations") 
    else: 
        print("Hard Luck")
        
    print(f"The winner was the {winner} turtle")
    
    screen.bye()

if __name__ == '__main__':
    main()
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 27 11:51:33 2021

@author: jb
"""

from turtle import Turtle, Screen
from random import randint

colours = ["red", "blue", "orange", "green", "purple", "yellow"]

screen = Screen()

screen.setup(width=500, height=400)


def create_turtles():
    
    turtle_list = []
    x_start = -230
    y_start = -100
    
    for colour in colours: 
        turt = Turtle()
        turt.shape("turtle")
        turt.color(colour)
        turt.penup()
        
        turt.goto(x_start,y_start)
        y_start = y_start + 50
        
        turtle_list.append(turt)
    
    return turtle_list
    
def show_text(title, prompt):
    user_bet = screen.textinput(title, prompt)
    return user_bet
    

def main():
    
    # Get the desired turtle bet from the user 
    user_bet = show_text("Turtle Race Tote", "Which colour turtle will win the race")
    
    # Init the race state by creating the turtles and placing them at the starting line
    turtle_list = create_turtles()
    
    # Used to keep the race moving until a turtle reaches the finish line
    control = False
    
    winner = ""
    
    while (control == False):
        
        # Loop through the turtle list to move the turtles along the racetrack 
        for turtle in turtle_list:
            
            # Generate a random integer that the turtle moves foward
            x_movement = randint(0, 20)
            turtle.forward(x_movement)
            
            current_pos = turtle.pos()
            
            # If a turtle has reached the finish line, end the race by stopping the while loop
            if (current_pos[0] >=  250): 
                control = True 
                winner = turtle.color()[0]
    
    
    
    if(user_bet == winner): 
        print("Congratulations") 
    else: 
        print("Hard Luck")
        
    print(f"The winner was the {winner} turtle")
    
    screen.bye()

if __name__ == '__main__':
    main()
#!/usr/bin/env python3 # -*- coding: utf-8 -*- Created on Mon Sep 27 11:51:33 2021  @author: jb # Get the desired turtle bet from the user # Init the race state by creating the turtles and placing them at the starting line # Used to keep the race moving until a turtle reaches the finish line # Loop through the turtle list to move the turtles along the racetrack # Generate a random integer that the turtle moves foward # If a turtle has reached the finish line, end the race by stopping the while loop