Der Programm-Code
from gturtle import *
from time import sleep
a=0
SiegeGelb = 0
SiegeRot = 0
def drawGrid():
setPenColor("black")
setLineWidth(1)
heading(-90)
setPos(110,90)
for seite in [220,160,220,160]:
forward(seite)
leftArc(10,90)
setPos(100,70)
setFillColor("navy blue")
fill()
cleanGrid()
def cleanGrid():
heading(0)
penUp()
setPenColor("white")
x = -90
repeat 7:
setPos(x, -60)
repeat 5:
dot(20)
forward(30)
x += 30
def drawAnzeige():
setPenColor("black")
penDown()
heading(90)
setPos(-100,-150)
for seite in [200,50,200,50]:
forward(seite)
right(90)
setPos(90,-160)
setFillColor("black")
fill()
setPenColor("yellow")
setPos(-93,-183)
label("Gelb ist jetzt dran")
setPos(-100,-150)
setPenColor(makeColor(0.2,0.2,0.2))
heading(towards(0,0))
forward(15)
x,y=getX(),getY()
moveTo(-x,y)
moveTo(100,-150)
setPos(0,-140)
setFillColor(makeColor(0.2,0.2,0.2))
fill()
def drawSchriftAnzeige():
penDown()
setPos(75,-175)
setPenColor("black")
setLineWidth(50)
moveTo(-75,-175)
if a== 0:
setPenColor("yellow")
setPos(-93,-183)
label("Gelb ist jetzt dran")
else:
setPenColor("red")
setPos(-90,-183)
label("Rot ist jetzt dran")
def drawChipLager():
b= 1
repeat 2:
setLineWidth(3)
setPenColor("black")
heading(90*b)
setPos(150*b,150)
for seite in [140,80,130]:
forward(seite)
leftArc(10,90*b)
forward(67)
setPos(162*b,162)
if b == 1:
i= 21
setPos(141*b,141)
x,y = getX(), getY()
repeat 7:
x += i
repeat 4:
y += i
dotXY(x, y , "red")
y -= 4*i
else:
i= 21
setPos(141*b,141)
x,y = getX(), getY()
repeat 7:
x -= i
repeat 4:
y += i
dotXY(x, y , "yellow")
y -= 4*i
setLineWidth(2)
setPenColor("black")
setPos(11*b, 90)
repeat 3:
heading (0)
forward (19)
right (90*b)
forward(8)
right(90*b)
forward(19)
penUp()
left(90*b)
forward(22)
penDown()
moveTo(101*b,109)
moveTo(101*b,149)
moveTo(150*b,149)
setPos(0,131)
moveTo(79*b,131)
moveTo(79*b,159)
rightArc(12,b*90)
moveTo(150*b,171)
b -=2
def drawSpielAnzeige():
setLineWidth(75)
setPenColor("navy blue")
setPos(-110, 275)
moveTo(110, 275)
setPenColor("white")
setPos(-120, 260)
label("made by Tom & Jakob")
def drawPunkteAnzeige():
drawPunkteAnzeige2()
setPenColor(makeColor(0.2,0.2,0.2))
setLineWidth(1)
setPos(-75,-225)
heading(towards(0,0))
forward(20)
x,y=getX(),getY()
moveTo(-x,y)
moveTo(74,-225)
moveTo(-75,-225)
setPos(0,-220)
setFillColor(makeColor(0.2,0.2,0.2))
fill()
def drawPunkteAnzeige2():
setPos(-50,-250)
setLineWidth(50)
setPenColor("black")
moveTo(50,-250)
setPenColor("white")
setPos(-45,-258)
label(str(SiegeGelb))
setPos(-5,-258)
label(":")
setPos(30,-258)
label(str(SiegeRot))
drawSchriftAnzeige()
def drawSpieler():
c = 1
d = 1
repeat 2:
setLineWidth(50)
if c == -1:
setPenColor ("yellow")
else:
setPenColor("red")
setPos(300*c,-200)
moveTo(150*c,-200)
setLineWidth(1)
setPenColor("black")
heading(90)
setPos(125*c,-175)
for seite in [200,50,200,50]:
forward(seite*c)
right(90*c)
heading(towards(0,0))
forward(20)
x,y=getX(),getY()
setPos(325*c,-175)
heading(towards(0,0))
forward(34)
moveTo(x,y)
setPos(130*c,-170)
setFillColor(makeColor(1.0,0.6**d,0.6))
fill()
setPos(125*c,-225)
heading(towards(0,0))
forward(25)
moveTo(x,y)
setPos(120*c,-200)
setFillColor(makeColor(1.0,0.3**d,0.3))
fill()
c -= 2
d -= 1
setPenColor("black")
setPos(-310, -210)
label( input("gib einen Namen für Gelb ein:"))
setPos(140, -210)
label( input("gib einen Namen für Rot ein:"))
def dotXY(x, y, color):
setPenColor(color)
setFillColor(color)
setPos(x, y)
dot(20)
def putChip(spalte):
global a
x = -90 + spalte * 30
y = 60
setPos(x,y)
repeat :
if getPixelColorStr() != "white":
break
if a== 0:
x= -140
y= 160
repeat 10:
dotXY(x, y , "yellow")
sleep(0.03)
dotXY(x, y , "white")
x+= 5
repeat 8:
dotXY(x, y , "yellow")
sleep(0.03)
dotXY(x, y , "white")
y-= 5
repeat:
dotXY(x, y , "yellow")
sleep(0.03)
dotXY(x, y , "white")
if x == -90 + spalte * 30:
break
x+= 5
repeat 5:
dotXY(x, y , "yellow")
sleep(0.03)
dotXY(x, y , "white")
y-= 5
else:
x= 140
y= 160
repeat 10:
dotXY(x, y , "red")
sleep(0.03)
dotXY(x, y , "white")
x-= 5
repeat 8:
dotXY(x, y , "red")
sleep(0.03)
dotXY(x, y , "white")
y-= 5
repeat:
dotXY(x, y , "red")
sleep(0.03)
dotXY(x, y , "white")
if x == -90 + spalte * 30:
break
x-= 5
repeat 5:
dotXY(x, y , "red")
sleep(0.03)
dotXY(x, y , "white")
y-= 5
x = -90 + spalte * 30
y = 60
if a==0:
a+=1
setPos(x,y)
repeat 5:
setPos(x,y)
if getPixelColorStr() != "white":
a-=1
break
dotXY(x, y, "yellow")
sleep(0.3)
setPos(x, y - 30)
if getPixelColorStr() != "white":
break
dotXY(x, y , "white")
y -=30
else:
a-=1
repeat 5:
setPos(x,y)
if getPixelColorStr() != "white":
a+=1
break
dotXY(x, y, "red")
sleep(0.3)
setPos(x, y - 30)
if getPixelColorStr() != "white":
break
dotXY(x, y, "white")
y -= 30
break
def check():
global SiegeGelb, SiegeRot
y= 60
liste = []
repeat 5:
x= -90
repeat 7:
setPos(x,y)
liste.append( getPixelColorStr())
x += 30
y -= 30
i = 0
for farbe in liste:
if ( (i != 6 and i!= 13 and i != 20 and i!= 27 and i!= 34) and \
farbe != "white" and farbe == liste[i+1]):
if ( (i!= 5 and i!= 12 and i!= 19 and i!= 26 and i!= 33) and \
farbe == liste[i+2]):
if ( (i!= 4 and i!= 11 and i!= 18 and i!= 25 and i!= 32) and \
farbe == liste [i+3]):
if farbe == "yellow":
beep()
msgDlg("Gelb hat gewonnen")
SiegeGelb += 1
drawPunkteAnzeige2()
cleanGrid()
break
else:
beep()
msgDlg("Rot hat gewonnen")
SiegeRot += 1
drawPunkteAnzeige2()
cleanGrid()
break
i += 1
i = 0
for farbe in liste:
if ( i >= 7 and farbe != "white" and farbe == liste[i-7]):
if (i >= 14 and farbe == liste[i-14]):
if ( i >= 21 and farbe == liste [i-21]):
if farbe == "yellow":
beep()
msgDlg("Gelb hat gewonnen")
SiegeGelb += 1
drawPunkteAnzeige2()
cleanGrid()
break
else:
beep()
msgDlg("Rot hat gewonnen")
SiegeRot += 1
drawPunkteAnzeige2()
cleanGrid()
break
i += 1
i = 0
for farbe in liste:
if ( (i >= 7 and i != 27 and i!= 34) and farbe != "white" and \
farbe == liste[i-6]):
if ( (i >= 14 and i!= 26 and i != 33)and farbe == liste[i-12]):
if ( ( i >= 21 and i!= 25 and i != 32) and \
farbe == liste [i-18]):
if farbe == "yellow":
beep()
msgDlg("Gelb hat gewonnen")
SiegeGelb += 1
drawPunkteAnzeige2()
cleanGrid()
break
else:
beep()
msgDlg("Rot hat gewonnen")
SiegeRot += 1
drawPunkteAnzeige2()
cleanGrid()
break
i += 1
i = 0
for farbe in liste:
if ( i >= 8 and farbe != "white" and farbe == liste[i-8]):
if (i >= 16 and farbe == liste[i-16]):
if ( (i >= 24 and i!= 28 and i!= 29 and i!= 30) and \
farbe == liste [i-24]):
if farbe == "yellow":
beep()
msgDlg("Gelb hat gewonnen")
SiegeGelb += 1
drawPunkteAnzeige2()
cleanGrid()
break
else:
beep()
msgDlg("Rot hat gewonnen")
SiegeRot += 1
drawPunkteAnzeige2()
cleanGrid()
break
i += 1
def onClick(x, y):
spalte = (x + 105) // 30
if 0 <= spalte <= 6:
putChip(spalte)
check()
drawSchriftAnzeige()
makeTurtle(mouseHitX = onClick)
hideTurtle()
setTitle("Viergewinnt")
drawGrid()
drawAnzeige()
drawChipLager()
drawSpielAnzeige()
drawPunkteAnzeige()
drawSpieler()
check()