נוספו מצגות מערכת השידורים נוסח מלא
שחקו להנאתכם, תוכלו להרחיב את המשחק, הלוגיקה דורשת שימוש בתנאים מורכבים.
import turtle
import time
import random
screen = turtle.Screen()
screen.setup(700,700)
screen.addshape("x.gif")
screen.addshape("o.gif")
screen.addshape("check.gif")
screen.addshape("clean.gif")
screen.bgcolor("lightyellow")
x11=turtle.Turtle()
x12=turtle.Turtle()
x13=turtle.Turtle()
x21=turtle.Turtle()
x22=turtle.Turtle()
x23=turtle.Turtle()
x31=turtle.Turtle()
x32=turtle.Turtle()
x33=turtle.Turtle()
check=turtle.Turtle()
check.shape("check.gif")
check.pu()
check.goto(150,-250)
clr=turtle.Turtle()
clr.shape("clean.gif")
clr.pu()
clr.goto(-150,-250)
msg=turtle.Turtle()
msg.pu()
msg.ht()
msg.goto(-170, 250)
msg.write("X/O", align="left", font=("Courier", 30, "bold"))
wl=[0,1,2,3,4,5,6,7,8]
def wins(x,y):
global turn
line=True
msg.clear()
m="no win"
if(wl[0]==wl[3] and wl[3]==wl[6]):
m=str(wl[0])+" won"
elif(wl[1]==wl[4] and wl[4]==wl[7]):
m=str(wl[1])+" won"
elif(wl[3]==wl[5] and wl[5]==wl[8]):
m=str(wl[3])+" won"
elif(wl[0]==wl[1] and wl[1]==wl[2]):
m=str(wl[0])+" won"
elif(wl[3]==wl[4] and wl[4]==wl[5]):
m=str(wl[3])+" won"
elif(wl[6]==wl[7] and wl[7]==wl[8]):
m=str(wl[6])+" won"
elif(wl[0]==wl[4] and wl[4]==wl[8]):
m=str(wl[0])+" won"
elif(wl[2]==wl[4] and wl[4]==wl[6]):
m=str(wl[2])+" won"
else:
msg.write("no win", align="left", font=("Courier", 20, "bold"))
msg.write(m, align="left", font=("Courier", 20, "bold"))
def clickme11(x,y):
global turn
if turn%2==0:
x11.shape("x.gif")
wl[0]=1
else:
x11.shape("o.gif")
wl[0]=0
turn = turn + 1
clr.onclick(clearme)
check.onclick(checkme)
x11.onclick(clickme11)
x12.onclick(clickme12)
x13.onclick(clickme13)
x21.onclick(clickme21)
x22.onclick(clickme22)
x23.onclick(clickme23)
x31.onclick(clickme31)
x32.onclick(clickme32)
x33.onclick(clickme33)
def checkme(x,y):
wins(x,y)
setall()
def clearme(x,y):
setall()
clr.onclick(clearme)
import turtle
import time
import random
screen = turtle.Screen()
screen.setup(700,700)
screen.addshape("x.gif")
screen.addshape("o.gif")
screen.addshape("check.gif")
screen.addshape("clean.gif")
screen.bgcolor("lightyellow")
x11=turtle.Turtle()
x12=turtle.Turtle()
x13=turtle.Turtle()
x21=turtle.Turtle()
x22=turtle.Turtle()
x23=turtle.Turtle()
x31=turtle.Turtle()
x32=turtle.Turtle()
x33=turtle.Turtle()
check=turtle.Turtle()
check.shape("check.gif")
check.pu()
check.goto(150,-250)
clr=turtle.Turtle()
clr.shape("clean.gif")
clr.pu()
clr.goto(-150,-250)
msg=turtle.Turtle()
msg.pu()
msg.ht()
msg.goto(-170, 250)
msg.write("X/O", align="left", font=("Courier", 30, "bold"))
wl=[0,1,2,3,4,5,6,7,8]
def wins(x,y):
global turn
line=True
msg.clear()
m="no win"
if(wl[0]==wl[3] and wl[3]==wl[6]):
m=str(wl[0])+" won"
elif(wl[1]==wl[4] and wl[4]==wl[7]):
m=str(wl[1])+" won"
elif(wl[3]==wl[5] and wl[5]==wl[8]):
m=str(wl[3])+" won"
elif(wl[0]==wl[1] and wl[1]==wl[2]):
m=str(wl[0])+" won"
elif(wl[3]==wl[4] and wl[4]==wl[5]):
m=str(wl[3])+" won"
elif(wl[6]==wl[7] and wl[7]==wl[8]):
m=str(wl[6])+" won"
elif(wl[0]==wl[4] and wl[4]==wl[8]):
m=str(wl[0])+" won"
elif(wl[2]==wl[4] and wl[4]==wl[6]):
m=str(wl[2])+" won"
else:
msg.write("no win", align="left", font=("Courier", 20, "bold"))
msg.write(m, align="left", font=("Courier", 20, "bold"))
def clickme11(x,y):
global turn
if turn%2==0:
x11.shape("x.gif")
wl[0]=1
else:
x11.shape("o.gif")
wl[0]=0
turn = turn + 1
def clickme12(x,y):
global turn
if turn%2==0:
x12.shape("x.gif")
wl[1]=1
else:
x12.shape("o.gif")
wl[1]=0
turn = turn + 1
def clickme13(x,y):
global turn
if turn%2==0:
x13.shape("x.gif")
wl[2]=1
else:
x13.shape("o.gif")
wl[2]=0
turn = turn + 1
def clickme21(x,y):
global turn
if turn%2==0:
x21.shape("x.gif")
wl[3]=1
else:
x21.shape("o.gif")
wl[3]=0
turn = turn + 1
def clickme22(x,y):
global turn
if turn%2==0:
x22.shape("x.gif")
wl[4]=1
else:
x22.shape("o.gif")
wl[4]=0
turn = turn + 1
def clickme23(x,y):
global turn
if turn%2==0:
x23.shape("x.gif")
wl[5]=1
else:
x23.shape("o.gif")
wl[5]=0
turn = turn + 1
def clickme31(x,y):
global turn
if turn%2==0:
x31.shape("x.gif")
wl[6]=1
else:
x31.shape("o.gif")
wl[6]=0
turn = turn + 1
def clickme32(x,y):
global turn
if turn%2==0:
x32.shape("x.gif")
wl[7]=1
else:
x32.shape("o.gif")
wl[7]=0
turn = turn + 1
def clickme33(x,y):
global turn
if turn%2==0:
x33.shape("x.gif")
wl[8]=1
else:
x33.shape("o.gif")
wl[8]=0
turn = turn + 1
def setall():
global turn
turn = 0
wl=[0,1,2,3,4,5,6,7,8]
x11.pu()
x11.goto(-120,120)
x11.shape("square")
x11.color("white")
x11.speed(10)
x11.shapesize(6)
x12.pu()
x12.goto(0,120)
x12.shape("square")
x12.color("yellow")
x12.speed(10)
x12.shapesize(6)
x13.pu()
x13.goto(120,120)
x13.shape("square")
x13.color("white")
x13.speed(10)
x13.shapesize(6)
x21.pu()
x21.goto(-120,0)
x21.shape("square")
x21.color("yellow")
x21.speed(10)
x21.shapesize(6)
x22.pu()
x22.goto(0,0)
x22.shape("square")
x22.color("white")
x22.speed(10)
x22.shapesize(6)
x23.pu()
x23.goto(120,0)
x23.shape("square")
x23.color("yellow")
x23.speed(10)
x23.shapesize(6)
x31.pu()
x31.goto(-120,-120)
x31.shape("square")
x31.color("white")
x31.speed(10)
x31.shapesize(6)
x32.pu()
x32.goto(0,-120)
x32.shape("square")
x32.color("yellow")
x32.speed(10)
x32.shapesize(6)
x33.pu()
x33.goto(120,-120)
x33.shape("square")
x33.color("white")
x33.speed(10)
x33.shapesize(6)
setall()
def checkme(x,y):
wins(x,y)
setall()
def clearme(x,y):
setall()
clr.onclick(clearme)
check.onclick(checkme)
x11.onclick(clickme11)
x12.onclick(clickme12)
x13.onclick(clickme13)
x21.onclick(clickme21)
x22.onclick(clickme22)
x23.onclick(clickme23)
x31.onclick(clickme31)
x32.onclick(clickme32)
x33.onclick(clickme33)
screen.mainloop()
הלוגיקה דורשת שימוש בתנאים מורכבים
import turtle
import time
import random
screen = turtle.Screen()
screen.setup(700,700)
screen.addshape("click.gif")
screen.addshape("r.gif")
screen.addshape("p.gif")
screen.addshape("c.gif")
t4=turtle.Turtle()
t4.pu()
t4.goto(0,-200)
t4.shape("click.gif")
score1=turtle.Turtle()
score1.pu()
score1.goto(-200,200)
score1.write("", align="center", font=("Comic Sans MS", 60, "normal"))
score2=turtle.Turtle()
score2.pu()
score2.goto(200,200)
score2.write("", align="center", font=("Comic Sans MS", 60, "normal"))
move_speed = 10
turn_speed = 10
s1=0
s2=0
def clickme(x,y):
global s1
global s2
t1=turtle.Turtle()
t1.pu()
t1.goto(-200,0)
t2=turtle.Turtle()
t2.pu()
t2.goto(200,0)
t3=turtle.Turtle()
t3.pu()
t3.goto(0,120)
shapes=["r.gif","p.gif","c.gif"]
pic1=random.choice(shapes)
t1.shape(pic1)
pic2=random.choice(shapes)
t2.shape(pic2)
if pic1==pic2:
t3.write("Tekko", align="center", font=("Comic Sans MS", 80, "normal"))
elif (pic1=="r.gif" and pic2=="p.gif") or (pic1=="p.gif" and pic2=="r.gif") or (pic1=="c.gif" and pic2=="r.gif"):
t3.write("Player 1 won", align="center", font=("Comic Sans MS", 60, "normal"))
s1=s1+1
score1.write(s1, align="center", font=("Comic Sans MS", 60, "normal"))
else:
t3.write("Player 2 won", align="center", font=("Comic Sans MS", 60, "normal"))
s2=s2+1
score2.write(s2, align="center", font=("Comic Sans MS", 60, "normal"))
time.sleep(2)
t1.ht()
t2.ht()
t3.ht()
score1.ht()
score2.ht()
t1.shape("blank")
t2.shape("blank")
t3.clear()
score1.clear()
score2.clear()
if pic1==pic2:
t3.write("Tekko", align="center", font=("Comic Sans MS", 80, "normal"))
elif (pic1=="r.gif" and pic2=="p.gif") or (pic1=="p.gif" and pic2=="r.gif") or (pic1=="c.gif" and pic2=="r.gif"):
t3.write("Player 1 won", align="center", font=("Comic Sans MS", 60, "normal"))
s1=s1+1
score1.write(s1, align="center", font=("Comic Sans MS", 60, "normal"))
else:
t3.write("Player 2 won", align="center", font=("Comic Sans MS", 60, "normal"))
s2=s2+1
score2.write(s2, align="center", font=("Comic Sans MS", 60, "normal"))
import turtle
import time
import random
screen = turtle.Screen()
screen.setup(700,700)
screen.addshape("click.gif")
screen.addshape("r.gif")
screen.addshape("p.gif")
screen.addshape("c.gif")
t4=turtle.Turtle()
t4.pu()
t4.goto(0,-200)
t4.shape("click.gif")
score1=turtle.Turtle()
score1.pu()
score1.goto(-200,200)
score1.write("", align="center", font=("Comic Sans MS", 60, "normal"))
score2=turtle.Turtle()
score2.pu()
score2.goto(200,200)
score2.write("", align="center", font=("Comic Sans MS", 60, "normal"))
move_speed = 10
turn_speed = 10
s1=0
s2=0
def clickme(x,y):
global s1
global s2
t1=turtle.Turtle()
t1.pu()
t1.goto(-200,0)
t2=turtle.Turtle()
t2.pu()
t2.goto(200,0)
t3=turtle.Turtle()
t3.pu()
t3.goto(0,120)
shapes=["r.gif","p.gif","c.gif"]
pic1=random.choice(shapes)
t1.shape(pic1)
pic2=random.choice(shapes)
t2.shape(pic2)
if pic1==pic2:
t3.write("Tekko", align="center", font=("Comic Sans MS", 80, "normal"))
elif (pic1=="r.gif" and pic2=="p.gif") or (pic1=="p.gif" and pic2=="r.gif") or (pic1=="c.gif" and pic2=="r.gif"):
t3.write("Player 1 won", align="center", font=("Comic Sans MS", 60, "normal"))
s1=s1+1
score1.write(s1, align="center", font=("Comic Sans MS", 60, "normal"))
else:
t3.write("Player 2 won", align="center", font=("Comic Sans MS", 60, "normal"))
s2=s2+1
score2.write(s2, align="center", font=("Comic Sans MS", 60, "normal"))
time.sleep(2)
t1.ht()
t2.ht()
t3.ht()
score1.ht()
score2.ht()
t1.shape("blank")
t2.shape("blank")
t3.clear()
score1.clear()
score2.clear()
screen.onclick(clickme)
def forward():
turtle.forward(move_speed)
def backward():
turtle.backward(move_speed)
def left():
turtle.left(turn_speed)
def right():
turtle.right(turn_speed)
turtle.penup()
turtle.speed(0)
turtle.home()
# now associate the defs from above with certain keyboard events
screen.onkey(forward, "Up")
screen.onkey(backward, "Down")
screen.onkey(left, "Left")
screen.onkey(right, "Right")
screen.listen()
import turtle
import time
import random
screen = turtle.Screen()
screen.setup(500,500)
screen.bgcolor("lightgreen")
screen.addshape("click.gif")
screen.addshape("King.gif")
screen.addshape("Queen.gif")
screen.addshape("Prince.gif")
screen.addshape("Ace.gif")
תוכלו להרחיבה, להוסיף תמונות ולהגדיל את אפשריות ההשוואה.
hand=["King.gif","Queen.gif","Prince.gif"]
p1=turtle.Turtle()
p1.pu()
p1.goto(-200,0)
p1.shape("blank")
p2=turtle.Turtle()
p2.pu()
p2.goto(200,0)
p2.shape("blank")
t=turtle.Turtle()
t.pu()
t.goto(0,-200)
t.shape("blank")
msg=turtle.Turtle()
msg.pu()
msg.goto(0,150)
def clickme(x,y):
msg.clear()
h1=random.choice(hand)
h2=random.choice(hand)
p1.shape(h1)
p2.shape(h2)
#m="hand 1: "+ h1+" "+ "hand 2: "+ h2
#msg.write(m, align="center", font=("Comic Sans MS", 20, "normal"))
time.sleep(1)
msg.clear()
if h1==h2:
msg.write("Tekko", align="center", font=("Comic Sans MS", 40, "normal"))
elif h1=="King.gif" or (h1=="Queen.gif" and h2=="Prince.gif"):
msg.write("Player 1 won", align="center", font=("Comic Sans MS", 40, "normal"))
else:
msg.write("Player 2 won", align="center", font=("Comic Sans MS", 40, "normal"))
time.sleep(2)
msg.clear()
p1.shape("blank")
p2.shape("blank")
if h1==h2:
msg.write("Tekko", align="center", font=("Comic Sans MS", 40, "normal"))
elif h1=="King.gif" or (h1=="Queen.gif" and h2=="Prince.gif"):
msg.write("Player 1 won", align="center", font=("Comic Sans MS", 40, "normal"))
else:
msg.write("Player 2 won", align="center", font=("Comic Sans MS", 40, "normal"))
screen.onclick(clickme)
import turtle
import time
import random
hand=["King.gif","Queen.gif","Prince.gif"]
screen = turtle.Screen()
screen.setup(500,500)
screen.bgcolor("lightgreen")
screen.addshape("click.gif")
screen.addshape("King.gif")
screen.addshape("Queen.gif")
screen.addshape("Prince.gif")
screen.addshape("Ace.gif")
p1=turtle.Turtle()
p1.pu()
p1.goto(-200,0)
p1.shape("blank")
p2=turtle.Turtle()
p2.pu()
p2.goto(200,0)
p2.shape("blank")
t=turtle.Turtle()
t.pu()
t.goto(0,-200)
t.shape("blank")
msg=turtle.Turtle()
msg.pu()
msg.goto(0,150)
def clickme(x,y):
msg.clear()
h1=random.choice(hand)
h2=random.choice(hand)
p1.shape(h1)
p2.shape(h2)
#m="hand 1: "+ h1+" "+ "hand 2: "+ h2
#msg.write(m, align="center", font=("Comic Sans MS", 20, "normal"))
time.sleep(1)
msg.clear()
if h1==h2:
msg.write("Tekko", align="center", font=("Comic Sans MS", 40, "normal"))
elif h1=="King.gif" or (h1=="Queen.gif" and h2=="Prince.gif"):
msg.write("Player 1 won", align="center", font=("Comic Sans MS", 40, "normal"))
else:
msg.write("Player 2 won", align="center", font=("Comic Sans MS", 40, "normal"))
time.sleep(2)
msg.clear()
p1.shape("blank")
p2.shape("blank")
msg.write("Click to play again", align="center", font=("Comic Sans MS", 20, "normal"))
screen.onclick(clickme)