Ejemplo n.º 1
0
def main():
    s = Screen()
    s.bgcolor('black')
    p = Turtle()
    p.speed(0)
    p.hideturtle()
    p.pencolor('red')
    p.pensize(3)
    s.tracer(36, 0)
    at = clock()
    mn_eck(p, 36, 19)
    et = clock()
    z1 = et - at
    sleep(1)
    at = clock()
    while any([t.undobufferentries() for t in s.turtles()]):
        for t in s.turtles():
            t.undo()
    et = clock()
    return 'runtime: %.3f sec' % (z1 + et - at)
def turtle_race():
    colors = ["red", "orange", "yellow", "green", "blue", "purple"]
    all_turtles = []
    x = -440
    y = 300
    is_race_on = False
    winning_color = []

    screen = Screen()
    screen.setup(width=1000, height=700)

    user_bet = screen.textinput(title="Make your bet", prompt="Which turtle will win the race? Enter a colour: ")

    for color in colors:
        new_turtle = Turtle(shape="turtle")
        new_turtle.color(color)
        new_turtle.penup()
        new_turtle.setpos(x=x, y=y)
        all_turtles.append(new_turtle)
        y -= 120

    if user_bet:
        is_race_on = True

    while is_race_on:
        for turtle in all_turtles:
            rand_distance = random.randint(0, 10)
            turtle.forward(rand_distance)
            if turtle.xcor() > 400:
                winning_color.append(turtle.color()[0])

        if winning_color:
            winning_color = ", ".join(winning_color)
            if user_bet.lower() in winning_color:
                is_play_again = screen.textinput(title="You've won!",
                                                 prompt=f"The {winning_color} turtle is the winner!\n"
                                                        "Do you want to play again?(y/n) ")
            else:
                is_play_again = screen.textinput(title="You've lost...",
                                                 prompt=f"The {winning_color} turtle is the winner.\n"
                                                        "Do you want to play again?(y/n) ")
            if is_play_again == "y":
                for old_turtle in screen.turtles():
                    old_turtle.hideturtle()
                turtle_race()
            else:
                is_race_on = False

    screen.bye()
def main():
    s = Screen()
    s.bgcolor("black")
    p=Turtle()
    p.speed(0)
    p.hideturtle()
    p.pencolor("red")
    p.pensize(3)

    s.tracer(36,0)

    at = clock()
    mn_eck(p, 36, 19)
    et = clock()
    z1 = et-at

    sleep(1)

    at = clock()
    while any([t.undobufferentries() for t in s.turtles()]):
        for t in s.turtles():
            t.undo()
    et = clock()
    return "Laufzeit: {0:.3f} sec".format(z1+et-at)
Ejemplo n.º 4
0
def main():
    s = Screen()
    s.bgcolor("black")
    p=Turtle()
    p.speed(0)
    p.hideturtle()
    p.pencolor("red")
    p.pensize(3)

    s.tracer(36,0)

    at = clock()
    mn_eck(p, 36, 19)
    et = clock()
    z1 = et-at

    sleep(1)

    at = clock()
    while any(t.undobufferentries() for t in s.turtles()):
        for t in s.turtles():
            t.undo()
    et = clock()
    return "runtime: %.3f sec" % (z1+et-at)
Ejemplo n.º 5
0
import time
from turtle import Screen
from player import Player
from car_manager import CarManager
from scoreboard import Scoreboard
from board import create_b

MOVE_INCREMENT = 10
screen = Screen()
screen.colormode(255)
screen.setup(width=1200, height=600)
screen.tracer(0)
screen.title("TurtleZ")
screen.listen()
print(screen.turtles())
create_b()
turtle = Player()
scoreboard = Scoreboard()
scoreboard.score()
# scoreboard.instruct()
screen.onkeyrelease(turtle.move_u, "Up")
screen.onkeyrelease(turtle.move_d, "Down")
game_is_on = True
car = CarManager()
cars = car.create_cars()


while game_is_on:
    time.sleep(0.1)
    turtle_y = turtle.ycor()
    game_over = car.move(MOVE_INCREMENT, turtle_y)
Ejemplo n.º 6
0

def out_of_bounds(turtle):
    return not (-width // 2 < turtle.xcor() < width // 2
                and -height // 2 < turtle.ycor() < height // 2)


while r < 50:
    for i in range(0, m):

        maker1.forward(m)
        maker2.forward(m)
        maker3.backward(m)
        maker4.backward(m)

        if any(out_of_bounds(turtle) for turtle in screen.turtles()):
            for turtle in screen.turtles():
                turtle.undo()

        if d:
            maker1.right(r * n)
            maker2.right(-r * n)
            maker3.left(-r * n)
            maker4.left(r * n)
        else:
            maker1.left(r * n)
            maker2.left(-r * n)
            maker3.right(-r * n)
            maker4.right(r * n)

        maker1.forward(m)
Ejemplo n.º 7
0
    i += 1

play = True
while play:
    rule = True
    winner = None
    guess = screen.textinput("Place your bet!", "Who will win(alex,benji,chris,dan,ellie)?")
    while rule:
        for turtle in t.keys():
            turtle.forward(random.randint(1, 10))
            pos = turtle.pos()
            if pos[0] >= 280:
                rule = False
                winner = turtle
                break

    if t[winner] == guess:
        print("YOU WON")
    else:
        print(f"YOU LOST, The Winner is {t[winner]}")

    i = -2
    for turtle1 in screen.turtles():
        turtle1.setpos(-300, 50 * i)
        i += 1
    choice = screen.textinput('Want to play again?', 'Yes/No')
    if choice.lower() == 'no':
        play = False

screen.exitonclick()
Ejemplo n.º 8
0
from turtle import Turtle, Screen

clr = (64, 64, 64)
text_list = ['R', 'G', 'B', '', 90, -60, -210, 250]
cl_list = ['red', 'green', 'blue', 150, 0, -150]

screen = Screen()
screen.delay(0)
screen.title('Миксер цветов')
screen.colormode(255)

cl_r = Turtle(shape='circle')
cl_g = cl_r.clone()
cl_b = cl_r.clone()

for t, turtle in enumerate(screen.turtles()):
    turtle.speed(0)
    turtle.shapesize(3, 3, 5)
    turtle.color(cl_list[t])
    turtle.width(10)
    turtle.pu()
    turtle.setpos(-255, cl_list[3 + t])
    turtle.pd()
    turtle.setx(255)
    turtle.pu()
    turtle.setx(0)
    turtle.pencolor(clr)

for obj in range(4):
    text = Turtle()
    text.color(clr)
Ejemplo n.º 9
0
		employer4.speed(0)
		employer4.penup()
		employer4.setpos(-50, -60)
		employer4.write(n, font=("Arial", 100, "bold"))
		employer4.penup()
		time.sleep(1)
		employer4.clear()
		recurse(n-1)
		
employer4.hideturtle()
recurse(3)

#Setting the distance

screen = Screen()
turtles = screen.turtles()

while True:
	for i in turtles:
		alex.forward(randint(5,10))
		tess.forward(randint(5,10))
		tim.forward(randint(5,10))
		duck.forward(randint(5,10))
		dog.forward(randint(5,10))
	
	if alex.xcor() > finish_line:
		print("The winner is Alex! ") 
		winner = "alex"
		break  
	
	if tess.xcor() > finish_line: