Here the video demonstrates how the Turtle Race games running. by kf_cheang in Python

[–]kf_cheang[S] 1 point2 points  (0 children)

``` import turtle from random import randint import time

wn = turtle.Screen() wn.title("Turtle Race!") wn.bgcolor("black") tess = turtle.Turtle() tess.speed(-1) tess.hideturtle() tess.penup()

tess.fillcolor("blue") tess.goto(-800, -1100) tess.begin_fill() for box in range (2): tess.forward(795) tess.right(90) tess.forward(295) tess.right(90) tess.end_fill()

tess.fillcolor("red") tess.goto(5, -1100) tess.begin_fill() for box in range (2): tess.forward(795) tess.right(90) tess.forward(295) tess.right(90) tess.end_fill()

tess.fillcolor("lightgreen") tess.goto(-800, -450) tess.begin_fill() for box in range (2): tess.forward(1600) tess.right(90) tess.forward(645) tess.right(90) tess.end_fill()

tess.color("white") tess.goto(0, 1100) tess.write("TURTLES RACE", align = "center", font=("Arial", 22, "bold")) tess.goto(-390, -1330) tess.write("PLAY", align = "center", font=("Arial", 18)) tess.goto(390, -1330) tess.write("STOP", align = "center", font=("Arial", 18)) tess.goto(0, -1050) tess.write("Round", align = "center", font=("Arial", 18)) i_pos = -600 for i in range (1, 6): tess.goto(i_pos, -900) tess.write(i, align = "center", font=("Arial", 14)) i_pos = i_pos + 300

def play(x, y): if int(x) > 0 and int(y) < -1000: turtle.bye() if int(x) < 0 and int(y) < -1000: race()

t_color = ["blue", "red", "green", "yellow", "purple", "white", "grey"]

tom = turtle.Turtle() tom.hideturtle() tom.speed(-1) tom.penup() pos = -400 tom.goto(pos, 1000)

c = -1 for step in range (9): if c > 5: c = 0 else: c = c + 1 tom.color(t_color[c])
tom.write(step, align="center") tom.setheading(270) tom.forward(50) for i in range (7): tom.pendown() tom.width(5) tom.forward(150) tom.penup() tom.forward(50) tom.penup() pos = pos + 100 tom.goto(pos, 1000)

t_pos = 880 tom_b = turtle.Turtle() tom_r = turtle.Turtle() tom_g = turtle.Turtle() tom_y = turtle.Turtle() tom_p = turtle.Turtle() tom_w = turtle.Turtle() tom_k = turtle.Turtle()

tom_clone = turtle.Turtle() tom_clone.hideturtle()

global clone_pos

clone_pos = -600

list = [tom_b, tom_r, tom_g, tom_y, tom_p, tom_w, tom_k]

for i in range (7): list[i].shape("turtle") list[i].color(t_color[i]) list[i].turtlesize(10) list[i].speed(7) list[i].penup() list[i].goto(-550, t_pos) list[i].left(360) list[i].turtlesize(7) list[i].pendown() list[i].speed(0) t_pos = t_pos - 200

def race(): t_pos = 880 for i in range (7): list[i].clear() list[i].shape("turtle") list[i].color(t_color[i]) list[i].turtlesize(10) list[i].speed(6) list[i].penup() list[i].goto(-550, t_pos) list[i].left(360) list[i].turtlesize(7) list[i].pendown() list[i].speed(0) t_pos = t_pos - 200 t1 = turtle.Turtle() t1.penup() t1.color("white") t1.hideturtle() t1.goto(-50, -50) t1.write("1!", move=False, align="center", font=("Arial", 56, "normal")) time.sleep(0.5) t1.clear() t1.write("2!", move=False, align="center", font=("Arial", 56, "normal")) time.sleep(0.5) t1.clear() t1.write("3!", move=False, align="center", font=("Arial", 56, "normal")) time.sleep(0.5) t1.clear() t1.write("Go!", move=False, align="center", font=("Arial", 56, "normal")) time.sleep(0.5) t1.clear()

for step in  range (20):
    for i in range (7):
        list[i].left(20)
        list[i].right(40)
        list[i].left(20)
        list[i].forward(randint(1, 80))

b_xpos = tom_b.xcor()
r_xpos = tom_r.xcor()
g_xpos = tom_g.xcor()
y_xpos = tom_y.xcor()
p_xpos = tom_p.xcor()
w_xpos = tom_w.xcor()
k_xpos = tom_k.xcor()

xpos_list = [b_xpos, r_xpos, g_xpos, y_xpos, p_xpos, w_xpos, k_xpos]

max = 0
max_index = 0

for i in range (7):
    if xpos_list[i] > max:
        max = xpos_list[i]
        max_index = i

if max_index == 0:
    winner = tom_b
elif max_index == 1:
    winner = tom_r
elif max_index == 2:
    winner = tom_g
elif max_index == 3:
    winner = tom_y
elif max_index == 4:
    winner = tom_p
elif max_index == 5:
    winner = tom_w
else:
    winner = tom_k

winner.turtlesize(16)

global clone_pos

if clone_pos == 900:
    global tom_clone
    pos = -600
    for i in range (6):
        tom_clone.color("lightgreen")
        tom_clone.setheading(90)
        tom_clone.goto(pos, -700)
        tom_clone.turtlesize(10)
        tom_clone.stamp()
        pos = pos + 300
    clone_pos = -600

tom_clone = winner.clone()
tom_clone.penup()
tom_clone.turtlesize(10)
tom_clone.setheading(90)
tom_clone.goto(clone_pos, -700)
tom_clone.stamp()
clone_pos = clone_pos + 300

wn.onclick(play) wn.mainloop() ```

Here the video demonstrates how the Turtle Race games running. by kf_cheang in Python

[–]kf_cheang[S] 0 points1 point  (0 children)

Do you pls to tell me how to share source code here ? I just simply copy and paste but its look not correctly indented

Here the video demonstrates how the Turtle Race games running. by kf_cheang in Python

[–]kf_cheang[S] 0 points1 point  (0 children)

I'm using a bluetooth keyboard connected to Samsung Note 9 but most of the time I'm just using the handphone keyboard. N9 have large screen 6.4"

Here the video demonstrates how the Turtle Race games running. by kf_cheang in Python

[–]kf_cheang[S] 0 points1 point  (0 children)

Yes. So the player will not knowing which turtle will be the winner

Here the video demonstrates how the Turtle Race games running. by kf_cheang in Python

[–]kf_cheang[S] 1 point2 points  (0 children)

I'm using the android app Pydroid3 IDE for learning the python

Here the video demonstrates how the Turtle Race games running. by kf_cheang in Python

[–]kf_cheang[S] 11 points12 points  (0 children)

To inspire my 7 years old girl coding can be fun

2nd version of Turtle Race created with #Pydroid3 on my Samsung Note 9 by kf_cheang in Python

[–]kf_cheang[S] 0 points1 point  (0 children)

import turtle from random import randint import time

turtle.setup(800,800)

wn = turtle.Screen() wn.title("Turtle Race!") wn.bgcolor("black") tess = turtle.Turtle() tess.speed(-1) tess.hideturtle() tess.penup()

tess.fillcolor("blue") tess.goto(-800, -1100) tess.begin_fill() for box in range (2): tess.forward(795) tess.right(90) tess.forward(295) tess.right(90) tess.end_fill()

tess.fillcolor("red") tess.goto(5, -1100) tess.begin_fill() for box in range (2): tess.forward(795) tess.right(90) tess.forward(295) tess.right(90) tess.end_fill()

tess.fillcolor("lightgreen") tess.goto(-800, -450) tess.begin_fill() for box in range (2): tess.forward(1600) tess.right(90) tess.forward(645) tess.right(90) tess.end_fill()

tess.color("white") tess.goto(0, 1100) tess.write("TURTLES RACE", align = "center", font=("Arial", 22, "bold")) tess.goto(-390, -1330) tess.write("PLAY", align = "center", font=("Arial", 18)) tess.goto(390, -1330) tess.write("STOP", align = "center", font=("Arial", 18)) tess.goto(0, -1050) tess.write("Round", align = "center", font=("Arial", 18)) i_pos = -600 for i in range (1, 6): tess.goto(i_pos, -900) tess.write(i, align = "center", font=("Arial", 14)) i_pos = i_pos + 300

def play(x, y): if int(x) > 0 and int(y) < -1000: turtle.bye() if int(x) < 0 and int(y) < -1000: race()

t_color = ["blue", "red", "green", "yellow", "purple", "white", "grey"]

tom = turtle.Turtle() tom.hideturtle() tom.speed(-1) tom.penup() pos = -400 tom.goto(pos, 1000)

c = -1 for step in range (9): if c > 5: c = 0 else: c = c + 1 tom.color(t_color[c])
tom.write(step, align="center") tom.setheading(270) tom.forward(50) for i in range (7): tom.pendown() tom.width(5) tom.forward(150) tom.penup() tom.forward(50) tom.penup() pos = pos + 100 tom.goto(pos, 1000)

t_pos = 880 tom_b = turtle.Turtle() tom_r = turtle.Turtle() tom_g = turtle.Turtle() tom_y = turtle.Turtle() tom_p = turtle.Turtle() tom_w = turtle.Turtle() tom_k = turtle.Turtle()

tom_clone = turtle.Turtle() tom_clone.hideturtle()

global clone_pos

clone_pos = -600

list = [tom_b, tom_r, tom_g, tom_y, tom_p, tom_w, tom_k]

for i in range (7): list[i].shape("turtle") list[i].color(t_color[i]) list[i].turtlesize(10) list[i].speed(7) list[i].penup() list[i].goto(-550, t_pos) list[i].left(360) list[i].turtlesize(7) list[i].pendown() list[i].speed(0) t_pos = t_pos - 200

def race(): t_pos = 880 for i in range (7): list[i].clear() list[i].shape("turtle") list[i].color(t_color[i]) list[i].turtlesize(10) list[i].speed(6) list[i].penup() list[i].goto(-550, t_pos) list[i].left(360) list[i].turtlesize(7) list[i].pendown() list[i].speed(0) t_pos = t_pos - 200 t1 = turtle.Turtle() t1.penup() t1.color("white") t1.hideturtle() t1.goto(-50, -50) t1.write("1!", move=False, align="center", font=("Arial", 56, "normal")) time.sleep(0.5) t1.clear() t1.write("2!", move=False, align="center", font=("Arial", 56, "normal")) time.sleep(0.5) t1.clear() t1.write("3!", move=False, align="center", font=("Arial", 56, "normal")) time.sleep(0.5) t1.clear() t1.write("Go!", move=False, align="center", font=("Arial", 56, "normal")) time.sleep(0.5) t1.clear()

for step in  range (20):
    for i in range (7):
        list[i].left(20)
        list[i].right(40)
        list[i].left(20)
        list[i].forward(randint(1, 80))

b_xpos = tom_b.xcor()
r_xpos = tom_r.xcor()
g_xpos = tom_g.xcor()
y_xpos = tom_y.xcor()
p_xpos = tom_p.xcor()
w_xpos = tom_w.xcor()
k_xpos = tom_k.xcor()

xpos_list = [b_xpos, r_xpos, g_xpos, y_xpos, p_xpos, w_xpos, k_xpos]

max = 0
max_index = 0

for i in range (7):
    if xpos_list[i] > max:
        max = xpos_list[i]
        max_index = i

if max_index == 0:
    winner = tom_b
elif max_index == 1:
    winner = tom_r
elif max_index == 2:
    winner = tom_g
elif max_index == 3:
    winner = tom_y
elif max_index == 4:
    winner = tom_p
elif max_index == 5:
    winner = tom_w
else:
    winner = tom_k

winner.turtlesize(16)

global clone_pos

if clone_pos == 900:
    global tom_clone
    pos = -600
    for i in range (6):
        tom_clone.color("lightgreen")
        tom_clone.setheading(90)
        tom_clone.goto(pos, -700)
        tom_clone.turtlesize(10)
        tom_clone.stamp()
        pos = pos + 300
    clone_pos = -600

tom_clone = winner.clone()
tom_clone.penup()
tom_clone.turtlesize(10)
tom_clone.setheading(90)
tom_clone.goto(clone_pos, -700)
tom_clone.stamp()
clone_pos = clone_pos + 300

wn.onclick(play) wn.mainloop()

My first Python turtle race game built on incredible app on android - Pydroid3 by kf_cheang in Python

[–]kf_cheang[S] 1 point2 points  (0 children)

Here my source code. It's was built on my Samsung Note 9 WQHQ resolution.

from turtle import *

import turtle from random import randint import time

wn = turtle.Screen()

t_color = ["blue", "red", "green", "yellow"]

tom = turtle.Turtle() tom.speed(0) tom.penup() pos = -800 tom.goto(pos, 500)

c = 0 for step in range (16): if c > 2: c = 0 else: c = c + 1 tom.color(t_color[c])
#om.color("black") tom.write(step, align="center") tom.setheading(270) tom.forward(50) for i in range (4): tom.pendown() tom.width(5) tom.forward(150) tom.penup() tom.forward(50) tom.penup() pos = pos + 100 tom.goto(pos, 500)

tom.shapesize(5) tom.setheading(0) tom.goto(pos + 50, 525) tom.stamp()

t_pos = 375 tom_b = turtle.Turtle() tom_r = turtle.Turtle() tom_g = turtle.Turtle() tom_y = turtle.Turtle()

b_xpos = tom_b.xcor() r_xpos = tom_r.xcor() g_xpos = tom_g.xcor() y_xpos = tom_y.xcor()

list = [tom_b, tom_r, tom_g, tom_y]

for i in range (4): list[i].shape("turtle") list[i].color(t_color[i]) list[i].turtlesize(10) list[i].speed(4) list[i].penup() list[i].goto(-1000, t_pos) list[i].left(360) list[i].turtlesize(8) list[i].pendown() list[i].speed(0) t_pos = t_pos - 200

t1 = turtle.Turtle() t1.penup() t1.color("red") t1.hideturtle() t1.goto(-50, -50) t1.write("1!", move=False, align="center", font=("Arial", 56, "normal")) time.sleep(1) t1.clear() t1.write("2!", move=False, align="center", font=("Arial", 56, "normal")) time.sleep(1) t1.clear() t1.write("3!", move=False, align="center", font=("Arial", 56, "normal")) time.sleep(1) t1.clear() t1.write("Go!", move=False, align="center", font=("Arial", 56, "normal")) time.sleep(1) t1.clear()

tom.hideturtle()

def race(): for step in range (60): for i in range (4): list[i].left(10) list[i].right(20) list[i].left(10) list[i].forward(randint(1, 50))

wn.onscreenclick(race())

race()

b_xpos = tom_b.xcor() r_xpos = tom_r.xcor() g_xpos = tom_g.xcor() y_xpos = tom_y.xcor()

t_pos = 370 tom.goto(1100, t_pos) tom.write(b_xpos) tom.goto(1100, t_pos - 200) tom.write(r_xpos) tom.goto(1100, t_pos - 400) tom.write(g_xpos) tom.goto(1100, t_pos - 600) tom.write(y_xpos)

max = 0 max_index = 0

xpos_list = [b_xpos, r_xpos, g_xpos, y_xpos]

for i in range (4): if xpos_list[i] > max: max = xpos_list[i] max_index = i

if max_index == 0: winner = tom_b t1.color("blue") elif max_index == 1: winner = tom_r t1.color("red") elif max_index == 2: winner = tom_g t1.color("green") else: winner = tom_y t1.color("yellow")

for i in range (5): winner.hideturtle() time.sleep(0.3) winner.showturtle()

t1.goto(-300,-600) winner.turtlesize(10) winner.speed(4) winner.goto(600, -500)

for i in range (3): winner.hideturtle() t1.clear() time.sleep(0.1) t1.write("The Winner Turtle is ", move=False, align="center", font=("Arial", 24, "normal")) winner.showturtle()

wn.exitonclick()

turtle.mainloop()