frommathimport*fromrandomimport*fromkandinskyimport*fromionimport*fromtimeimport*globalwhwh=color(255,255,255)definit():fill_rect(0,0,320,240,'black')globalikicks,bsys,dropspeed,kickdata,scoresys,scoretitles,keys,whiteline,tetraminos,matrix,colors,levelsyscolors=[(0,255,255),(255,255,0),(200,0,255),(255,150,0),(0,0,255),(255,0,0),(0,255,0)]tetraminos=[[[2,3,3,3,3],[0,0,1,2,0,0,1,2,0,0,1,2,0,0,3],[2,2,3,3,3,3],[0,1,2,0,1,2,0,1,2,0,3],0],[[0,1,1,2,0,3,3],1],[[0,1,2,3,3,3],[0,1,2,0,1,3,2,0,3],[2,3,1,3,2,0,3],[0,1,2,3,1,2,0,3],2],[[0,0,1,2,3,3,3],[0,1,2,0,1,2,0,3,3],[2,1,3,3,2,3],[3,1,2,0,1,2,0,3],3],[[1,2,3,3,3],[0,1,3,2,0,1,2,0,3],[2,3,3,1,2,0,0,3],[0,1,2,0,1,2,3,3],4],[[3,1,2,0,3,3],[0,0,1,2,0,1,3,2,0,3],[2,3,1,2,0,3,3],[0,1,2,1,3,2,3],5],[[0,1,3,2,3,3],[0,1,2,0,3,1,2,0,0,3],[2,0,1,3,2,3,3],[1,2,3,1,2,0,3],6]]kickdata=[[(-1,0),(-1,-1),(0,2),(-1,2)],[(1,0),(1,1),(0,-2),(1,-2)],[(1,0),(1,-1),(0,2),(1,2)],[(-1,0),(-1,1),(0,-2),(-1,-2)],[(-2,0),(1,0),(-2,1),(1,-2)],[(2,0),(-1,0),(2,-1),(-1,2)],[(-1,0),(2,0),(-1,-2),(2,1)],[(1,0),(-2,0),(1,2),(-2,-1)]]ikicks=[[0,5,0,7],[4,0,7,0],[0,6,0,4],[6,0,5,0]]scoresys=[[0,100,300,500,800],[100,400,1200,1600],[0,1200,1800,2400,1200],[100,200,400,1200],[0,0,600,2400]]levelsys=[0,1,3,5,8]bsys=[[0,0,0,0,1],[1,1,1,1],[1,1,1,1,1],[0,0,1,1],[0,0,1,1]]scoretitles=[["","Single","Double","Triple","Tetris"],["M T-S","T-S S","T-S D","T-S T"],["","T-S B","T-S D B","T-S T B","Tetris B"],["M T-S","M T-S S","M T-S D","T-S T"],["","","T-S M D B","T-S T B"]]bt=(120,120,120)fill_rect(110,0,100,230,wh)forysinrange(0,230,10):square(100,ys,bt)square(210,ys,bt)forxsinrange(110,210,10):square(xs,220,bt)fill_rect(110,19,100,1,(255,0,0))forysinrange(40,190,10):forxsinrange(240,300,10):square(xs,ys,bt)forysinrange(80,140,10):forxsinrange(240,300,10):square(xs-220,ys-40,bt)fill_rect(250,50,40,130,'black')fill_rect(30,50,40,40,'black')ifmode%3!=1:draw_string("Score :",15,110,wh,'black')draw_string("0000000",15,130,wh,'black')else:draw_string("Lines :",15,110,wh,'black')draw_string("00/40",15,130,wh,'black')ifmode%3==0:draw_string("Level :",15,160,wh,'black')draw_string("01",65,180,wh,'black')else:draw_string("Time :",15,160,wh,'black')draw_string("00:00.00",15,180,wh,'black')fortminrange(3):draw_string(str(3-tm),155,110)sleep(1)draw_string("",155,110)game()defgame():x,y,px,py=140,20,150,10t=randrange(0,7)wait=-1rot=0poutline=[400,0]plowest=500next=[[0,0,0,0,0,0,0,0],[-1,0,0,0,0,0,0,0],[-1]]next[0]=randombag()next=nextt(next)hold,holdtemp,holdallowed=-1,0,Truemov_allowed=[True,True]score,combo=0,0level=1ifmode==0elsespeedxp=0btob=0end=Falsemono=monotonic()mt=monotonic()coolr=0lines=0coolh=monotonic()whileend==False:px,py,prot=x,y,rotmove=[0,0,0,0]ifkeydown(KEY_EXE):whilekeydown(KEY_EXE):passwhilenotkeydown(KEY_EXE):draw_string("Paused",240,205,wh,'black')draw_string("7-Restart",5,5,wh,'black')draw_string("Menu-9",240,5,wh,'black')ifkeydown(KEY_SEVEN):init()ifkeydown(KEY_NINE):menu(mode,speed)draw_string("",240,205,wh,'black')draw_string("",5,5,wh,'black')draw_string("",240,5,wh,'black')whilekeydown(KEY_EXE):passfortminrange(3):draw_string(str(3-tm),10,200,wh,'black')sleep(1)draw_string("",10,200,wh,'black')if (mt+(0.8-(level-1)*0.007)**(level-1)<=monotonic()andnotkeydown(KEY_DOWN))or(mt+0.03<=monotonic()andkeydown(KEY_DOWN)):y+=10mt=monotonic()move[1]=1ifkeydown(KEY_BACKSPACE)andholdallowed:ifhold==-1:hold=next[0][0]next=nextt(next)refresh(t,px,py,prot)refresh(t,px,plowest,prot)holdtemp=holdhold=tfill_rect(30,50,40,40,'black')tetra(30,60,hold,0)t=holdtempholdallowed=Falsex,y,rot,px,py,prot,plowest=140,10,0,140,10,0,500ifkeydown(KEY_LEFT)andcoolh<=monotonic():x-=10coolh=monotonic()+0.13move[0]=1ifnot(keydown(KEY_RIGHT)orkeydown(KEY_LEFT)):coolh=monotonic()ifkeydown(KEY_RIGHT)andcoolh<=monotonic():x+=10coolh=monotonic()+0.13move[0]=1ifkeydown(KEY_UP):move[3]=1y=plowestwait=monotonic()ifkeydown(KEY_5):coolr+=1else:coolr=0ifcoolr==1:rot=(rot+(1-2*int(keydown(KEY_SHIFT))))%(len(tetraminos[t])-1)move[2]=1timer=monotonic()-monotimems=str(int((timer-floor(timer))*100))timem=floor(int(timer)/60)times=str(int(timer)-60*timem)ifmode!=0:draw_string(timems,75,180,wh,'black')draw_string(str(timem),25-len(str(timem)),180,wh,'black')draw_string(times,65-len(times)*10,180,wh,'black')if (mode==1andlines>=40)or(mode==2andtimem>=3):whilekeydown(KEY_5):passdraw_string("Victory",125,60)draw_string("[5] Back to menu",75,80)whilenotkeydown(KEY_5):passmenu(mode,speed)ifpx!=xorpy!=yorprot!=rot:refresh(t,px,py,prot)refresh(t,px,plowest,prot)fill_rect(110,19,100,1,(255,0,0))x_,y_=x,yfortestsinrange(7-int(prot==rot)*4):cur=tetraminos[t][rot]tempx,tempy=x_,y_foriinrange(len(cur)):ifcur[i]==0:tempx+=10ifcur[i]==1orcur[i]==3:ifnotget_pixel(tempx,tempy)==wh:iftests==0:y,y_,move[1]=py,py,0eliftests==1:x,x_,move[0]=px,px,0elif6>tests>=2andprot!=rot:iftests<5:iskicked=Trueelse:iskicked=Falsex_,y_=x,yift==0:ikick=ikicks[rot][prot]x_+=kickdata[ikick][tests-2][0]*10y_+=kickdata[ikick][tests-2][1]*10elift>=2:ifprot==0orprot==2:x_+=kickdata[rot-1][tests-2][0]*10y_+=kickdata[rot-1][tests-2][1]*10else:x_+=kickdata[prot][tests-2][0]*10y_+=kickdata[prot][tests-2][1]*10elift==1or(prot==rotandt==2):tests=6eliftests==6:rot,move[2]=prot,0breaktempx+=10ifcur[i]==2:tempy+=10tempx=x_ifprot!=rot:x,y=x_,y_hasmoved=Trueifmove[3]==1:lastmove=3hasmoved=Falseelifmove[2]==1:lastmove=2elifmove[1]==1:lastmove=1elifmove[0]==1:lastmove=0else:lastmove=-1hasmoved=Falsecur=tetraminos[t][rot]tempx,tempy=x+2,y+2foriinrange(len(cur)):ifcur[i]<=1:tempx+=10ifcur[i]==3:ifnotget_pixel(tempx,tempy+10)==wh:ifwait==-1orhasmoved:wait=monotonic()+.5py=yifwait<=monotonic():wait=-1tetra(x,y,t,rot)holdallowed=True#line
sline=0forys_inrange(20):ys=20-ys_line=0forxsinrange(112,212,10):ifget_pixel(xs,12+ys*10)!=wh:line+=1ifline==10:passsline+=1temp_y=10+ys*10scoring=0ifsline==0:combo=0else:score+=combo*50*levelcombo+=1ift==2andlastmove==2:c=0foradjinrange(4):ads=get_pixel(5+x+floor(adj%2)*20,5+y+floor(adj/2)*20)ifads!=wh:c+=1else:if (rot%2==0and(adj==rotoradj==rot+1))or(rot%2==1and(adj==1-(rot-1)/2)oradj==3-(rot-1)/2):scoring=3ifc>=3:ifscoring!=3:scoring=1ifiskicked:scoring=3elifscoring==3:scoring=0xp+=levelsys[sline]ifxp>=10andmode%3==0:iflevel<15:level+=1xp=0ifbsys[scoring][sline]==1:btob+=1elifsline!=0:btob=0ifbtob>=2:ifscoring!=3:scoring=2else:scoring=4lines+=slineifmode==0:score+=scoresys[scoring][sline]*levelelse:score+=scoresys[scoring][sline]title=scoretitles[scoring][sline]ifmode!=1:draw_string(str(score),85-ceil(len(str(score)))*10,130,wh,'black')else:draw_string(str(lines),35-ceil(len(str(lines)))*10,130,wh,'black')ifmode==0:draw_string(str(level),85-ceil(len(str(level)))*10,180,'white','black')draw_string(scoretitles[0][0],5,5,wh,'black')draw_string(title,5,5,wh,'black')ifbsys[scoring][sline]==1:btob=1ifsline!=0orscoring!=0:sleep(0.5)forys_inrange(20):ys=20-ys_line=0forxsinrange(112,212,10):ifget_pixel(xs,12+ys*10)!=wh:line+=1ifline==10:fill_rect(110,10+ys*10,100,10,wh)ifnotline==0:a=0temp_y=10+ys*10temp_line=[0,0,0,0,0,0,0,0,0,0]forxsinrange(10):temp_line[xs]=get_pixel(114+10*xs,temp_y+4)whilea<10:a=0forxsinrange(10):ifnotget_pixel(112+10*xs,temp_y+12)==wh:a+=1ifa==0:fill_rect(110,temp_y,100,10,wh)temp_y+=10else:forxs_inrange(10):ifnottemp_line[xs_]==wh:square(110+10*xs_,temp_y,temp_line[xs_])a=10forxdinrange(112,212,10):ifget_pixel(xd,12)!=wh:#ded
end=Truex,y,rot=140,0,0t=next[0][0]iskicked=Falsepx,py,prot=x,y,rotnext=nextt(next)sleep(0.2)breaktempx+=10ifcur[i]==2:tempy+=10tempx=xplowest=getlowest(x,y,t,rot)outline(x,plowest,t,rot)tetra(x,y,t,rot)draw_string("GAME OVER",115,60)draw_string("[5] Back to menu",75,80)whilenotkeydown(KEY_5):passdefmenu(mm,sm):globalmode,speedmode,speed=mm,smmodetext=["Marathon (default)","Sprint 40 lines ","Ultra 3 min "]i=0logo=[[1,1,1,0,2,2,2,0,3,3,3,0,4,4,4,0,5,0,6,6,6],[0,1,0,0,2,0,0,0,0,3,0,0,4,0,4,0,0,0,6,0,0],[0,1,0,0,2,2,0,0,0,3,0,0,4,4,0,0,5,0,0,6,0],[0,1,0,0,2,0,0,0,0,3,0,0,4,0,4,0,5,0,0,0,6],[0,1,0,0,2,2,2,0,0,3,0,0,4,0,0,4,5,0,6,6,6],]logocolors=[(0,0,100),(255,0,0),(255,150,0),(255,255,0),(0,255,0),(0,255,255),(255,0,255)]draw_logo()foryminrange(5):forxminrange(21):fill_rect(65+xm*9,32+ym*9,9,9,logocolors[logo[ym][xm]])whileTrue:ifi==0:draw_string("Press [EXE] to start",60,170,wh,'black')draw_string("[0] Options",105,190,wh,'black')ifkeydown(KEY_ZERO):i=1fill_rect(0,0,320,240,'black')whilekeydown(KEY_ZERO):passifkeydown(KEY_EXE):init()draw_logo()foryminrange(5):forxminrange(21):fill_rect(65+xm*9,32+ym*9,9,9,logocolors[logo[ym][xm]])ifi==1:draw_string("[Options]",10,10,wh,'black')draw_string("Mode : ",30,40,wh,'black')ifmm%3!=0:draw_string("Speed : ",30,60,wh,'black')draw_string(str(speed)+"",120,60,wh,'black')else:draw_string("",30,60,wh,'black')draw_string(modetext[mode%3],110,40,wh,'black')ifkeydown(KEY_5):mm+=1mode=mm%3whilekeydown(KEY_5):passsm+=int(keydown(KEY_UP))*int(speed<15)-int(keydown(KEY_DOWN)*int(speed>1))speed=smsleep(0.12)ifkeydown(KEY_ZERO):i=0draw_logo()foryminrange(5):forxminrange(21):fill_rect(65+xm*9,32+ym*9,9,9,logocolors[logo[ym][xm]])whilekeydown(KEY_ZERO):passdefdraw_logo():bc=(0,0,150)fill_rect(0,0,320,240,'black')fill_rect(55,20,210,70,bc)fill_rect(125,90,70,70,bc)fill_rect(60,25,200,60,(0,0,100))fill_rect(130,75,60,80,(0,0,100))defoutline(xt,yt,t,r):cur=tetraminos[t][r]xl=xtc=colors[tetraminos[t][len(tetraminos[t])-1]]cl=list(c)foriinrange(3):cl[i]=(cl[i]+255*5)/6c=tuple(cl)foriinrange(len(cur)):ifcur[i]==0:xl+=10ifcur[i]==1orcur[i]==3:square(xl,yt,c)xl+=10ifcur[i]==2:yt+=10xl=xtdefrefresh(t,px,py,prot):cur=tetraminos[t][prot]xtemp=pxforiinrange(len(cur)):ifcur[i]==0:px+=10ifcur[i]==1orcur[i]==3:fill_rect(px,py,10,10,wh)px+=10ifcur[i]==2:py+=10px=xtempdeftetra(xt,yt,t,r):cur=tetraminos[t][r]xl=xtforiinrange(len(cur)):ifcur[i]==0:xl+=10ifcur[i]==1orcur[i]==3:square(xl,yt,colors[tetraminos[t][len(tetraminos[t])-1]])xl+=10ifcur[i]==2:yt+=10xl=xtdefsquare(x,y,c):cd=list(c)foriinrange(3):cd[i]/=2cd=tuple(cd)cl=list(c)foriinrange(3):cl[i]=(cl[i]+255)/2fill_rect(x+1,y+1,8,8,c)fill_rect(x,y,9,1,cl)fill_rect(x,y,1,9,cl)fill_rect(x,y+9,9,1,cd)fill_rect(x+9,y,1,10,cd)defgetlowest(x,y,t,r):cur=tetraminos[t][r]forysinrange(y,230,10):py,px=ys+5,x+5calcdone=Falseforiinrange(len(cur)):ifcur[i]==0:px+=10ifcur[i]==1orcur[i]==3:ifnotget_pixel(px,py)==wh:calcdone=Truebreakpx+=10ifcur[i]==2:py+=10px=x+5ifcalcdone==True:returnys-10defnextt(l):ifl[1][0]==-1:l[1]=randombag()foriinrange(14):l[floor(i/7)][i%7]=l[floor((i+1)/7)][(i+1)%7]l[2][0]=-1fill_rect(250,50,40,130,'black')fornsinrange(4):tetra(250,60+30*ns,l[0][ns],0)returnldefrandombag():bag=[0,0,0,0,0,0,0]inbag=[0,1,2,3,4,5,6]foriinrange(7):rand=randrange(0,len(inbag))bag[i]=inbag[rand]inbag.pop(rand)returnbagdefstart_notice():print("Tetris C 1985-2022 Tetris Holding.\nTetris logos, Tetris theme song and Tetriminos are trademarks of Tetris Holding.\nThe Tetris trade dress is owned by Tetris Holding.\nLicensed to The Tetris Company.\nTetris Game Design by Alexey Pajitnov.\nTetris Logo Design by Roger Dean.\nAll Rights Reserved.")sleep(.5)start_notice()menu(0,2)
During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:
Ensure the proper functioning of the site (essential cookies); and
Track your browsing to send you personalized communications if you have created a professional account on the site and can be contacted (audience measurement cookies).
With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.