نام و نام خانوادگی:علی فدائی
دوره:کاربردی(پایتون)
#ـــــــــــــــــــــــــــــــــ import Turtle from turtle import* try: saved_var = open('var.txt') except FileNotFoundError: new_var = open('var.txt', 'w') new_var.writelines(['soundnumber=1\n', 'effectnumber=1\n', 'themenumber=1']) new_var.close() saved_var = open('var.txt') for line in saved_var: if line == 'soundnumber=1\n': soundnumber=1 break elif line == 'soundnumber=2\n': soundnumber=2 break elif line == 'soundnumber=3\n': soundnumber=3 break elif line == 'soundnumber=4\n': soundnumber=4 break for line in saved_var: if line == 'effectnumber=1\n': effectnumber=1 changeeffect=1 break elif line == 'effectnumber=2\n': effectnumber=2 changeeffect=2 break elif line == 'effectnumber=3\n': effectnumber=3 changeeffect=3 break elif line == 'effectnumber=4\n': effectnumber=4 changeeffect=4 break for line in saved_var: if line == 'themenumber=1': themenumber=1 break elif line == 'themenumber=2': themenumber=2 break elif line == 'themenumber=3': themenumber=3 break elif line == 'themenumber=4': themenumber=4 break saved_var.close() lightyellowcolor=['lightyellow','oldlace','lavenderblush','lightyellow'] tealcolor=['teal','lightseagreen','midnightblue','olive'] lightsalmoncolor=['lightsalmon','pink','paleturquoise','gold'] palegreencolor=['palegreen','palegreen','palegreen','palegreen'] lightcoralcolor=['lightcoral','lightcoral','lightcoral','lightcoral'] lawngreencolor=['lawngreen','yellow','gold','springgreen'] crimsoncolor=['crimson','crimson','crimson','crimson'] darkredcolor=['darkred','purple','firebrick','maroon'] goldcolor=['gold','tomato','yellow','darkred'] limecolor=['lime','lime','lime','lime'] silvercolor=['silver','silver','silver','silver',] dimgreycolor=['dimgrey','dimgrey','dimgrey','dimgrey'] lightyellow=lightyellowcolor[themenumber-1] teal=tealcolor[themenumber-1] lightsalmon=lightsalmoncolor[themenumber-1] palegreen=palegreencolor[themenumber-1] lightcoral=lightcoralcolor[themenumber-1] lawngreen=lawngreencolor[themenumber-1] crimson=crimsoncolor[themenumber-1] darkred=darkredcolor[themenumber-1] gold=goldcolor[themenumber-1] lime=limecolor[themenumber-1] silver=silvercolor[themenumber-1] dimgrey=dimgreycolor[themenumber-1] bgcolor(lightyellow) title('XO Game 1.2.7') tracer(False) onclick(False) onscreenclick(None) levelname=Turtle() rplyt=Turtle() plyrt=Turtle() lvlt=Turtle() comt=Turtle() tblt=Turtle() wrtt=Turtle() hidt=Turtle() trnt=Turtle() mnut=Turtle() lodt=Turtle() stgt=Turtle() click=Turtle() #ـــــــــــــــــــــــــــــــــ import another libs from random import randint, choice from time import sleep from sys import exit from os import getcwd from pygame import mixer cwd = getcwd() cwd = (str("{0}".format(cwd))+'/') mixer.init() playlist=['track 1.mp3','track 2.mp3','track 3.mp3'] if soundnumber < 4: mixer.music.load(cwd+playlist[soundnumber-1]) mixer.music.play(-1) #ـــــــــــــــــــــــــــــــــ about Turtles levelname.ht() rplyt.ht() plyrt.ht() lvlt.ht() comt.ht() tblt.ht() wrtt.ht() hidt.ht() trnt.ht() trnt.ht() mnut.ht() lodt.ht() stgt.ht() click.ht() ht() levelname.pu() rplyt.pu() plyrt.pu() lvlt.pu() comt.pu() tblt.pu() wrtt.pu() hidt.pu() trnt.pu() mnut.pu() lodt.pu() stgt.pu() click.pu() pu() levelname.speed(0) rplyt.speed(0) plyrt.speed(0) lvlt.speed(0) comt.speed(0) tblt.speed(0) wrtt.speed(0) hidt.speed(0) trnt.speed(0) mnut.speed(0) lodt.speed(0) stgt.speed(0) click.speed(0) speed(0) #ـــــــــــــــــــــــــــــــــ global varibles and lists full = [0]*9 game_on = False player1 = None player2 = None movep = [] movec = [] fh = False rnhl = -1 first = False lc = False nobat = False level = False rncm = False table = False lvl = False rply = False typ = False menudone = False thn=1 efn=1 son=1 mnuu = ['computer','human'] lev = ['Easy','Medium','Hard'] levxy = [[160,80],[60,-20],[-40,-120]] mnuxy = [[200,80],[60,-60]] dooz = [[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]] dd = [[],[],[],[],[],[],[],[],[]] #ـــــــــــــــــــــــــــــــــ sleeper def sleeper(n): tracer(True) sleep(n) tracer(False) #ـــــــــــــــــــــــــــــــــ starter def game(): global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey tracer(False) wrtt.pencolor(lightsalmon) wrtt.goto(0,160) wrtt.write("Programmer",font=('Aviny',40),align='center') wrtt.pencolor(teal) wrtt.goto(0,70) wrtt.write("Ali Fadaeifard",font=('Aviny',60),align='center') wrtt.pencolor(lightsalmon) wrtt.goto(0,-10) wrtt.write("Thanks to",font=('Aviny',40),align='center') wrtt.pencolor(teal) wrtt.goto(0,-90) wrtt.write("Mr. Farhadi",font=('Aviny',60),align='center') wrtt.pu() wrtt.pencolor(teal) wrtt.pensize(100) wrtt.goto(0,-150) wrtt.pd() wrtt.fd(0) wrtt.pu() wrtt.pensize(5) wrtt.goto(-17,-180) wrtt.seth(30) wrtt.fillcolor(lightsalmon) wrtt.pencolor(lightsalmon) wrtt.pd() wrtt.begin_fill() for i in range(3): wrtt.fd(60) wrtt.lt(120) wrtt.end_fill() wrtt.pu() onscreenclick(None) tracer(True) onscreenclick(go_first_menu) #ـــــــــــــــــــــــــــــــــ go to first menu def go_first_menu(x,y): global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey if (((y/50+3)**2) + ((x/50)**2)) <= 1: onscreenclick(None) click.pu() click.pensize(3) click.pencolor(gold) click.goto(0,-200) click.pd() click.seth(0) click.circle(50) onscreenclick(None) sleeper(0.2) click.clear() onscreenclick(None) sleeper(0.1) wrtt.pencolor(teal) wrtt.pensize(20) wrtt.pu() wrtt.goto(-200,-220) wrtt.pd() wrtt.goto(200,-220) wrtt.speed(1) wrtt.pencolor(gold) wrtt.pensize(16) wrtt.pu() wrtt.goto(-200,-220) wrtt.pd() onscreenclick(None) tracer(True) wrtt.speed(0) lodt.pencolor(teal) lodt.pu() lodt.goto(-200,-265) lodt.write('loding',font=('Aviny',20),align='left') rnstop1 = randint(1,99) rnstop2 = randint(1,99) rnstop3 = randint(1,99) if rnstop1 == rnstop2 and rnstop2 > 50: rnstp2 == randint(50,99) elif rnstop1 == rnstop2 and rnstop2 <= 50: rnstp2 == randint(1,50) if rnstop1 == rnstop3 and rnstop2 > 50: rnstp3 == randint(50,99) elif rnstop1 == rnstop3 and rnstop3 <= 50: rnstp3 == randint(1,50) if rnstop2 == rnstop3 and rnstop2 > 50: rnstp3 == randint(50,99) elif rnstop2 == rnstop3 and rnstop3 <=50: rnstp3 == randint(1,50) for i in range(1,51): if i*2-1 == rnstop1: rnsleep = 2 elif i*2-1 == rnstop2: rnsleep = 1 elif i*2-1 == rnstop3: rnsleep = 0.5 else: rnsleep = 0.05 tracer(False) wrtt.seth(0) wrtt.fd(8) onscreenclick(None) tracer(True) mnut.pencolor(teal) mnut.pu() mnut.goto(-150,-265) mnut.write(str(i*2-1)+'%',font=('Aviny',20),align='left') sleeper(rnsleep) mnut.clear() mnut.write(str(i*2)+'%',font=('Aviny',20),align='left') onscreenclick(None) tracer(True) if i*2 == rnstop1: rnsleep = 2 elif i*2 == rnstop2: rnsleep = 1 elif i*2 == rnstop3: rnsleep = 0.5 else: rnsleep = 0.05 sleeper(rnsleep) if i*2 != 100: mnut.clear() sleeper(1) wrtt.pu() wrtt.speed(0) mnut.pu() mnut.speed(0) wrtt.clear() mnut.clear() lodt.clear() first_menu() #ـــــــــــــــــــــــــــــــــ first menu def first_menu(): tracer(False) onscreenclick(None) global typ, lvl, table, rply, menudone, mnuu, mnuy, lw_typ, boxnames global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey lw_typ=[300,80] mnuy=[160,60] boxnames=['Play VS Computer','Play VS Player'] mnuu=['computer','human'] mnut.fillcolor(teal) mnut.pencolor(lightsalmon) mnut.pensize(5) mnut.pu() mnut.goto(0,175) mnut.write("Choose the game type",font=('Aviny',60),align='center') for i in range(2): mnut.goto(-150,mnuy[i]) mnut.seth(0) mnut.pd() mnut.begin_fill() for j in range(4): mnut.fd(lw_typ[j%2]) mnut.rt(90) mnut.end_fill() mnut.pu() mnut.goto(0,mnuy[i]-75) mnut.write(boxnames[i],font=('Aviny',30),align='center') mnut.goto(-150,-40) mnut.seth(0) mnut.pd() mnut.fillcolor(teal) mnut.begin_fill() for i in range(4): mnut.fd(lw_typ[i%2]) mnut.rt(90) mnut.end_fill() mnut.pu() mnut.goto(0,-115) mnut.write('Setting',font=('Aviny',30),align='center') mnut.goto(-150,-140) mnut.seth(0) mnut.pd() mnut.fillcolor(darkred) mnut.begin_fill() for i in range(4): mnut.fd(lw_typ[i%2]) mnut.rt(90) mnut.end_fill() mnut.pu() mnut.goto(0,-215) mnut.write('Exit',font=('Aviny',30),align='center') lvl = False rply = False table = False menudone = True onscreenclick(choosetype) #ـــــــــــــــــــــــــــــــــ choose type def choosetype(x,y): global typ, mnuu, menuy, menudone, lvl, mnuy, lw_typ, boxnames global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey if -150 <= x <= 150: onscreenclick(None) for i in range(2): if mnuy[i]-80 <= y <= mnuy[i]: typ=mnuu[i] click.pencolor(lawngreen) click.pu() click.goto(-150,mnuy[i]) click.seth(0) click.pd() click.fillcolor(teal) click.begin_fill() for j in range(4): click.fd(lw_typ[j%2]) click.rt(90) click.end_fill() click.pu() click.goto(0,mnuy[i]-75) click.write(boxnames[i],font=('Aviny',30),align='center') onscreenclick(None) sleeper(0.2) click.clear() onscreenclick(None) sleeper(0.3) mnut.clear() types(typ) menudone = False break if -120 <= y <= -40: click.pencolor(lawngreen) click.pu() click.goto(-150,-40) click.seth(0) click.pd() click.fillcolor(teal) click.begin_fill() for i in range(4): click.fd(lw_typ[i%2]) click.rt(90) click.end_fill() click.pu() click.goto(0,-115) click.write('Setting',font=('Aviny',30),align='center') onscreenclick(None) sleeper(0.2) click.clear() onscreenclick(None) sleeper(0.3) mnut.clear() setting() if -220 <= y <= -140: click.pencolor(crimson) click.pu() click.goto(-150,-140) click.seth(0) click.pd() click.fillcolor(darkred) click.begin_fill() for i in range(4): click.fd(lw_typ[i%2]) click.rt(90) click.end_fill() click.pu() click.goto(0,-215) click.write('Exit',font=('Aviny',30),align='center') onscreenclick(None) sleeper(0.2) click.clear() onscreenclick(None) sleeper(0.3) mixer.music.stop() bye() exit() #ـــــــــــــــــــــــــــــــــ setting def setting(): onscreenclick(None) tracer(False) global sett, sety, stlw, setxy global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey setxy=[[160,80],[60,-20],[-40,-120]] stlw=[150,80] sety=[160,60,-40] sett=['Sounds','Effects','Themes'] mnut.pencolor(teal) mnut.fillcolor(lightsalmon) mnut.pensize(5) mnut.pu() mnut.goto(0,165) mnut.write("Setting",font=('Aviny',60),align='center') for i in range(3): mnut.goto(-75,sety[i]) mnut.seth(0) mnut.pd() mnut.begin_fill() for j in range(4): mnut.fd(stlw[j%2]) mnut.rt(90) mnut.end_fill() mnut.pu() mnut.goto(0,sety[i]-75) mnut.write(sett[i],font=('Aviny',30),align='center') mnut.goto(-75,-140) mnut.seth(0) mnut.pd() mnut.fillcolor(darkred) mnut.begin_fill() for j in range(4): mnut.fd(stlw[j%2]) mnut.rt(90) mnut.end_fill() mnut.pu() mnut.goto(0,-215) mnut.write('Back',font=('Aviny',30),align='center') onscreenclick(choosesetting) #ـــــــــــــــــــــــــــــــــ choose setting def choosesetting(x,y): global first, sett, sety, stlw, setxy global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey onscreenclick(None) if lc == False: if -75 <= x <= 75: for i in range(3): if setxy[i][1] <= y <= setxy[i][0]: click.pencolor(lawngreen) click.goto(-75,sety[i]) click.seth(0) click.pd() click.fillcolor(lightsalmon) click.begin_fill() for j in range(4): click.fd(stlw[j%2]) click.rt(90) click.end_fill() click.pu() click.goto(0,sety[i]-75) click.write(sett[i],font=('Aviny',30),align='center') sleeper(0.2) click.clear() sleeper(0.3) mnut.clear() go_settings(i) break if -215 <= y <= -140: typ = False click.pencolor(crimson) click.goto(-75,-140) click.seth(0) click.pd() click.fillcolor(darkred) click.begin_fill() for j in range(4): click.fd(stlw[j%2]) click.rt(90) click.end_fill() click.pu() click.goto(0,-215) click.write('Back',font=('Aviny',30),align='center') onscreenclick(None) sleeper(0.2) click.clear() onscreenclick(None) sleeper(0.3) mnut.clear() first_menu() else: onscreenclick(choosesetting) #ـــــــــــــــــــــــــــــــــ varibale saver def varible_saver(s, e, t): SaveNewVarible = open('var.txt', 'w') SaveNewVarible.writelines(['soundnumber='+str(s)+'\n', 'effectnumber='+str(e)+'\n', 'themenumber='+str(t)]) SaveNewVarible.close() #ـــــــــــــــــــــــــــــــــ go settings def go_settings(i): global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey if i == 0: sounds_menu() elif i == 1: effects_menu() elif i == 2: themes_menu() #ـــــــــــــــــــــــــــــــــ sounds menu def sounds_menu(): onscreenclick(None) tracer(False) global snd, sndy, sndx, lw, lw1, sndxy, sndfc, sndtxtnum, tmlw, tmlw1, sounds_on global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey sndxy=[[160,80],[60,-20],[-40,-120],[-140,-220]] tmlw1=[80,80] tmlw=[180,80] sndtxtnum=0 sndtxty=[-115,-215] sndx=[-90,10] lw1=[80,80] lw=[180,80] sndfc=[lightsalmon,darkred] sndy=[160,60,-40,-140] snd=['1','2','3','4','Save','Back'] stgt.pencolor(teal) stgt.fillcolor(lightsalmon) stgt.pensize(5) stgt.pu() stgt.goto(0,165) stgt.write("Sounds",font=('Aviny',60),align='center') for i in range(2): for q in range(2): stgt.goto(sndx[q],sndy[i]) stgt.seth(0) stgt.pd() stgt.begin_fill() for j in range(4): stgt.fd(lw1[j%2]) stgt.rt(90) stgt.end_fill() stgt.pu() stgt.goto(sndx[q]+40,sndy[i]-75) stgt.write(snd[sndtxtnum],font=('Aviny',30),align='center') sndtxtnum+=1 for i in range(2): stgt.goto(-90,sndy[i+2]) stgt.seth(0) stgt.pd() stgt.fillcolor(sndfc[i]) stgt.begin_fill() for j in range(4): stgt.fd(lw[j%2]) stgt.rt(90) stgt.end_fill() stgt.pu() stgt.goto(0,sndtxty[i]) stgt.write(snd[i+4],font=('Aviny',30),align='center') for j in range(4): if soundnumber == j+1: if soundnumber == 1 or soundnumber == 2: i=0 else: i=1 click.clear() click.pencolor(lawngreen) click.goto(sndx[j%2],sndy[i]) click.seth(0) click.pd() click.fillcolor(lightsalmon) click.begin_fill() for q in range(4): click.fd(tmlw1[q%2]) click.rt(90) click.end_fill() click.pu() click.goto(sndx[j%2]+40,sndy[i]-75) click.write(snd[soundnumber-1],font=('Aviny',30),align='center') sleeper(0.2) onscreenclick(sounds) #ـــــــــــــــــــــــــــــــــ sounds def sounds(x,y): tracer(False) global snd, sndy, sndx, tmlw, tmlw1, sndxy, sndfc, sndtxtnum, sounds_on, son, themenumber, effectnumber, soundnumber global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey sounds_on = True if -90 <= x <= 90: onscreenclick(None) for i in range(4): if sndxy[i][1] <= y <= sndxy[i][0]: if i <= 1: for j in range(2): if sndx[j] <= x <= sndx[j]+80: click.clear() click.pencolor(lawngreen) click.goto(sndx[j],sndy[i]) click.seth(0) click.pd() click.fillcolor(lightsalmon) click.begin_fill() for q in range(4): click.fd(tmlw1[q%2]) click.rt(90) click.end_fill() click.pu() click.goto(sndx[j]+40,sndy[i]-75) if i == 0: if j == 0: n = 0 elif j ==1: n = 1 elif i == 1: if j == 0: n = 2 elif j ==1: n = 3 click.write(snd[n],font=('Aviny',30),align='center') sleeper(0.2) son=n+1 elif i == 2: click.pencolor(lawngreen) click.goto(-90,sndy[i]) click.seth(0) click.pd() click.fillcolor(lightsalmon) click.begin_fill() for q in range(4): click.fd(tmlw[q%2]) click.rt(90) click.end_fill() click.pu() click.goto(0,sndy[i]-75) click.write('Save',font=('Aviny',30),align='center') onscreenclick(None) sleeper(0.2) click.clear() sleeper(0.3) stgt.clear() soundnumber=son sounds_on = False varible_saver(soundnumber, effectnumber, themenumber) playsounds(soundnumber) setting() elif i == 3: click.clear() click.pencolor(crimson) click.goto(-90,sndy[i]) click.seth(0) click.pd() click.fillcolor(darkred) click.begin_fill() for q in range(4): click.fd(tmlw[q%2]) click.rt(90) click.end_fill() click.pu() click.goto(0,sndy[i]-75) click.write('Back',font=('Aviny',30),align='center') onscreenclick(None) sleeper(0.2) click.clear() sleeper(0.3) stgt.clear() soundnumber=1 sounds_on = False setting() onscreenclick(gosounds) #ـــــــــــــــــــــــــــــــــ play sounds def playsounds(n): path = cwd playlist=['track 1.mp3','track 2.mp3','track 3.mp3'] if n < 4: mixer.music.load(path+playlist[n-1]) mixer.music.stop() mixer.music.play(-1) else: mixer.music.stop() #ـــــــــــــــــــــــــــــــــ go sounds def gosounds(x,y): onscreenclick(None) global sounds_on global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey if sounds_on == True: click.clear() sounds(x,y) else: choosesetting(x,y) #ـــــــــــــــــــــــــــــــــ effects menu def effects_menu(): onscreenclick(None) tracer(False) global snd, sndy, sndx, lw, lw1, sndxy, sndfc, sndtxtnum, tmlw1, tmlw, effectnumber global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey sndxy=[[160,80],[60,-20],[-40,-120],[-140,-220]] tmlw1=[80,80] tmlw=[180,80] sndtxtnum=0 sndtxty=[-115,-215] sndx=[-90,10] lw1=[80,80] lw=[180,80] sndfc=[lightsalmon,darkred] sndy=[160,60,-40,-140] snd=['1','2','3','4','Save','Back'] stgt.pencolor(teal) stgt.fillcolor(lightsalmon) stgt.pensize(5) stgt.pu() stgt.goto(0,165) stgt.write("Effects",font=('Aviny',60),align='center') for i in range(2): for q in range(2): stgt.goto(sndx[q],sndy[i]) stgt.seth(0) stgt.pd() stgt.begin_fill() for j in range(4): stgt.fd(lw1[j%2]) stgt.rt(90) stgt.end_fill() stgt.pu() stgt.goto(sndx[q]+40,sndy[i]-75) stgt.write(snd[sndtxtnum],font=('Aviny',30),align='center') sndtxtnum+=1 for i in range(2): stgt.goto(-90,sndy[i+2]) stgt.seth(0) stgt.pd() stgt.fillcolor(sndfc[i]) stgt.begin_fill() for j in range(4): stgt.fd(lw[j%2]) stgt.rt(90) stgt.end_fill() stgt.pu() stgt.goto(0,sndtxty[i]) stgt.write(snd[i+4],font=('Aviny',30),align='center') for j in range(4): if effectnumber == j+1: if effectnumber == 1 or effectnumber == 2: i=0 else: i=1 click.clear() click.pencolor(lawngreen) click.goto(sndx[j%2],sndy[i]) click.seth(0) click.pd() click.fillcolor(lightsalmon) click.begin_fill() for q in range(4): click.fd(tmlw1[q%2]) click.rt(90) click.end_fill() click.pu() click.goto(sndx[j%2]+40,sndy[i]-75) click.write(snd[effectnumber-1],font=('Aviny',30),align='center') sleeper(0.2) onscreenclick(effects) #ـــــــــــــــــــــــــــــــــ effects def effects(x,y): tracer(False) global changeeffect, snd, sndy, sndx, tmlw, tmlw1, sndxy, sndfc, sndtxtnum, effects_on, efn, themenumber, effectnumber, soundnumber global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey effects_on = True if -90 <= x <= 90: onscreenclick(None) for i in range(4): if sndxy[i][1] <= y <= sndxy[i][0]: if i <= 1: for j in range(2): if sndx[j] <= x <= sndx[j]+80: click.clear() click.pencolor(lawngreen) click.goto(sndx[j],sndy[i]) click.seth(0) click.pd() click.fillcolor(lightsalmon) click.begin_fill() for q in range(4): click.fd(tmlw1[q%2]) click.rt(90) click.end_fill() click.pu() click.goto(sndx[j]+40,sndy[i]-75) if i == 0: if j == 0: n = 0 elif j ==1: n = 1 elif i == 1: if j == 0: n = 2 elif j ==1: n = 3 click.write(snd[n],font=('Aviny',30),align='center') sleeper(0.2) efn=n+1 elif i == 2: click.pencolor(lawngreen) click.goto(-90,sndy[i]) click.seth(0) click.pd() click.fillcolor(lightsalmon) click.begin_fill() for q in range(4): click.fd(tmlw[q%2]) click.rt(90) click.end_fill() click.pu() click.goto(0,sndy[i]-75) click.write('Save',font=('Aviny',30),align='center') onscreenclick(None) sleeper(0.2) click.clear() sleeper(0.3) stgt.clear() effectnumber=efn changeeffect=effectnumber effects_on = False varible_saver(soundnumber, effectnumber, themenumber) setting() elif i == 3: click.clear() click.pencolor(crimson) click.goto(-90,sndy[i]) click.seth(0) click.pd() click.fillcolor(darkred) click.begin_fill() for q in range(4): click.fd(tmlw[q%2]) click.rt(90) click.end_fill() click.pu() click.goto(0,sndy[i]-75) click.write('Back',font=('Aviny',30),align='center') onscreenclick(None) sleeper(0.2) click.clear() sleeper(0.3) stgt.clear() effects_on = False setting() onscreenclick(goeffects) #ـــــــــــــــــــــــــــــــــ go effects def goeffects(x,y): onscreenclick(None) global effects_on global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey if effects_on == True: click.clear() effects(x,y) else: choosesetting(x,y) #ـــــــــــــــــــــــــــــــــ themes menu def themes_menu(): onscreenclick(None) tracer(False) global snd, sndy, sndx, tmlw, tmlw1, sndxy, sndfc, sndtxtnum global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey sndxy=[[160,80],[60,-20],[-40,-120],[-140,-220]] sndtxtnum=0 sndtxty=[-115,-215] sndx=[-90,10] tmlw1=[80,80] tmlw=[180,80] sndfc=[lightsalmon,darkred] sndy=[160,60,-40,-140] snd=['1','2','3','4','Save','Back'] stgt.pencolor(teal) stgt.fillcolor(lightsalmon) stgt.pensize(5) stgt.pu() stgt.goto(0,165) stgt.write("Themes",font=('Aviny',60),align='center') for i in range(2): for q in range(2): stgt.goto(sndx[q],sndy[i]) stgt.seth(0) stgt.pd() stgt.begin_fill() for j in range(4): stgt.fd(tmlw1[j%2]) stgt.rt(90) stgt.end_fill() stgt.pu() stgt.goto(sndx[q]+40,sndy[i]-75) stgt.write(snd[sndtxtnum],font=('Aviny',30),align='center') sndtxtnum+=1 for i in range(2): stgt.goto(-90,sndy[i+2]) stgt.seth(0) stgt.pd() stgt.fillcolor(sndfc[i]) stgt.begin_fill() for j in range(4): stgt.fd(tmlw[j%2]) stgt.rt(90) stgt.end_fill() stgt.pu() stgt.goto(0,sndtxty[i]) stgt.write(snd[i+4],font=('Aviny',30),align='center') for j in range(4): if themenumber == j+1: if themenumber == 1 or themenumber == 2: i=0 else: i=1 click.clear() click.pencolor(lawngreen) click.goto(sndx[j%2],sndy[i]) click.seth(0) click.pd() click.fillcolor(lightsalmon) click.begin_fill() for q in range(4): click.fd(tmlw1[q%2]) click.rt(90) click.end_fill() click.pu() click.goto(sndx[j%2]+40,sndy[i]-75) click.write(snd[themenumber-1],font=('Aviny',30),align='center') sleeper(0.2) onscreenclick(themes) #ـــــــــــــــــــــــــــــــــ themes def themes(x,y): tracer(False) global snd, sndy, sndx, tmlw, tmlw1, sndxy, sndfc, sndtxtnum, themes_on, thn, themenumber, effectnumber, soundnumber global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey themes_on = True if -90 <= x <= 90: onscreenclick(None) for i in range(4): if sndxy[i][1] <= y <= sndxy[i][0]: if i <= 1: for j in range(2): if sndx[j] <= x <= sndx[j]+80: click.clear() click.pencolor(lawngreen) click.goto(sndx[j],sndy[i]) click.seth(0) click.pd() click.fillcolor(lightsalmon) click.begin_fill() for q in range(4): click.fd(tmlw1[q%2]) click.rt(90) click.end_fill() click.pu() click.goto(sndx[j]+40,sndy[i]-75) if i == 0: if j == 0: n = 0 elif j ==1: n = 1 elif i == 1: if j == 0: n = 2 elif j ==1: n = 3 click.write(snd[n],font=('Aviny',30),align='center') sleeper(0.2) thn=n+1 elif i == 2: click.pencolor(lawngreen) click.goto(-90,sndy[i]) click.seth(0) click.pd() click.fillcolor(lightsalmon) click.begin_fill() for q in range(4): click.fd(tmlw[q%2]) click.rt(90) click.end_fill() click.pu() click.goto(0,sndy[i]-75) click.write('Save',font=('Aviny',30),align='center') onscreenclick(None) sleeper(0.2) click.clear() sleeper(0.3) stgt.clear() themes_on = False themenumber=thn changetheme(themenumber-1) varible_saver(soundnumber, effectnumber, themenumber) setting() elif i == 3: click.clear() click.pencolor(crimson) click.goto(-90,sndy[i]) click.seth(0) click.pd() click.fillcolor(darkred) click.begin_fill() for q in range(4): click.fd(tmlw[q%2]) click.rt(90) click.end_fill() click.pu() click.goto(0,sndy[i]-75) click.write('Back',font=('Aviny',30),align='center') onscreenclick(None) sleeper(0.2) click.clear() sleeper(0.3) stgt.clear() themes_on = False setting() onscreenclick(gothemes) #ـــــــــــــــــــــــــــــــــ go themes def gothemes(x,y): onscreenclick(None) global themes_on global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey if themes_on == True: click.clear() themes(x,y) else: choosesetting(x,y) #ـــــــــــــــــــــــــــــــــ change theme def changetheme(n): tracer(False) global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey lightyellowcolor=['lightyellow','oldlace','lavenderblush','lightyellow'] tealcolor=['teal','lightseagreen','midnightblue','olive'] lightsalmoncolor=['lightsalmon','pink','paleturquoise','gold'] palegreencolor=['palegreen','palegreen','palegreen','palegreen'] lightcoralcolor=['lightcoral','lightcoral','lightcoral','lightcoral'] lawngreencolor=['lawngreen','yellow','gold','springgreen'] crimsoncolor=['crimson','crimson','crimson','crimson'] darkredcolor=['darkred','purple','firebrick','maroon'] goldcolor=['gold','tomato','yellow','darkred'] limecolor=['lime','lime','lime','lime'] silvercolor=['silver','silver','silver','silver',] dimgreycolor=['dimgrey','dimgrey','dimgrey','dimgrey'] lightyellow=lightyellowcolor[n] teal=tealcolor[n] lightsalmon=lightsalmoncolor[n] palegreen=palegreencolor[n] lightcoral=lightcoralcolor[n] lawngreen=lawngreencolor[n] crimson=crimsoncolor[n] darkred=darkredcolor[n] gold=goldcolor[n] lime=limecolor[n] silver=silvercolor[n] dimgrey=dimgreycolor[n] update() #ـــــــــــــــــــــــــــــــــ types def types(tp): global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey if tp=='computer' and lc == False and lvl == False: level_btn() elif tp=='human': draw_table() onscreenclick(human) #ـــــــــــــــــــــــــــــــــ level buttons def level_btn(): onscreenclick(None) tracer(False) global menudone, lvl, table, rply, levy, lw, lev global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey levxy=[[160,80],[60,-20],[-40,-120]] lw=[150,80] levy=[160,60,-40] lev=['Easy','Medium','Hard'] lvlt.pencolor(teal) lvlt.fillcolor(lightsalmon) lvlt.pensize(5) lvlt.pu() lvlt.goto(0,165) lvlt.write("Choose the game level",font=('Aviny',60),align='center') for i in range(3): lvlt.goto(-75,levy[i]) lvlt.seth(0) lvlt.pd() lvlt.begin_fill() for j in range(4): lvlt.fd(lw[j%2]) lvlt.rt(90) lvlt.end_fill() lvlt.pu() lvlt.goto(0,levy[i]-75) lvlt.write(lev[i],font=('Aviny',30),align='center') lvlt.goto(-75,-140) lvlt.seth(0) lvlt.pd() lvlt.fillcolor(darkred) lvlt.begin_fill() for j in range(4): lvlt.fd(lw[j%2]) lvlt.rt(90) lvlt.end_fill() lvlt.pu() lvlt.goto(0,-215) lvlt.write('Back',font=('Aviny',30),align='center') lvl = True rply = False table = False menudone = False onscreenclick(chooselevel) #ـــــــــــــــــــــــــــــــــ print level name def print_level(): global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey levelname.pencolor(teal) levelname.goto(0,-275) levelname.write(level,font=('Aviny',60),align='center') #ـــــــــــــــــــــــــــــــــ choose level def chooselevel(x,y): global first, level, lc, lvl, typ, levy, lw, lev global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey if lc == False: if -75 <= x <= 75: onscreenclick(None) for i in range(3): if levxy[i][1] <= y <= levxy[i][0]: level=lev[i] click.pencolor(lawngreen) click.goto(-75,levy[i]) click.seth(0) click.pd() click.fillcolor(lightsalmon) click.begin_fill() for j in range(4): click.fd(lw[j%2]) click.rt(90) click.end_fill() click.pu() click.goto(0,levy[i]-75) click.write(lev[i],font=('Aviny',30),align='center') onscreenclick(None) sleeper(0.2) click.clear() onscreenclick(None) sleeper(0.3) lvlt.clear() levels(level) lc = True lvl = True break if -215 <= y <= -140: typ = False click.pencolor(crimson) click.goto(-75,-140) click.seth(0) click.pd() click.fillcolor(darkred) click.begin_fill() for j in range(4): click.fd(lw[j%2]) click.rt(90) click.end_fill() click.pu() click.goto(0,-215) click.write('Back',font=('Aviny',30),align='center') onscreenclick(None) sleeper(0.2) click.clear() onscreenclick(None) sleeper(0.3) lvlt.clear() first_menu() #ـــــــــــــــــــــــــــــــــ levels def levels(ln): global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey global nobat, first onscreenclick(None) if ln=='Easy': first='player' draw_table() if full.count(0)==9: nobat='player' onscreenclick(your_turn) else: if ln=='Medium': first='player' draw_table() if full.count(0)==9: nobat='player' onscreenclick(your_turn) else: if ln=='Hard': first='com' draw_table() if full.count(0)==9: nobat='com' #ـــــــــــــــــــــــــــــــــ x,y circles def ntp_circle(n): x = (n % 3 * 100 + 50 ) - 150 y = (n // 3 * 100 + 25 ) - 150 return x,y #ـــــــــــــــــــــــــــــــــ x,y cross def ntp_cross(n,xc,yc): x = ((n % 3 * 100 + 50 ) - 150) + xc y = ((n // 3 * 100 + 50 ) - 150) + yc return x,y #ـــــــــــــــــــــــــــــــــ replay def replay(x,y): global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey row = (y + 150) // 100 col = (x + 150) // 100 n = int(row * 3 + col) pencolor=gold if -250 <= y <= -170: if -245 <= x <= -95: again() elif -75 <= x <= 75: click.pencolor(crimson) click.goto(-75,-170) click.seth(0) click.pd() click.fillcolor(darkred) click.begin_fill() for j in range(4): click.fd(lw_rply[j%2]) click.rt(90) click.end_fill() click.pu() click.goto(0,-245) click.write('Exit',font=('Aviny',30),align='center') onscreenclick(None) sleeper(0.2) click.clear() onscreenclick(None) sleeper(0.3) mixer.music.stop() bye() exit() elif 95 <= x <= 245: menu() #ـــــــــــــــــــــــــــــــــ click to draw circle def ptn_circle(x,y): global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey tracer(False) if -150 <= x <= 150 and -150 <= y <= 150: row = (y + 150) // 100 col = (x + 150) // 100 n = int(row * 3 + col) pencolor=gold if 0<= n <= 8: if full[n]==0 and game_on == False and nobat=='player': draw_circle(n,gold) onscreenclick(None) tracer(True) full[n]=1 movep.append(n) winner() #ـــــــــــــــــــــــــــــــــ auto draw circle def auto_circle(n,clr): global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey onscreenclick(None) if level!='Hard' or typ=='human': if full[n]==1 and game_on == True: draw_circle(n,clr) elif level=='Hard' or typ=='human': if full[n]==2 and game_on == True: draw_circle(n,clr) #ـــــــــــــــــــــــــــــــــ auto draw cross def auto_cross(n,clr): global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey onscreenclick(None) if level!='Hard' or typ=='human': if full[n]==2 and game_on == True: draw_cross(n,clr) elif level=='Hard' or typ=='human': if full[n]==1 and game_on == True: draw_cross(n,clr) #ـــــــــــــــــــــــــــــــــ ai draw cross def ptn_cross(n): global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey if full[n]==0 and game_on == False: onscreenclick(None) sleeper(1) if nobat=='com': draw_cross(n,gold) tracer(True) elif level=='Hard' and fh == False: draw_cross(n,gold) tracer(True) draw_cross(n,gold) full[n]=2 movec.append(n) winner() if game_on == False: onscreenclick(your_turn) else: onscreenclick(replay) #ـــــــــــــــــــــــــــــــــ Hard level draw cross def hrd_cross(x,y): global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey tracer(False) if -150 <= x <= 150 and -150 <= y <= 150: row = (y + 150) // 100 col = (x + 150) // 100 n = int(row * 3 + col) pencolor=gold if 0<= n <= 8: if full[n]==0 and game_on == False and nobat=='player': draw_cross(n,gold) onscreenclick(None) tracer(True) full[n]=1 movep.append(n) winner() #ـــــــــــــــــــــــــــــــــ Hard level draw circle def hrd_circle(n): global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey if full.count(2)==full.count(1) or full.count(0)==9: if full[n]==0 and game_on == False: onscreenclick(None) sleeper(1) if level=='Hard' and fh == False: draw_circle(n,gold) tracer(True) elif nobat=='com': draw_circle(n,gold) tracer(True) full[n]=2 movec.append(n) winner() if game_on == False: onscreenclick(your_turn) else: onscreenclick(replay) #ـــــــــــــــــــــــــــــــــ draw circle def draw_circle(n,clr): global nobat global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey tracer(False) plyrt.goto(ntp_circle(n)) plyrt.pensize(10) plyrt.seth(0) plyrt.pd() plyrt.pencolor(clr) plyrt.circle(25) plyrt.pu() if level!='Hard': nobat='com' elif level=='Hard': nobat='player' #ـــــــــــــــــــــــــــــــــ draw cross def draw_cross(n,clr): global nobat global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey cxy=[-25,25] tracer(False) comt.pencolor(clr) comt.pensize(10) comt.pu() comt.goto(ntp_cross(n,cxy[0],cxy[1])) comt.pd() comt.goto(ntp_cross(n,cxy[1],cxy[0])) comt.pu() comt.goto(ntp_cross(n,cxy[1],cxy[1])) comt.pd() comt.goto(ntp_cross(n,cxy[0],cxy[0])) comt.pu() comt.seth(0) tracer(True) if level!='Hard': nobat='player' elif level=='Hard': nobat='com' #ـــــــــــــــــــــــــــــــــ draw table def draw_table(): onscreenclick(None) txy = [-150,-50,50,150] global table, lvl, rply, menudone, player1, player2 global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey tracer(False) tblt.seth(0) tblt.pencolor(teal) tblt.pensize(10) tblt.goto(-150,150) tblt.fillcolor(lightsalmon) tblt.pd() tblt.begin_fill() for m in range(4): tblt.fd(300) tblt.rt(90) tblt.end_fill() tblt.pu() for i in range(2): tblt.pu() tblt.goto(txy[i+1],txy[3]) tblt.pd() tblt.goto(txy[i+1],txy[0]) for j in range(2): tblt.pu() tblt.goto(txy[0],txy[2-j]) tblt.pd() tblt.goto(txy[3],txy[2-j]) tblt.pu() tracer(True) if level=='Hard': print_level() trnt.pu() trnt.goto(0,175) trnt.clear() trnt.pencolor(teal) trnt.write("It is the computer's turn!",font=('Aviny',30),align='center') first_hard() elif level=='Medium' or level=='Easy': print_level() start() onscreenclick(your_turn) else: player1=textinput(' First Player ',' Pleas enter your name : ') player2=textinput(' Socond Player ',' Pleas enter your name : ') if player1==None or player1=='': player1='O' if player2==None or player2=='': player2='X' trnt.pu() trnt.goto(0,175) trnt.clear() trnt.pencolor(teal) trnt.write("It is "+player1+"'s turn!",font=('Aviny',30),align='center') table = True lvl = False rply = False menudone = False #ـــــــــــــــــــــــــــــــــ your turn def your_turn(x,y): global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey row = (y + 150) // 100 col = (x + 150) // 100 n = int(row * 3 + col) if level!='Hard': if nobat=='player': ptn_circle(x,y) ai(n) elif nobat=='com': ai(n) elif level=='Hard': if nobat=='com': ai(n) elif nobat=='player': hrd_cross(x,y) ai(n) #ـــــــــــــــــــــــــــــــــ start def start(): global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey trnt.pu() trnt.goto(0,175) trnt.seth(0) trnt.pencolor(teal) trnt.write("Start!",font=('Aviny',30),align='center') #ـــــــــــــــــــــــــــــــــ turn def turn(): global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey tracer(False) trnt.pu() trnt.goto(0,175) if typ=='computer': if first=='player': if full.count(1)==full.count(2): trnt.clear() trnt.pencolor(teal) trnt.write("It is your turn!",font=('Aviny',30),align='center') elif full.count(1)>full.count(2): trnt.clear() trnt.pencolor(teal) trnt.write("It is the computer's turn!",font=('Aviny',30),align='center') elif first=='com': if full.count(1)==full.count(2): trnt.clear() trnt.pencolor(teal) trnt.write("It is the computer's turn!",font=('Aviny',30),align='center') elif full.count(1)<full.count(2): trnt.clear() trnt.pencolor(teal) trnt.write("It is your turn!",font=('Aviny',30),align='center') elif typ=='human': if full.count(1)==full.count(2): trnt.clear() trnt.pencolor(teal) trnt.write("It is "+player1+"'s turn!",font=('Aviny',30),align='center') elif full.count(1)>full.count(2): trnt.clear() trnt.pencolor(teal) trnt.write("It is "+player2+"'s turn!",font=('Aviny',30),align='center') tracer(True) #ـــــــــــــــــــــــــــــــــ make dd list def did(): global dd for i in range(9): for j in range(8): for u in range(3): if i in dooz[j]: dd[i].append(j) break #ـــــــــــــــــــــــــــــــــ human def human(x,y): global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey if full.count(1)==full.count(2): hmn_circle(x,y) elif full.count(1)>=full.count(2): hmn_cross(x,y) #ـــــــــــــــــــــــــــــــــ click to draw circle for human def hmn_circle(x,y): global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey tracer(False) row = (y + 150) // 100 col = (x + 150) // 100 n = int(row * 3 + col) pencolor=gold if 0<= n <= 8: if full[n]==0 and game_on == False: draw_circle(n,gold) tracer(True) full[n]=1 winner() #ـــــــــــــــــــــــــــــــــ click to draw cross for human def hmn_cross(x,y): global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey tracer(False) row = (y + 150) // 100 col = (x + 150) // 100 n = int(row * 3 + col) pencolor=gold if 0<= n <= 8: if full[n]==0 and game_on == False: draw_cross(n,gold) full[n]=2 tracer(True) winner() #ـــــــــــــــــــــــــــــــــ win circle def wl_circle(b,clr): global effectnumber,changeeffect global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey onscreenclick(None) if changeeffect != effectnumber: changeeffect = effectnumber if effectnumber == 1: for i in range(5): tracer(True) auto_circle(dooz[b][0],clr) auto_circle(dooz[b][1],clr) auto_circle(dooz[b][2],clr) sleeper(0.1) auto_circle(dooz[b][0],gold) auto_circle(dooz[b][1],gold) auto_circle(dooz[b][2],gold) sleeper(0.1) auto_circle(dooz[b][0],clr) auto_circle(dooz[b][1],clr) auto_circle(dooz[b][2],clr) tracer(True) elif effectnumber == 2: for i in range(3): auto_circle(dooz[b][0],clr) sleeper(0.1) auto_circle(dooz[b][0],gold) auto_circle(dooz[b][1],clr) sleeper(0.1) auto_circle(dooz[b][1],gold) auto_circle(dooz[b][2],clr) sleeper(0.1) auto_circle(dooz[b][2],gold) sleeper(0.2) auto_circle(dooz[b][2],clr) sleeper(0.1) auto_circle(dooz[b][2],gold) auto_circle(dooz[b][1],clr) sleeper(0.1) auto_circle(dooz[b][1],gold) auto_circle(dooz[b][0],clr) sleeper(0.1) auto_circle(dooz[b][0],gold) sleeper(0.2) auto_circle(dooz[b][0],clr) sleeper(0.1) auto_circle(dooz[b][1],clr) sleeper(0.1) auto_circle(dooz[b][2],clr) elif effectnumber == 3: for i in range(5): auto_circle(dooz[b][0],clr) sleeper(0.1) auto_circle(dooz[b][1],clr) sleeper(0.1) auto_circle(dooz[b][2],clr) sleeper(0.2) auto_circle(dooz[b][0],gold) sleeper(0.1) auto_circle(dooz[b][1],gold) sleeper(0.1) auto_circle(dooz[b][2],gold) sleeper(0.1) auto_circle(dooz[b][0],clr) sleeper(0.1) auto_circle(dooz[b][1],clr) sleeper(0.1) auto_circle(dooz[b][2],clr) elif effectnumber == 4: for i in range(5): auto_circle(dooz[b][0],clr) sleeper(0.15) auto_circle(dooz[b][0],gold) sleeper(0.15) auto_circle(dooz[b][0],clr) sleeper(0.15) auto_circle(dooz[b][1],clr) sleeper(0.15) auto_circle(dooz[b][1],gold) sleeper(0.15) auto_circle(dooz[b][0],gold) sleeper(0.15) auto_circle(dooz[b][0],clr) sleeper(0.15) auto_circle(dooz[b][1],clr) sleeper(0.15) auto_circle(dooz[b][2],clr) sleeper(0.15) if i != 4: auto_circle(dooz[b][2],gold) sleeper(0.15) auto_circle(dooz[b][1],gold) sleeper(0.15) auto_circle(dooz[b][0],gold) sleeper(0.15) #ـــــــــــــــــــــــــــــــــ win cross def wl_cross(b,clr): global effectnumber, changeeffect global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey onscreenclick(None) if changeeffect != effectnumber: changeeffect = effectnumber if effectnumber == 1: for i in range(5): tracer(True) auto_cross(dooz[b][0],clr) auto_cross(dooz[b][1],clr) auto_cross(dooz[b][2],clr) sleeper(0.1) auto_cross(dooz[b][0],gold) auto_cross(dooz[b][1],gold) auto_cross(dooz[b][2],gold) sleeper(0.1) auto_cross(dooz[b][0],clr) auto_cross(dooz[b][1],clr) auto_cross(dooz[b][2],clr) tracer(True) if effectnumber == 2: for i in range(2): auto_cross(dooz[b][0],clr) sleeper(0.1) auto_cross(dooz[b][0],gold) auto_cross(dooz[b][1],clr) sleeper(0.1) auto_cross(dooz[b][1],gold) auto_cross(dooz[b][2],clr) sleeper(0.1) auto_cross(dooz[b][2],gold) sleeper(0.2) auto_cross(dooz[b][2],clr) sleeper(0.1) auto_cross(dooz[b][2],gold) auto_cross(dooz[b][1],clr) sleeper(0.1) auto_cross(dooz[b][1],gold) auto_cross(dooz[b][0],clr) sleeper(0.1) auto_cross(dooz[b][0],gold) sleeper(0.2) auto_cross(dooz[b][0],clr) sleeper(0.1) auto_cross(dooz[b][1],clr) sleeper(0.1) auto_cross(dooz[b][2],clr) elif effectnumber == 3: for i in range(3): auto_cross(dooz[b][0],clr) sleeper(0.1) auto_cross(dooz[b][1],clr) sleeper(0.1) auto_cross(dooz[b][2],clr) sleeper(0.1) auto_cross(dooz[b][0],gold) sleeper(0.1) auto_cross(dooz[b][1],gold) sleeper(0.1) auto_cross(dooz[b][2],gold) sleeper(0.1) auto_cross(dooz[b][0],clr) sleeper(0.1) auto_cross(dooz[b][1],clr) sleeper(0.1) auto_cross(dooz[b][2],clr) elif effectnumber == 4: for i in range(5): auto_cross(dooz[b][0],clr) sleeper(0.15) auto_cross(dooz[b][0],gold) sleeper(0.15) auto_cross(dooz[b][0],clr) sleeper(0.15) auto_cross(dooz[b][1],clr) sleeper(0.15) auto_cross(dooz[b][1],gold) sleeper(0.15) auto_cross(dooz[b][0],gold) sleeper(0.15) auto_cross(dooz[b][0],clr) sleeper(0.15) auto_cross(dooz[b][1],clr) sleeper(0.15) auto_cross(dooz[b][2],clr) sleeper(0.15) if i != 4: auto_cross(dooz[b][2],gold) sleeper(0.15) auto_cross(dooz[b][1],gold) sleeper(0.15) auto_cross(dooz[b][0],gold) sleeper(0.15) #ـــــــــــــــــــــــــــــــــ winner def winner(): global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey global game_on for b in range(8): if game_on == False: if full[dooz[b][0]]==1 and full[dooz[b][1]]==1 and full[dooz[b][2]]==1: if typ=='computer': win='You win!' clr=lime bgc=palegreen elif typ=='human': win=player1+' won!' clr=lime bgc=palegreen game_on = True trnt.clear() levelname.clear() sleeper(0.5) bgcolor(bgc) wrtt.pencolor('black') wrtt.goto(-3,162) wrtt.write(win,font=('Aviny',60),align='center') wrtt.pencolor(clr) wrtt.goto(0,165) wrtt.write(win,font=('Aviny',60),align='center') if typ=='computer': if level!='Hard': wl_circle(b,lime) elif level=='Hard': wl_cross(b,lime) elif typ=='human': wl_circle(b,lime) onscreenclick(None) break if full[dooz[b][0]]==2 and full[dooz[b][1]]==2 and full[dooz[b][2]]==2: if typ=='computer': lose='You lose!' clr=crimson bgc=lightcoral elif typ=='human': lose=player2+' won!' clr=lime bgc=palegreen game_on = True trnt.clear() levelname.clear() sleeper(0.5) bgcolor(bgc) wrtt.pencolor('black') wrtt.goto(-3,162) wrtt.write(lose,font=('Aviny',60),align='center') wrtt.pencolor(clr) wrtt.goto(0,165) wrtt.write(lose,font=('Aviny',60),align='center') if typ=='computer': if level!='Hard': wl_cross(b,crimson) if level=='Hard': wl_circle(b,crimson) elif typ=='human': wl_cross(b,lime) onscreenclick(None) break if game_on == False: if full.count(0)==0: game_on = True sleeper(0.5) pencolor(teal) trnt.clear() levelname.clear() bgcolor(silver) wrtt.pencolor('black') wrtt.goto(-3,162) wrtt.write('Draw!',font=('Aviny',60),align='center') wrtt.pencolor(dimgrey) wrtt.goto(0,165) wrtt.write('Draw!',font=('Aviny',60),align='center') else: turn() if game_on == True: sleeper(0.5) replay_btn() game_on=3 #ـــــــــــــــــــــــــــــــــ replay buttons def replay_btn(): global rply, table, lvl, lw_rply, xx, wr global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey tracer(False) lw_rply=[150,80] xx=[-245,-75,95] fcl=[lightsalmon,darkred,lightsalmon] wr=['Again','Exit','Menu'] rplyt.pencolor(teal) rplyt.pensize(5) levelname.clear() for i in range(3): rplyt.goto(xx[i],-170) rplyt.seth(0) rplyt.pd() rplyt.fillcolor(fcl[i]) rplyt.begin_fill() for j in range(4): rplyt.fd(lw_rply[j%2]) rplyt.rt(90) rplyt.end_fill() rplyt.pu() rplyt.goto(xx[i]+75,-245) rplyt.write(wr[i],font=('Aviny',30),align='center') onscreenclick(replay) table = False lvl = False rply = True #ـــــــــــــــــــــــــــــــــ again def again(): global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey onscreenclick(None) global full, game_on, wr, fh, rnhl, first, nobat, lc, rncm, movec, movep, z, lvl, rply, table, lw_rply, xx click.pencolor(lawngreen) click.goto(-245,-170) click.seth(0) click.pd() click.fillcolor(lightsalmon) click.begin_fill() for j in range(4): click.fd(lw_rply[j%2]) click.rt(90) click.end_fill() click.pu() click.goto(-170,-245) click.write('Again',font=('Aviny',30),align='center') sleeper(0.2) click.clear() sleeper(0.3) clear() levelname.clear() rplyt.clear() lvlt.clear() plyrt.clear() comt.clear() trnt.clear() tblt.clear() wrtt.clear() hidt.clear() bgcolor(lightyellow) rplyt.pu() lvlt.pu() plyrt.pu() comt.pu() tblt.pu() wrtt.pu() hidt.pu() pu() speed(0) del full full = [0]*9 game_on = False movep.clear() movec.clear() fh = False rnhl=-1 lc = True nobat = False rncm = False table = False lvl = False rply = False if level=='Hard': if len(movec)==0: first='com' nobat='com' draw_table() first_hard() elif level=='Medium' or level=='Easy': first='player' nobat='player' draw_table() onscreenclick(your_turn) else: draw_table() onscreenclick(human) #ـــــــــــــــــــــــــــــــــ menu def menu(): global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey onscreenclick(None) global full, game_on, fh, rnhl, first, nobat, lc, movec, movep, rncm, level, lvl, rply, table, typ, menudone, lw_rply click.pencolor(lawngreen) click.goto(95,-170) click.seth(0) click.pd() click.fillcolor(lightsalmon) click.begin_fill() for j in range(4): click.fd(lw_rply[j%2]) click.rt(90) click.end_fill() click.pu() click.goto(170,-245) click.write('Menu',font=('Aviny',30),align='center') sleeper(0.2) click.clear() sleeper(0.3) clear() levelname.clear() rplyt.clear() lvlt.clear() plyrt.clear() comt.clear() tblt.clear() wrtt.clear() hidt.clear() trnt.clear() bgcolor(lightyellow) rplyt.pu() lvlt.pu() plyrt.pu() comt.pu() tblt.pu() wrtt.pu() hidt.pu() pu() del full full = [0]*9 game_on = False movep.clear() movec.clear() fh = False rnhl=-1 first = False lc = False table = False lvl = False rply = False typ = False rncm = False level = False nobat = False menudone = False first_menu() #ـــــــــــــــــــــــــــــــــ first move in hard level def first_hard(): global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey global fh, rncm if game_on == False and level=='Hard' and fh == False: did() cm=[4,'cor',4,'cen','cor',4,'cor','cen',4,'cor',4] rn=choice(cm) if rn==4: hrd_circle(4) elif rn=='cor': lst=[0,2,6,8] rncm=choice(lst) hrd_circle(rncm) elif rn=='cen': lst=[1,3,5,7] rncm=choice(lst) hrd_circle(rncm) del rn fh = True onscreenclick(your_turn) #ـــــــــــــــــــــــــــــــــ ai def ai(n): global lightyellowcolor, lightyellow, tealcolor, teal, lightsalmoncolor, lightsalmon, palegreencolor, palegreen, lightcoralcolor, lightcoral, lawngreencolor, lawngreen, crimsoncolor, crimson, darkredcolor, darkred, goldcolor, gold, limecolor, lime, silvercolor, silver, dimgreycolor, dimgrey global dd, rnhl, rncm if full.count(0)!=0 and game_on == False and nobat=='com': may_win = False may_lose = False #General #the computer may Win for i in range(8): if full[dooz[i][0]]==2 and full[dooz[i][1]]==2 and full[dooz[i][2]]==0: if level!='Hard': ptn_cross(dooz[i][2]) may_win == True hrd_random = True med_random = True elif level=='Hard': hrd_circle(dooz[i][2]) may_win == True hrd_random = True med_random = True break elif full[dooz[i][0]]==2 and full[dooz[i][2]]==2 and full[dooz[i][1]]==0: if level!='Hard': ptn_cross(dooz[i][1]) may_win == True hrd_random = True med_random = True elif level=='Hard': hrd_circle(dooz[i][1]) may_win == True hrd_random = True med_random = True break elif full[dooz[i][1]]==2 and full[dooz[i][2]]==2 and full[dooz[i][0]]==0: if level!='Hard': ptn_cross(dooz[i][0]) may_win == True hrd_random = True med_random = True elif level=='Hard': hrd_circle(dooz[i][0]) may_win == True hrd_random = True med_random = True break #the computer may Lose if may_win == False: for j in range(8): if full[dooz[j][0]]==1 and full[dooz[j][1]]==1 and full[dooz[j][2]]==0: if level!='Hard': ptn_cross(dooz[j][2]) may_lose = True hrd_random = True med_random = True elif level=='Hard': hrd_circle(dooz[j][2]) may_lose = True hrd_random = True med_random = True break if full[dooz[j][0]]==1 and full[dooz[j][2]]==1 and full[dooz[j][1]]==0: if level!='Hard': ptn_cross(dooz[j][1]) may_lose = True hrd_random = True med_random = True elif level=='Hard': hrd_circle(dooz[j][1]) may_lose = True hrd_random = True med_random = True break if full[dooz[j][1]]==1 and full[dooz[j][2]]==1 and full[dooz[j][0]]==0: if level!='Hard': ptn_cross(dooz[j][0]) may_lose = True hrd_random = True med_random = True elif level=='Hard': hrd_circle(dooz[j][0]) may_lose = True hrd_random = True med_random = True break #Specialty #Random: for Easy level if may_lose == False and level=='Easy': empty=[] for i in range(9): if full[i]==0: empty.append(i) rn=choice(empty) ptn_cross(rn) #Defense: for Medium level def_is_do = False corner=[0,2,6,8] center=[1,3,5,7] ntc=[[1,3],[0,2],[1,5],[0,6],[4],[2,8],[3,7],[6,8],[5,7]] if may_lose == False and level=='Medium': med_random = False if n!=4: if full[4]==0: ptn_cross(4) med_random = True else: if n in corner: if full[4]==1: for i in range(4): rn=corner[i] if full[rn]==0: ptn_cross(rn) def_is_do = True med_random = True break for i in range(4): if def_is_do == True: break elif movep[-2]==center[i]: for j in range(2): rn=ntc[center[i]][j] if full[rn]==0: ptn_cross(rn) def_is_do = True med_random = True break for i in range(4): if def_is_do == True: break elif movep[-2]==corner[i]: for j in range(2): rn=ntc[corner[i]][j] if full[rn]==0: ptn_cross(rn) def_is_do = True med_random = True break for i in range(4): if def_is_do == False: rn=corner[i] if full[rn]==0: ptn_cross(rn) def_is_do = True med_random = True break else: if full[4]==1: for i in range(4): rn=corner[i] if full[rn]==0: ptn_cross(rn) med_random = True break else: for i in range(4): rn=choice(ntc[n]) if full[rn]==0: ptn_cross(rn) med_random = True break else: empty=[] for i in corner: if full[i]==0: empty.append(i) if len(empty)>=1: rn=choice(empty) ptn_cross(rn) med_random = True if med_random == False: empty=[] for i in range(9): if full[i]==0: empty.append(i) rn=choice(empty) ptn_cross(rn) med_random = True #Attack: for Hard level ftc=[8,7,6,5,4,3,2,1,0] ftcor=[[5,7,8],[3,6,7],[1,2,5],[0,1,3]] ftcen=[[3,5,6,8],[1,2,7,8],[0,1,6,7],[0,2,3,5]] cen=[[0,3,6,2,5,8],[0,1,2,6,7,8],[0,1,2,6,7,8],[0,3,6,2,5,8]] ntc=[[1,3],[0,2],[1,5],[0,6],[4],[2,8],[3,7],[6,8],[5,7]] end=0 hrd_random = False z=0 if may_lose == False and level=='Hard' and fh == True and game_on == False: if len(movec)==1: if movec[-1]==4: if n in corner: hrd_circle(ftc[n]) hrd_random = True elif n in center: rn=choice(cen[center.index(n)]) hrd_circle(rn) hrd_random = True else: if n==4: if movec[-1] in corner: rn=choice(ftcor[corner.index(movec[-1])]) hrd_circle(rn) hrd_random = True else: rn=choice(ftcen[center.index(movec[-1])]) hrd_circle(rn) hrd_random = True else: if movec[-1] in corner: if n in corner: if n!=ftc[movec[-1]]: hrd_circle(ftc[movec[-1]]) hrd_random = True else: cor_empty=[] for i in corner: if full[i]==0: cor_empty.append(i) rn=choice(cor_empty) hrd_circle(rn) hrd_random = True elif n in center: for i in corner: if i!=ftc[movec[-1]]: if i not in ntc[n]: if full[i]==0: hrd_circle(i) hrd_random = True elif movec[-1] in center: if n in corner: if n in ntc[movec[-1]]: for i in ntc[n]: if full[i]==0: hrd_circle(i) hrd_random = True break else: for i in ntc[movec[-1]]: if i!=ftc[movec[-1]]: hrd_circle(i) hrd_random = True elif n in center: if n!=ftc[movec[-1]]: hrd_circle(4) hrd_random = True else: hrd_circle(4) hrd_random = True else: em=[] dl1=[] dl2=[] appro=[] for i in dd[movec[-1]]: if full[dooz[i][0]]!=1 and full[dooz[i][1]]!=1 and full[dooz[i][2]]!=1: dl1.append(i) for x in dd[movec[-2]]: if full[dooz[x][0]]!=1 and full[dooz[x][1]]!=1 and full[dooz[x][2]]!=1: dl2.append(x) for i in dl1: for j in dooz[i]: for x in dl2: for y in dooz[x]: if j==y and i!=x: appro.append(j) if len(appro)!=0: appro=list(set(appro)) rn=choice(appro) hrd_circle(rn) hrd_random = True if hrd_random == False: empty=[] for i in range(9): if full[i]==0: empty.append(i) rn=choice(empty) hrd_circle(rn) hrd_random = True game() done()[/dm_code_snippet]
نقد و بررسیها
هیچ دیدگاهی برای این محصول نوشته نشده است.