tetris.py

Created by marius-layan

Created on February 05, 2024

5.17 KB

BETA (un problème sur la navigation latéral, et la rotation des pièces n’est pas présente) Se script est réalisé par un lycéen de première. Voici mon jeu nommé Tetris. ce jeu est assez connu mais pour les quelques personnes vivants dans une grotte, je vous explique le but du jeu : Tetris met le joueur au défi de réaliser des lignes complètes en déplaçant des pièces de formes différentes, les tétrominos, qui défilent depuis le haut jusqu’au bas de l’écran. Les lignes complétées disparaissent et le joueur peut de nouveau remplir les cases libérées.

Les touches utilisables sont: [LEFT]–[RIGHT]–[DOWN]


from kandinsky import *
from random import *
from time import *
from ion import *
color=[(225,225,0),(20,40,255),(225,0,0),(0,200,0),(255,150,0),(230,80,160),(160,30,160)]
def o():fill_rect(a,b,30,30,color[0])
def i():fill_rect(a,b,15,60,color[1])
def s():fill_rect(15+a,b,30,15,color[2]);fill_rect(a,15+b,30,15,color[2])
def z():fill_rect(a,b,30,15,color[3]);fill_rect(15+a,15+b,30,15,color[3])
def l():fill_rect(a,b,15,45,color[4]);fill_rect(15+a,30+b,15,15,color[4])
def j():fill_rect(15+a,b,15,45,color[5]);fill_rect(a,30+b,15,15,color[5])
def t():fill_rect(a,b,45,15,color[6]);fill_rect(15+a,15+b,15,15,color[6])
fill_rect(0,0,320,222,'black');fill_rect(80,0,160,222,'gray');fill_rect(85,6,150,210,'black')
score=[-1,0]
while True:
  for k in range(1,14):
    if get_pixel(90,6+15*k)!=(0,0,0) and get_pixel(105,6+15*k)!=(0,0,0) and get_pixel(120,6+15*k)!=(0,0,0) and get_pixel(135,6+15*k)!=(0,0,0) and get_pixel(150,6+15*k)!=(0,0,0) and get_pixel(165,6+15*k)!=(0,0,0) and get_pixel(180,6+15*k)!=(0,0,0) and get_pixel(195,6+15*k)!=(0,0,0) and get_pixel(210,6+15*k)!=(0,0,0) and get_pixel(225,6+15*k)!=(0,0,0):
      fill_rect(85,6+15*k,150,15,'black')
      for b in range(1,k):
        for d in range(1,11):
          e=get_pixel(70+d*15,6+15*(k-b))
          fill_rect(70+d*15,21+15*(k-b),15,15,e)
      score[1]+=1
  if get_pixel(90,11)!=(0,0,0) or get_pixel(105,11)!=(0,0,0) or get_pixel(120,11)!=(0,0,0) or get_pixel(135,11)!=(0,0,0) or get_pixel(150,11)!=(0,0,0) or get_pixel(165,11)!=(0,0,0) or get_pixel(180,11)!=(0,0,0) or get_pixel(195,11)!=(0,0,0) or get_pixel(210,11)!=(0,0,0) or get_pixel(225,11)!=(0,0,0) or get_pixel(150,26)!=(0,0,0) or get_pixel(165,26)!=(0,0,0):break
  module=randint(0,6)
  a,b,c=145,6,0
  score[0]+=1
  draw_string("score:",5,5,'white','black')
  draw_string(str(score[0]),5,25,'white','black')
  draw_string("lignes:",5,60,'white','black')
  draw_string(str(score[1]),5,80,'white','black')
  while True:
    if module==0:
      if get_pixel(a+5,b+35)!=(0,0,0) or get_pixel(a+20,b+35)!=(0,0,0):break
      if keydown(KEY_LEFT) and c%24==0 and a>95:color[0]='black';o();a-=15;color[0]=(225,225,0)
      elif keydown(KEY_RIGHT) and c%24==0 and a<195:color[0]='black';o();a+=15;color[0]=(225,225,0)
      if keydown(KEY_DOWN) and c%12==0:color[0]='black';o();b+=15;color[0]=(225,225,0)
      if c==250:c=0;color[0]='black';o();b+=15;color[0]=(225,225,0)
      o()
    elif module==1:
      if get_pixel(a+5,b+65)!=(0,0,0):break
      if keydown(KEY_LEFT) and c%24==0 and a>95:color[1]='black';i();a-=15;color[1]=(20,40,255)
      elif keydown(KEY_RIGHT) and c%24==0 and a<210:color[1]='black';i();a+=15;color[1]=(20,40,255)
      if keydown(KEY_DOWN) and c%12==0:color[1]='black';i();b+=15;color[1]=(20,40,255)
      if c==250:c=0;color[1]='black';i();b+=15;color[1]=(20,40,255)
      i()
    elif module==2:
      if get_pixel(a+5,b+35)!=(0,0,0) or get_pixel(a+20,b+35)!=(0,0,0) or get_pixel(a+35,b+20)!=(0,0,0):break
      if keydown(KEY_LEFT) and c%24==0 and a>95:color[2]='black';s();a-=15;color[2]=(225,0,0)
      elif keydown(KEY_RIGHT) and c%24==0 and a<180:color[2]='black';s();a+=15;color[2]=(225,0,0)
      if keydown(KEY_DOWN) and c%12==0:color[2]='black';s();b+=15;color[2]=(225,0,0)
      if c==250:c=0;color[2]='black';s();b+=15;color[2]=(225,0,0)
      s()
    elif module==3:
      if get_pixel(a+5,b+20)!=(0,0,0) or get_pixel(a+20,b+35)!=(0,0,0) or get_pixel(a+35,b+35)!=(0,0,0):break
      if keydown(KEY_LEFT) and c%24==0 and a>95:color[3]='black';z();a-=15;color[3]=(0,200,0)
      elif keydown(KEY_RIGHT) and c%24==0 and a<180:color[3]='black';z();a+=15;color[3]=(0,200,0)
      if keydown(KEY_DOWN) and c%12==0:color[3]='black';z();b+=15;color[3]=(0,200,0)
      if c==250:c=0;color[3]='black';z();b+=15;color[3]=(0,200,0)
      z()
    elif module==4:
      if get_pixel(a+5,b+50)!=(0,0,0) or get_pixel(a+20,b+50)!=(0,0,0):break
      if keydown(KEY_LEFT) and c%24==0 and a>95:color[4]='black';l();a-=15;color[4]=(255,150,0)
      elif keydown(KEY_RIGHT) and c%24==0 and a<195:color[4]='black';l();a+=15;color[4]=(255,150,0)
      if keydown(KEY_DOWN) and c%12==0:color[4]='black';l();b+=15;color[4]=(255,150,0)
      if c==250:c=0;color[4]='black';l();b+=15;color[4]=(255,150,0)
      l()
    elif module==5:
      if get_pixel(a+5,b+50)!=(0,0,0) or get_pixel(a+20,b+50)!=(0,0,0):break
      if keydown(KEY_LEFT) and c%24==0 and a>95:color[5]='black';j();a-=15;color[5]=(230,80,160)
      elif keydown(KEY_RIGHT) and c%24==0 and a<195:color[5]='black';j();a+=15;color[5]=(230,80,160)
      if keydown(KEY_DOWN) and c%12==0:color[5]='black';j();b+=15;color[5]=(230,80,160)
      if c==250:c=0;color[5]='black';j();b+=15;color[5]=(230,80,160)
      j()
    else:
      if keydown(KEY_LEFT) and c%24==0 and a>95:color[6]='black';t();a-=15;color[6]=(160,30,160)
      elif keydown(KEY_RIGHT) and c%24==0 and a<180:color[6]='black';t();a+=15;color[6]=(160,30,160)
      if keydown(KEY_DOWN) and c%12==0:color[6]='black';t();b+=15;color[6]=(160,30,160)
      if c==250:c=0;color[6]='black';t();b+=15;color[6]=(160,30,160)
      t()
      if get_pixel(a+5,b+20)!=(0,0,0) or get_pixel(a+20,b+35)!=(0,0,0) or get_pixel(a+35,b+20)!=(0,0,0):break

    c+=1
fill_rect(0,0,320,222,'black')
draw_string("GAME OVER",115,100,'red','black')