def draw_canvas(state):
'''Draw all the cities in the current state in a canvas. Indicate the start
city with a description and the current city by the turtle pointer head
'''
turtle.clear()
turtle.hideturtle()
turtle.up()
turtle.pencolor("blue")
current_city = state.current_city
for city in state.cities:
x = city.position[0]
y = city.position[1]
turtle.goto(x, y)
if city.is_start:
turtle.write('{}, Start'.format(city.name), align="center", font=("Arial", 12, "bold"))
elif city == current_city:
turtle.write('{}, Current'.format(city.name), align="center", font=("Arial", 12, "bold"))
else:
turtle.write('{}'.format(city.name), align="center", font=("Arial", 12, "bold"))
turtle.goto(current_city.position[0], current_city.position[1])
评论列表
文章目录