ich probiere mich gerade an einem 4 Gewinnt Spiel mit der Turtle Funktion. Leider bin ich aber noch eine ziemliche Anfängerin und scheitere momentan an dem abwechselnden Setzen und dem Zeichen der Kreise. Google hat mich auch nicht weitergebracht … habt ihr vielleicht Ideen und Ansätze mit denen ich weiterarbeiten könnte?
Code: Alles auswählen
from turtle import *
t1 = Turtle()
setup(700, 600)
screen = t1.getscreen()
screen.screensize(700, 600)
t1.speed(10)
# Vertikale Linien
# 1.Linie
t1.penup()
t1.goto(-350, -300)
t1.pendown()
t1.right(270)
t1.forward(600)
# 2.Linie
t1.penup()
t1.goto(-250, 300)
t1.pendown()
t1.right(180)
t1.forward(600)
# 3.Linie
t1.penup()
t1.goto(-150, -300)
t1.pendown()
t1.right(180)
t1.forward(600)
# 4.Linie
t1.penup()
t1.goto(-50, 300)
t1.pendown()
t1.right(180)
t1.forward(600)
# 5.Linie
t1.penup()
t1.goto(50, -300)
t1.pendown()
t1.right(180)
t1.forward(600)
# 6.Linie
t1.penup()
t1.goto(150, 300)
t1.pendown()
t1.right(180)
t1.forward(600)
# 7.Linie
t1.penup()
t1.goto(250, -300)
t1.pendown()
t1.right(180)
t1.forward(600)
# 8.Linie
t1.penup()
t1.goto(350, 300)
t1.pendown()
t1.right(180)
t1.forward(600)
# Horizontale Linien
# 1.Linie
t1.right(90)
t1.forward(700)
# 2.Linie
t1.penup()
t1.goto(-350, -200)
t1.pendown()
t1.right(180)
t1.forward(700)
# 3.Linie
t1.penup()
t1.goto(350, -100)
t1.pendown()
t1.right(180)
t1.forward(700)
# 4.Linie
t1.penup()
t1.goto(-350, 0)
t1.pendown()
t1.right(180)
t1.forward(700)
# 5. Linie
t1.penup()
t1.goto(350, 100)
t1.pendown()
t1.right(180)
t1.forward(700)
# 6.Linie
t1.penup()
t1.goto(-350, 200)
t1.pendown()
t1.right(180)
t1.forward(700)
# 7.Linie
t1.penup()
t1.goto(350, 300)
t1.pendown()
t1.right(180)
t1.forward(700)
#Klick
def klick (x, y):
print(x,y)
t1.penup()
t1.goto(x,y)
Reihe(x,y)
#Kreise
def Kreis1():
t1.fillcolor("yellow")
t1.speed(100)
t1.begin_fill()
t1.pendown()
t1.seth(270)
t1.circle(45)
t1.end_fill()
def Kreis2():
t1.fillcolor("red")
t1.speed(100)
t1.begin_fill()
t1.pendown()
t1.seth(270)
t1.circle(45)
t1.end_fill()
#Reihen
def Reihe (x,y):
if x <= -250 and y >= -350 and y <= 300:
Reihe =1
print("1")
elif x >= -250 and x<= -150 and y <= 300 and y >= -350:
Reihe = 2
print("2")
elif x >= -150 and x <= -50 and y >= -350 and y <= 300:
Reihe = 3
print("3")
elif x>= -50 and x <= 50 and y >= -350 and y <= 300:
Reihe = 4
print("4")
elif x >= 50 and x <= 150 and y >= -350 and y <= 300:
Reihe = 5
print("5")
elif x >= 150 and x <=250 and y >= -350 and y <= 300:
Reihe = 6
print("6")
else:
Reihe = 7
print("7")
onscreenclick(klick)
mainloop()