Advertisement
Guest User

MatheopourLéo

a guest
Jan 20th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.67 KB | None | 0 0
  1. from random import *
  2.  
  3. class Tetrominos:
  4.     def __init__(self):
  5.        
  6.         pieces = [[[1,1,1],
  7.                    [0,1,0]]]
  8.        
  9.         self.apparence = choice(pieces)
  10.         self.couleur   = choice(['blue', 'red', 'yellow', 'white', 'cyan'])
  11.  
  12.  
  13. aa = Tetrominos()
  14. print(aa.)
  15.  
  16. #dictionnaire des options
  17. config = {
  18. 'colonne':  13,
  19. 'rangée':  25,
  20. 'nombre de piece':  7}
  21.  
  22. tab = [
  23. [0,0,0,0,0,0,0,0,0,0,0],
  24. [0,0,0,0,0,0,0,0,0,0,0],
  25. [0,0,0,0,0,0,0,0,0,0,0],
  26. [0,0,0,0,0,0,0,0,0,0,0],
  27. [0,0,0,0,0,0,0,0,0,0,0],
  28. [0,0,0,0,0,0,0,0,0,0,0],
  29. [0,0,0,0,0,0,0,0,0,0,0],
  30. [0,0,0,0,0,0,0,0,0,0,0],
  31. [0,0,0,0,0,0,0,0,0,0,0],
  32. [0,0,0,0,0,0,0,0,0,0,0],
  33. [0,0,0,0,0,0,0,0,0,0,0],
  34. [0,0,0,0,0,0,0,0,0,0,0],
  35. [0,0,0,0,0,0,0,0,0,0,0],
  36. [0,0,0,0,0,0,0,0,0,0,0],
  37. [0,0,0,0,0,0,0,0,0,0,0],
  38. [0,0,0,0,0,0,0,0,0,0,0],
  39. [0,0,0,0,0,0,0,0,0,0,0],
  40. [0,0,0,0,0,0,0,0,0,0,0],
  41. [0,0,0,0,0,0,0,0,0,0,0],
  42. [0,0,0,0,0,0,0,0,0,0,0],
  43. [0,0,0,0,0,0,0,0,0,0,0],
  44. [0,0,0,0,0,0,0,0,0,0,0]]
  45.  
  46. def placer_piece(tab, piece):
  47.     '''
  48.    Permet d'ajouter un tétrominos à la grille
  49.    Entrée : une liste (la grille vierge)
  50.    Sortie : une liste (la grille avec une pièce en haut)
  51.    '''
  52.     r = randint(0,6)
  53.  
  54.     tab[1] = piece[r][0]
  55.     tab[2] = piece[r][1]
  56.     return(tab)
  57.  
  58. def descendre_piece(tab):
  59.     '''
  60.    Permet de faire descendre une pièce
  61.    Entrée : une liste (la grille)
  62.    Sortie : une liste avec la pièce descendu (la grille)
  63.    '''
  64.     droit = 1
  65.     for i in range(len(tab)) :
  66.         if tab[i][2] == 1 :
  67.             droit = 0
  68.         for j in range (len(tab[0])):
  69.             i = -i
  70.             if (tab[i][j] == 1) and tab[i+1][j] == 0 :
  71.                 tab[i][j] = 0
  72.                 tab[i+1][j] = 1
  73.  
  74.             elif (tab[i][j] == 2) and tab[i+1][j] == 0 :
  75.                 tab[i][j] = 0
  76.                 tab[i+1][j] = 2
  77.  
  78.             elif (tab[i][j] == 3) and tab[i+1][j] == 0 :
  79.                 tab[i][j] = 0
  80.                 tab[i+1][j] = 3
  81.  
  82.             elif (tab[i][j] == 4) and tab[i+1][j] == 0 :
  83.                 tab[i][j] = 0
  84.                 tab[i+1][j] = 4
  85.  
  86.             elif (tab[i][j] == 5) and tab[i+1][j] == 0 :
  87.                 tab[i][j] = 0
  88.                 tab[i+1][j] = 5
  89.  
  90.             elif (tab[i][j] == 6) and tab[i+1][j] == 0 :
  91.                 tab[i][j] = 0
  92.                 tab[i+1][j] = 6
  93.  
  94.             elif (tab[i][j] == 7) and tab[i+1][j] == 0 :
  95.                 tab[i][j] = 0
  96.                 tab[i+1][j] = 7
  97.     return(tab)
  98.  
  99. def arret(tab) :
  100.     '''
  101.    Permet d'arrêter l'affichage lorsque la pièce arrive en bas de la grille
  102.    Permet d'éviter des prints inutiles
  103.    Sera utile dans le futur(pour remettre une piece lorque l'autre arrive en bas)
  104.    Entrée :
  105.    Sortie :
  106.    '''
  107.     ar = False
  108.  
  109.     for i in range (len(tab)) :
  110.         i = len(tab)-i-2
  111.         for j in range (len(tab[0])):
  112.             if (tab[i][j] > 0 and tab[i][j]<8) and tab[i+1][j] == 9 :
  113.                 ar = True
  114.     return(ar)
  115.  
  116. def affichage(tab) :
  117.     '''
  118.    Permet d'afficher la grille toute les secondes
  119.    Entrée : la grille
  120.    Sortie : la grille
  121.    '''
  122.     ent = int(input('appuyer sur 0 pour commencer'))
  123.  
  124.     while ent != 0 :
  125.         ent = int(input('appuyer sur 0 pour commencer'))
  126.     pl = placer_piece(tab, piece)
  127.     return(pl)
  128.  
  129.  
  130. def colision(tab):
  131.     for i,valeur in enumerate(tab):
  132.         pass
  133. # Programme
  134. """
  135. af = affichage(tab)
  136. for i in range (len(tab)) : #permet de print les lignes de la liste 2D une à une pour créer un tableau
  137.    print (af[i])
  138.  
  139. arr = arret(tab)
  140.  
  141. while arr == False:
  142.  
  143.    ds = descendre_piece(tab)
  144.    for i in range(len(tab)) :
  145.        print (ds[i])
  146.    print("==============================")
  147. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement