Turtle Racer, как добавить первое второе и третье меню в python - PullRequest
0 голосов
/ 23 марта 2019

Итак, у меня есть проект на 11 год, в котором мне нужно добавить раздел к этому коду, чтобы первые 3 черепахи, пересекающие финишную черту, были перечислены в меню, подобном этому enter image description here ОднакоМне нужно это сказать первое место, второе место, третье место и переместить туда соответствующих черепах.Сложность в том, что новый трек, который я сделал (проект сказал мне) enter image description here, однако, черепахи не пересекут финишную черту после первых пересечений черепахой, и я не уверен, как добавить новое менюпоскольку код, который нам изначально дали, не имеет смысла.

Текущий код, который я имею, выглядит следующим образом;

 #==========================================================

#                       Imports

#==========================================================
from PIL import Image, ImageTk
from turtle import *
import turtle
from random import randint
from turtle import Screen, Turtle
from math import sin, cos, atan2, pi
from random import randrange
racers = [] #defines what racers is 

#==========================================================

#                       GAME

#==========================================================

# Creating the window
screen = turtle.Screen()
screen.setup(1225, 1000)

pil_img = Image.open("eightLane.gif")  # Use PIL to open .jpg image.
tk_img = ImageTk.PhotoImage(pil_img)  # Convert it into something tkinter can use.
canvas = turtle.getcanvas()  # Get the tkinter Canvas of this TurtleScreen.
# Create a Canvas image object holding the tkinter image.
img_obj_id = canvas.create_image(0, 0, image=tk_img, anchor='center')

title("RACING TURTLES")

#==========================

#   Creating the turtles

#==========================

#in future adjust position 
LINEUP = [  # (color, (starting postion))
    ('red', (0, 90)), #creates each turtle and where it goes
    ('yellow', (-55, 120)),
    ('blue', (-120, 150)),
    ('green', (-195, 165)),
    ('dark goldenrod', (-270, 180)),
    ('blue violet', (-365, 170)),
    ('magenta', (-465, 140)),
    ('light slate gray', (-550, 100)),
]

for index, (color, position) in enumerate(LINEUP):

    racer = Turtle('turtle', visible=False) #pen settings for placing the turtles initially
    racer.setheading(180 + index * 10)
    racer.speed('fastest')
    racer.color(color) 
    racer.penup()
    racer.setposition(position)
    racer.showturtle() #shows the turtle now that it is in position

    racers.append(racer)



DELTA = 0.4  # angle at which they move

def radii(index):  # calculate concentric ellipse radii
    return 265 + index * 44, 90 + index * 36

def race(): #how often it moves a turtle
    """
    every 1/1000th of a second, pick a random 
    racer and move it forward a bit
    """

    index = randrange(len(racers)) 
    racer = racers[index]

    # get angle from x, y; increase angle; compute new x, y
    theta = atan2(racer.ycor(), racer.xcor()) + DELTA

    a, b = radii(index)

    x = a * cos(theta) #fancy maths
    y = b * sin(theta)

    racer.setheading(racer.towards(x, y)) #tells the racer where to face
    racer.setposition(x, y)  # moves the racer to the position 

    # check if a racer has crossed the finish line
    if pi/2 < theta < pi/2 + DELTA/2: #if the racer has crossed the line run next line else skip
        pass  #someone one
    else:
        screen.ontimer(race, 100) #keeps the loop going

race()
screen.mainloop()

любая помощь или совет будет принята с благодарностью.

...