"""
LESSON 1 - Guide the Turtle to the Finish Line!
=================================================
Goal: learn turtle.forward(), turtle.left(), turtle.right()

Look at path_background.png (it should be in the same folder as this file).
The path has a green flag (START, bottom-left) and a checkered flag
(FINISH, top-right). Your job is to fill in the blanks below so the turtle
walks along the sandy path, turn by turn, until it reaches the finish!

TIP: The turtle always starts facing EAST (to the right), at heading 0.
     right(90) turns it to face south (down).
     left(90)  turns it to face north (up).
"""

import turtle

# ---------- SCREEN SETUP (don't change this part) ----------
screen = turtle.Screen()
screen.setup(width=800, height=600)
screen.bgpic("path_background.png")
screen.title("Lesson 1: Guide the Turtle!")

t = turtle.Turtle()
t.shape("turtle")
t.color("purple")
t.penup()
t.goto(-350, -250)      # this is the START flag position
t.setheading(90)        # face north (up) to start walking
t.pendown()
t.speed(6)

# ---------- YOUR CODE HERE ----------
# The path goes: UP, then RIGHT, then UP, then RIGHT, then UP, then RIGHT.
# Fill in the ??? with the right distance or turn!
#
# Segment 1: walk UP along the path
t.forward(170)          # <-- already done for you as an example!

# Segment 2: turn to face right, then walk along the path
t.right(90)
t.forward(???)           # TODO: how far until the next turn?

# Segment 3: turn to face up, then walk along the path
t.left(90)
t.forward(???)           # TODO

# Segment 4: turn to face right, then walk along the path
t.right(90)
t.forward(???)           # TODO

# Segment 5: turn to face up, then walk along the path
t.left(90)
t.forward(???)           # TODO

# Segment 6: turn to face right, then walk to the FINISH flag
t.right(90)
t.forward(???)           # TODO

# ---------- CHECK IF WE MADE IT ----------
finish_x, finish_y = 350, 250
distance_to_finish = t.distance(finish_x, finish_y)

if distance_to_finish < 20:
    t.write("You reached the finish!  ", align="left", font=("Arial", 16, "bold"))
else:
    t.write(f"Not quite! {int(distance_to_finish)} px away.", align="left", font=("Arial", 14, "normal"))

screen.mainloop()
