# -*- coding: utf-8 -* #ideas """ щелкаем на букве - тогда появляется слагаемое из пары переключатель места в сумме букву тянем к цифре- вытесняет и заменяет предыдущую, и себя тоже!!! и ходов -10 или меньше выигрыш IQ 5-повезло!!! 6- прекрасно 7 - отлично 8 хорошо 9 неплохо 10 можно лучше 11 много лишних ходов, мало ходов уме """ import turtle import random import datetime current_time = datetime.datetime.now() print(str(current_time.date())+'_'+str(current_time.microsecond)) class Myturtle(turtle.Turtle): """class for math game DECODE ADDITION! Numbers 0-9 a+b=c""" switchto=0 switchto1=0 hody=0 hodall=0 hodyall=[] def moveto(self,x,y): """ form the line of decoding 0-9 digits """ self.down() self.up() self.x1=int((self.xcor()+300)//60) self.x=int((x+300)//60) self.color('yellow') self.goto(x-x%60+15,95) self.stamp() self.goto(x-x%60+15,110) self.stamp() self.goto(x-x%60+15,80) self.stamp() self.goto(x-x%60+15,80) self.color('blue') self.write(str(self.r),align="center",font=("Arial",30,"normal")) self.color('yellow') self.goto(-300+self.r*60+15,205) self.up() def check_rez(self,x,y): # check rezult of picked numbers! lastic.ht() lastic.up() lastic.shape('square') lastic.shapesize(3,20,3) lastic.color('white') lastic.goto(-40,259) lastic.stamp() lastic.ht() xxbn=[0]*10 for i in range(10): xxbn[i]=b[i].x # print(*xxbn,' -vibor2') xxbn1=[0]*10 for i in range(10): xxbn1[i]=b[i].x1 # print(*xxbn1,' -vibor1') xx=[0]*10 for i,j in enumerate(xxbn): xx[j]=i # print(*xx,' -vibor0') krez=0 self.x=self.xcor() self.y=self.ycor() for i in range(10): if not(rmix[i]==xx[i]): krez=1 if krez==1: self.ht() self.goto(0,240) self.write('BCE HE TAK !!!',align="center",font=("Arial",30,"normal")) self.goto(-30,-230) self.st() else: lastic.st() lastic.stamp() lastic.ht() self.goto(-66,240) self.ht() self.write('ypa !!!'+ ' ХОДОВ: '+str(Myturtle.hody),align="center",font=("Arial",30,"normal")) Myturtle.hodall+=1 Myturtle.hodyall.append(Myturtle.hody) ini1.ht() ini1.goto(335, -Myturtle.hodall*50+350) ini1.color('blue') ini1.write(str(len(Myturtle.hodyall))+' : '+str(Myturtle.hody),align="center",font=("Arial",22,"normal")) ini1.ht() self.goto(self.x,self.y) self.st() def redsquare(self,x,y): # print first part of sum only for i in range(10): a[i].color('red','yellow') self.up() lastic.shape('square') lastic.shapesize(3,25,3) lastic.color('yellow') lastic.goto(40-60,-117) lastic.st() lastic.stamp() self.x=int((x+300)//60) self.x1=self.xcor() self.y1=self.ycor() self.goto(0-60,-140) self.write(nmix[self.x],align="center",font=("Arial",40,"normal")) self.goto(self.x1,self.y1) self.color('black') Myturtle.switchto=self.x def cyansquare(self,x,y): # print second part and sum Myturtle.hody+=1 for i in range(10): d[i].color('cyan','yellow') self.up() self.color('black') lastic.shape('square') lastic.shapesize(3,23,3) lastic.color('white') lastic.goto(-60,-117) lastic.st() lastic.stamp() self.x=int((x+300)//60) self.x1=self.xcor() self.y1=self.ycor() self.goto(40-200,-140) self.color('red','yellow') self.write(nmix[Myturtle.switchto],align="center",font=("Arial",40,"normal")) umnozi.goto(40-160,-135) umnozi.write('+',align="center",font=("Arial",40,"normal")) self.goto(40-120,-140) self.color('cyan','yellow') self.write(nmix[self.x],align="center",font=("Arial",40,"normal")) #---------- dubble !!!!!!!! -------------------------------------------- if Myturtle.hody>-1: self.goto(-435, -Myturtle.hody*25+350) self.color('black') self.write(str(Myturtle.hody)+': '+nmix[Myturtle.switchto],align="center",font=("Arial",12,"normal")) f.write(str(Myturtle.hody)+': '+nmix[Myturtle.switchto]) umnozi.goto(-399-10, -Myturtle.hody*25+350) umnozi.write('+',align="center",font=("Arial",12,"normal")) f.write('+') self.goto(-399, -Myturtle.hody*25+350) self.color('black') self.write(nmix[self.x],align="center",font=("Arial",12,"normal")) f.write(nmix[self.x]) #---------- dubble !!!!!!!! -------------------------------------------- self.product12=rmix[self.x]+rmix[Myturtle.switchto] self.color('black') slozi.goto(40-60,-135) slozi.write('=',align="center",font=("Arial",40,"normal")) # ---------------------0000000000000-------------------------------------- if Myturtle.hody>-1: self.color('black') slozi.goto(-399+14, -Myturtle.hody*25+350) slozi.write('=',align="center",font=("Arial",12,"normal")) f.write('=') #-----------------------0000000000000------------------------------------- lastic.shapesize(3,13) lastic.color('white') lastic.goto(226,-282) lastic.stamp() # slozi.goto(220,-270) # slozi.write('ХОДОВ: '+str(Myturtle.hody),align="center",font=("Arial",30,"normal")) lastic.ht() sum1=int(str(self.product12).zfill(2)[0]) sum2=int(str(self.product12).zfill(2)[1]) for i in range(10): if sum1==rmix[i]: ssum1=nmix[i] sum1=ssum1 for i in range(10): if sum2==rmix[i]: ssum1=nmix[i] sum2=ssum1 first_part_of_sum.goto(80-60,-140) first_part_of_sum.st() lastic.goto(130,-155) lastic.st() lastic.stamp() first_part_of_sum.write(sum1,align="center",font=("Arial",40,"normal")) first_part_of_sum.ht() second_part_of_sum.goto(130-60,-140) second_part_of_sum.st() second_part_of_sum.write(sum2,align="center",font=("Arial",40,"normal")) second_part_of_sum.ht() self.goto(self.x1,self.y1) #-------------------------------------11111------------------------------------ if Myturtle.hody>-1: first_part_of_sum.goto(-399+30, -Myturtle.hody*25+350) first_part_of_sum.st() first_part_of_sum.write(sum1,align="center",font=("Arial",12,"normal")) f.write(sum1) first_part_of_sum.ht() second_part_of_sum.goto(-399+50, -Myturtle.hody*25+350) second_part_of_sum.st() second_part_of_sum.write(sum2,align="center",font=("Arial",12,"normal")) f.write(sum2) second_part_of_sum.ht() #-------------------------------------111111------------------------------------ lastic.ht() self.goto(self.x1,self.y1) Myturtle.switchto1=self.x def iniall(x,y): # INITIALISE ALL global tt,f global nmix,rmix,a,b,c,d,xbn,lastic,umnozi,slozi,first_part_of_sum,second_part_of_sum,br if tt!=0: f.write(str(rmix)) f.write(str(nmix)) f.close() current_time = datetime.datetime.now() # print(str(current_time.date())+'_'+str(current_time.microsecond)) filname="game_pl"+str(current_time.date())+'_'+str(current_time.microsecond)+'.txt' f=open(filname, 'w', encoding='utf-8') f.write('Привет, победитель!') tt=1 Myturtle.hody=0 strnmix='ЦЛЮШПЯБГЖФ' nmix=list(strnmix) # random.shuffle(nmix) # print(*nmix,'mix letters') rmix=list(range(10)) pmix=list(range(10)) random.shuffle(rmix) # print(*rmix,'mix digits') a=[None]*10 b=[None]*10 c=[None]*10 d=[None]*10 xbn=[None]*10 # выбранные значения перемешанных букв lastic=turtle.Turtle() lastic.speed(0) lastic.up() lastic.shape('square') lastic.shapesize(30,69,3) lastic.color('white') lastic.goto(-200,40) lastic.st() lastic.stamp() lastic.goto(-200,180) lastic.st() lastic.stamp() lastic.ht() ini1.goto(-80,320) ini1.write(" Зашифрованное сложение",align="center",font=("Arial",24,"normal")) #-------------init record's table --------------- ini1.ht() ini1.goto(335,380) ini1.color('red') print(Myturtle.hodall,Myturtle.hodyall,Myturtle.hody) if Myturtle.hodall!=0: for i in range(len(Myturtle.hodyall)): ini1.goto(335, -i*50+310) ini1.write(str(i+1)+' : '+str(Myturtle.hodyall[i]),align="center",font=("Arial",22,"normal")) ini1.ht() umnozi=turtle.Turtle() umnozi.speed(0) umnozi.ht() umnozi.up() slozi=turtle.Turtle() slozi.speed(0) slozi.ht() slozi.up() first_part_of_sum=turtle.Turtle() first_part_of_sum.ht() first_part_of_sum.speed(0) first_part_of_sum.up() second_part_of_sum=turtle.Turtle() second_part_of_sum.ht() second_part_of_sum.speed(0) second_part_of_sum.up() # CREATE ALL THE PICTURE !!!! for r in range(10): # # красные квадратики для букв и буквы a[r]=Myturtle() a[r].ht() a[r].r=r a[r].speed(0) a[r].shape('square') a[r].shapesize(1,2,1) a[r].color('red','yellow') a[r].up() a[r].goto(-300+r*60,0) a[r].st() a[r].write(nmix[r],font=("Arial",30,"normal")) a[r].ht() a[r].goto(-300+r*60+15,-25) a[r].st() a[r].onclick(a[r].redsquare) # синие квадратики для букв d[r]=Myturtle() d[r].ht() d[r].r=r d[r].speed(0) d[r].shape('square') d[r].shapesize(1,2,1) d[r].up() d[r].goto(-320,-47) d[r].color('black') d[r].write('+',font=("Arial",14,"normal")) d[r].color('cyan','yellow') d[r].goto(-300+r*60+15,-50) d[r].st() d[r].onclick(d[r].cyansquare) # синие кружки для цифр и цифры b[r]=Myturtle() b[r].ht() b[r].r=r b[r].x=0 b[r].x1=0 b[r].speed(0) b[r].shape('circle') b[r].shapesize(1,2,1) b[r].color('blue') b[r].up() b[r].goto(-300+r*60,155) b[r].st() b[r].write(pmix[r],font=("Arial",30,"normal")) b[r].ht() b[r].goto(-300+r*60+15,205) b[r].st() b[r].onrelease(b[r].moveto) # синие пустые кружки для цифр c[r]=Myturtle() c[r].ht() c[r].speed(0) c[r].shape('circle') c[r].shapesize(1,2,1) c[r].color('blue','white') c[r].up() c[r].st() c[r].goto(-300+r*60+15,80) br=Myturtle() br.hodall=0 br.speed(0) br.up() br.ht() br.shape('square') br.shapesize(1,12) br.color('black') br.goto(-30,-230) br.st() br.write('ПРОВЕРКА',align='center',font=("Arial",30,"normal")) br.onclick(br.check_rez) # Initial position on red line # Initial position on cyan line a[0].goto(-300+0*60+15,-25) a[0].r=0 a[0].redsquare(-300+0*60+15,-25) d[0].goto(-300+0*60+15,-50) d[0].r=0 d[0].cyansquare(-300+0*60+15,-50) d[0].color('black') d[0].goto(-300+0*60+15,-50) d[0].st() """ ========================MAIN LOOP========================= """ tt=0 turtle.tracer(3,0) ini1=Myturtle() ini1.up() ini1.ht() ini1.goto(-60,0) ini1.write("The idea of the game belongs to Key Curricullum, see Geometer's SketchPad (about 2008)",align="center",font=("Arial",10,"normal")) ini1.goto(-60,180) ini1.write('Ваша задача - расшифровать ЦИФРЫ,закодированные БУКВАМИ! 0 + 5 = 0 5',align="center",font=("Arial",18,"normal")) ini1.goto(-60,150) ini1.write('Складывать цифро-буквы вам помогут красные и голубые клеточки',align="center",font=("Arial",18,"normal")) ini1.goto(-60,120) ini1.write('Но ответ сложения, увы, тоже закодирован! Но зато - ТЕМ ЖЕ кодом! Ц+Ю = ЦЮ',align="center",font=("Arial",18,"normal")) ini1.goto(-60,90) ini1.write('Тут-то и пригодится знание арифметики и смекалка.',align="center",font=("Arial",18,"normal")) ini1.goto(-60,60) ini1.write('Отмечайте найденные цифры голубыми нумерованными овалами!',align="center",font=("Arial",18,"normal")) ini=turtle.Turtle() ini.up() ini.color('red') ini.shape('square') ini.shapesize(3,15) ini.ht() ini.goto(-30,-300) ini.write('NEW GAME !',align="center",font=("Arial",30,"normal")) ini.goto(-30,-330) ini.st() ini1.goto(-80,280) ini1.write("Зашифрованное сложение",align="center",font=("Arial",24,"normal")) ini1.ht() ini.onclick(iniall) turtle.mainloop()