Untitled

mail@pastecode.io avatar
unknown
plain_text
25 days ago
2.5 kB
1
Indexable
Never
from turtle import *
from time import sleep
from random import randint
 
w = 200
h = 150
v = 10
points = 0

t = Turtle()
t.color('red')
t.penup()
t.shape('turtle')
t.speed(v)
t.points = 0

t1 = Turtle()
t1.color('blue')
t1.penup()
t1.shape('turtle')
t1.speed(v)
t1.points = 0

def rand_move():
    t.goto(randint(-w, w), randint(-h, h))

def rand_move1():
    t1.goto(randint(-w, w), randint(-h, h))
 

def catch(x, y):
    t.write('A!', font=('Arial', 14, 'normal'))
    t.points = t.points + 1
    rand_move()


def catch1(x, y):
    t1.write('A!', font=('Arial', 14, 'normal'))
    t1.points = t1.points + 1
    rand_move1()

t.onclick(catch)
t1.onclick(catch1)
 
while t1.points < 3 or t.points < 3:
    sleep(1)
    rand_move()
    rand_move1()
 
t.write('WOW!', font=('Arial', 16, 'bold'))
t1.write('WOW!', font=('Arial', 16, 'bold'))
t.hideturtle()












2






















from turtle import *
from random import randint
from time import sleep
 
w = 200
h = 200
t1 = Turtle()
t1.color('blue')
t1.width(5)
t1.shape('turtle')
 
t2 = Turtle()
t2.color('green')
t2.width(5)
t2.left(120)
t2.shape('turtle')
 
t3 = Turtle()
t3.color('red')
t3.width(5)
t3.left(-120)
t3.shape('turtle')
 
def catch1(x, y):
    t1.penup()
    t1.goto(randint(-100,100),randint(-100,100))
    t1.pendown()
    t1.left(randint(0, 180))
 
def catch2(x, y):
    t2.penup()
    t2.goto(randint(-100,100),randint(-100,100))
    t2.pendown()
    t2.left(randint(0, 180))
 
def catch3(x, y):
    t3.penup()
    t3.goto(randint(-100,100),randint(-100,100))
    t3.pendown()
    t3.left(randint(0, 180))
 
def gameFinished(t1, t2, t3):
    t1_outside = abs(t1.xcor()) > w or abs(t1.ycor()) > h
    t2_outside = abs(t2.xcor()) > w or abs(t2.ycor()) > h
    t3_outside = abs(t3.xcor()) > w or abs(t3.ycor()) > h
    isOutside = t1_outside or t2_outside or t3_outside
    return isOutside
 
t1.onclick(catch1)
t2.onclick(catch2)
t3.onclick(catch3)
 
while gameFinished(t1, t2, t3) != True:
    t1.forward(7)
    t2.forward(7)
    t3.forward(7)
    sleep(0.1)
 
t1.clear()
t2.clear()
t3.clear()
 
t1.penup()
t1.goto(-30, 0)
t1.write('Good bye!', font=('Arial', 16, 'bold'))
 
t2.penup()
t2.goto(-30, 0)
t2.write('Good bye!', font=('Arial', 16, 'bold'))
 
t3.penup()
t3.goto(-30, 0)
t3.write('Good bye!', font=('Arial', 16, 'bold'))
 
t1.hideturtle()
t2.hideturtle()
t3.hideturtle()
 
exitonclick()
Leave a Comment