The first function calls to make the tic tac toe board, and the code before creates the screen and turtle.
#import needed modules
import turtle
#make a screen
ttts = turtle.Screen()
#set up the pen
d = turtle.Turtle()
d.color("indigo")
d.pensize(4)
d.speed(5)
d.penup()
#make number list
number_list = ["1","2","3","4","5","6","7","8","9"]
current_number = "1","2","3","4","5","6","7","8","9"
#set beginning position
d.goto(-150,100)
#make square (function)
def square(*squares):
squares = 0
columns = 0
rows = 0
x = -75
y = 100
while (squares < 4):
d.pendown()
d.forward(225)
d.right(90)
squares = squares + 1
d.right(90)
while (columns < 2):
d.goto(x,y)
d.pendown()
d.forward(225)
d.penup()
x = x + 75
columns = columns + 1
d.right(90)
while (rows < 3):
d.goto(x,y)
d.pendown()
d.forward(225)
d.penup()
y = y + -75
rows = rows + 1
square()
This code above is fine, I have made sure to debug all the functions below as well. I'm just having trouble calling the functions at the end.
#make the numbers
def numbers():
d.penup()
d.color("yellow")
d.goto(-120, 50)
d.write(1, align='left', font = ('arial', 16))
d.goto(-45, 50)
d.write(2, align='left', font = ('arial', 16))
d.goto(30, 50)
d.write(3, align='left', font = ('arial', 16))
d.goto(-120, -25)
d.write(4, align='left', font = ('arial', 16))
d.goto(-45, -25)
d.write(5, align='left', font = ('arial', 16))
d.goto(30, -25)
d.write(6, align='left', font = ('arial', 16))
d.goto(-120, -100)
d.write(7, align='left', font = ('arial', 16))
d.goto(-45, -100)
d.write(8, align='left', font = ('arial', 16))
d.goto(30, -100)
d.write(9, align='left', font = ('arial', 16))
d.hideturtle()
numbers()
#function for defining symbols(x and o)
def draw_symbol(number_list):
number_list
symbolc()
symbolxs()
#functions for x and o
c = turtle.Turtle()
xs = turtle.Turtle()
def symbolc(circle):
circle = 0
def check_number_1():
if (current_number == "1"):
c.goto(-120,70)
ttts.onkeypress(check_number_1, "1")
def check_number_2():
if (current_number == "2"):
c.goto(-45,70)
ttts.onkeypress(check_number_2, "2")
def check_number_3():
if (current_number == "3"):
c.goto(30,70)
ttts.onkeypress(check_number_3, "3")
def check_number_4():
if (current_number == "4"):
c.goto(-120,-5)
ttts.onkeypress(check_number_4, "4")
def check_number_5():
if (current_number == "5"):
c.goto(-45,-5)
ttts.onkeypress(check_number_5, "5")
def check_number_6():
if (current_number == "6"):
c.goto(30,-5)
ttts.onkeypress(check_number_6, "6")
def check_number_7():
if (current_number == "7"):
c.goto(-120,-80)
ttts.onkeypress(check_number_7, "7")
def check_number_8():
if (current_number == "8"):
c.goto(-45,-80)
ttts.onkeypress(check_number_8, "8")
def check_number_9():
if (current_number == "9"):
c.goto(30,-80)
ttts.onkeypress(check_number_9, "9")
#--- main ---
if (circle < 1):
c.penup()
c.color("red")
c.circle(20)
circle = circle + 1
#crosses
def symbolxs(cross):
cross = 0
while (cross < 4):
def check_number_1():
if (current_number == "1"):
xs.goto(-120,70)
ttts.onkeypress(check_number_1, "1")
def check_number_2():
if (current_number == "2"):
xs.goto(-45,70)
ttts.onkeypress(check_number_2, "2")
def check_number_3():
if (current_number == "3"):
xs.goto(30,70)
ttts.onkeypress(check_number_3, "3")
def check_number_4():
if (current_number == "4"):
xs.goto(-120,-5)
ttts.onkeypress(check_number_4, "4")
def check_number_5():
if (current_number == "5"):
xs.goto(-45,-5)
ttts.onkeypress(check_number_5, "5")
def check_number_6():
if (current_number == "6"):
xs.goto(30,-5)
ttts.onkeypress(check_number_6, "6")
def check_number_7():
if (current_number == "7"):
xs.goto(-120,-80)
ttts.onkeypress(check_number_7, "7")
def check_number_8():
if (current_number == "8"):
xs.goto(-45,-80)
ttts.onkeypress(check_number_8, "8")
def check_number_9():
if (current_number == "9"):
xs.goto(30,-80)
ttts.onkeypress(check_number_9, "9")
xs.penup()
xs.color("lime")
xs.right(45)
xs.pendown()
xs.forward(10)
cross = cross + 1
#turns - Circles goes first always. I hope you know how to play tic tac toe.
c.stamp()
xs.stamp()
c.stamp()
xs.stamp()
c.stamp()
xs.stamp()
c.stamp()
xs.stamp()
c.stamp()
ttts.listen()
turtle.mainloop()
If you see an immediate error, please comment on enter code hereit. However, keep in mind that this is code made by a very young (early teen) student. Thanks a bunch! ps, sorry if the code looks bad on this. I do not know how to use this app, as it is my first question here. :)