frommathimport*fromrandomimport*fromkandinskyimportfill_rectasrect,get_pixelasgpix,draw_stringasds,colorfromionimportkeydownaskdfromionimport*fromtimeimport*wh=color(255,255,255)bl=color(0,0,0)definit():rect(0,0,320,240,bl)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)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)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)rect(250,50,40,130,bl)rect(30,50,40,40,bl)ifmode%3!=1:ds("Score :",15,110,wh,bl)ds("0000000",15,130,wh,bl)else:ds("Lines :",15,110,wh,bl)ds("00/40",15,130,wh,bl)ifmode%3==0:ds("Level :",15,160,wh,bl)ds("01",65,180,wh,bl)else:ds("Time :",15,160,wh,bl)ds("00:00.00",15,180,wh,bl)fortminrange(3):ds(str(3-tm),155,110)sleep(1)ds("",155,110)game()defgame():x,y,px,py=140,20,150,10t=randrange(0,7)wait=-1rot=0plowest=500next=[[0]*8,[-1]+[0]*7,[-1]]next[0]=randombag()next=nextt(next)hold,holdtemp,holdallowed=-1,0,Truescore,combo=0,0level=1ifmode==0elsespeedxp=0btob=0end=Falsemono=monotonic()mt=monotonic()coolr=0lines=0coolh=monotonic()arr=Truewhileend==False:px,py,prot=x,y,rotmove=[0]*4ifkd(52):whilekd(52):passwhilenotkd(52):ds("Paused",240,205,wh,bl)ds("7-Restart",5,5,wh,bl)ds("Menu-9",240,5,wh,bl)ifkd(30):init()ifkd(32):menu(mode,speed)ds("",240,205,wh,bl)ds("",5,5,wh,bl)ds("",240,5,wh,bl)whilekd(52):passfortminrange(3):ds(str(3-tm),10,200,wh,bl)sleep(1)ds("",10,200,wh,bl)if (mt+(0.8-(level-1)*0.007)**(level-1)<=monotonic()andnotkd(2))or(mt+0.03<=monotonic()andkd(2)):y+=10mt=monotonic()move[1]=1ifkd(17)andholdallowed:ifhold==-1:hold=next[0][0]next=nextt(next)refresh(t,px,py,prot)refresh(t,px,plowest,prot)holdtemp=holdhold=trect(30,50,40,40,bl)tetra(30,60,hold,0)t=holdtempholdallowed=Falsex,y,rot,px,py,prot,plowest=140,10,0,140,10,0,500ifkd(0)andcoolh<=monotonic():x-=10coolh=monotonic()+0.03+int(arr)*0.14arr=Falsemove[0]=1ifnot(kd(3)orkd(0)):coolh=monotonic()arr=Trueifkd(3)andcoolh<=monotonic():x+=10coolh=monotonic()+0.03+int(arr)*0.14arr=Falsemove[0]=1ifkd(1):move[3]=1y=plowestwait=monotonic()ifkd(4):coolr+=1else:coolr=0ifcoolr==1:rot=(rot+(1-2*int(kd(12))))%(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:ds(timems,75,180,wh,bl)ds(str(timem),25-len(str(timem)),180,wh,bl)ds(times,65-len(times)*10,180,wh,bl)if (mode==1andlines>=40)or(mode==2andtimem>=3):whilekd(4):passds("Victory",125,60)ds("[OK] Back to menu",75,80)whilenotkd(4):passmenu(mode,speed)ifpx!=xorpy!=yorprot!=rot:refresh(t,px,py,prot)refresh(t,px,plowest,prot)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:ifnotgpix(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=-1
hasmoved=Falsecur=tetraminos[t][rot]tempx,tempy=x+2,y+2foriinrange(len(cur)):ifcur[i]<=1:tempx+=10ifcur[i]==3:ifnotgpix(tempx,tempy+10)==wh:ifwait==-1orhasmoved:wait=monotonic()+.5py=yifwait<=monotonic():wait=-1tetra(x,y,t,rot)holdallowed=Truesline=0forys_inrange(20):ys=20-ys_line=0forxsinrange(112,212,10):ifgpix(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=gpix(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:ds(str(score),85-ceil(len(str(score)))*10,130,wh,bl)else:ds(str(lines),35-ceil(len(str(lines)))*10,130,wh,bl)ifmode==0:ds(str(level),85-ceil(len(str(level)))*10,180,wh,bl)ds(scoretitles[0][0],5,5,wh,bl)ds(title,5,5,wh,bl)ifbsys[scoring][sline]==1:btob=1ifsline!=0orscoring!=0:sleep(0.5)forys_inrange(20):ys=20-ys_line=0forxsinrange(112,212,10):ifgpix(xs,12+ys*10)!=wh:line+=1ifline==10: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]=gpix(114+10*xs,temp_y+4)whilea<10:a=0forxsinrange(10):ifnotgpix(112+10*xs,temp_y+12)==wh:a+=1ifa==0: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):ifgpix(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)ds("GAME OVER",115,60)ds("[OK] Back to menu",75,80)whilenotkd(4):passdefmenu(mm,sm):globalmode,speedmode,speed=mm,smmodetext=["Marathon (default)","Sprint 40 lines ","Ultra 3 min "]i=0draw_logo()whileTrue:ifi==0:ds("Press [EXE] to start",60,170,wh,bl)ds("[0] Options",105,190,wh,bl)ifkd(48):i=1rect(0,0,320,240,bl)whilekd(48):passifkd(52):init()draw_logo()ifi==1:ds("[Options]",10,10,wh,bl)ds("Mode : ",30,40,wh,bl)ifmm%3!=0:ds("Speed : ",30,60,wh,bl)ds(str(speed)+"",120,60,wh,bl)else:ds("",30,60,wh,bl)ds(modetext[mode%3],110,40,wh,bl)ifkd(4):mm+=1mode=mm%3whilekd(4):passsm+=int(kd(1))*int(speed<15)-int(kd(2)*int(speed>1))speed=smsleep(0.12)ifkd(48):i=0draw_logo()whilekd(48):passdefdraw_logo():logo=[[1,1,1,0,2,2,2,0,3,3,3,0,4,4,4,0,5,0,0,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,4,0,5,0,6,6,0],]logocolors=[(0,0,100),(255,0,0),(255,150,0),(255,255,0),(0,255,0),(0,255,255),(255,0,255)]bc=(0,0,150)rect(0,0,320,240,bl)rect(55,20,210,70,bc)rect(125,90,70,70,bc)rect(60,25,200,60,(0,0,100))rect(130,75,60,80,(0,0,100))foryminrange(5):forxminrange(21):rect(65+xm*9,32+ym*9,9,9,logocolors[logo[ym][xm]])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: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)/2rect(x+1,y+1,8,8,c)rect(x,y,9,1,cl)rect(x,y,1,9,cl)rect(x,y+9,9,1,cd)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:ifnotgpix(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]=-1rect(250,50,40,130,bl)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-2023 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)# Type your text here
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.