Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import *
- class Tetrominos:
- def __init__(self):
- pieces = [[[1,1,1],
- [0,1,0]]]
- self.apparence = choice(pieces)
- self.couleur = choice(['blue', 'red', 'yellow', 'white', 'cyan'])
- aa = Tetrominos()
- print(aa.)
- #dictionnaire des options
- config = {
- 'colonne': 13,
- 'rangée': 25,
- 'nombre de piece': 7}
- tab = [
- [0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0]]
- def placer_piece(tab, piece):
- '''
- Permet d'ajouter un tétrominos à la grille
- Entrée : une liste (la grille vierge)
- Sortie : une liste (la grille avec une pièce en haut)
- '''
- r = randint(0,6)
- tab[1] = piece[r][0]
- tab[2] = piece[r][1]
- return(tab)
- def descendre_piece(tab):
- '''
- Permet de faire descendre une pièce
- Entrée : une liste (la grille)
- Sortie : une liste avec la pièce descendu (la grille)
- '''
- droit = 1
- for i in range(len(tab)) :
- if tab[i][2] == 1 :
- droit = 0
- for j in range (len(tab[0])):
- i = -i
- if (tab[i][j] == 1) and tab[i+1][j] == 0 :
- tab[i][j] = 0
- tab[i+1][j] = 1
- elif (tab[i][j] == 2) and tab[i+1][j] == 0 :
- tab[i][j] = 0
- tab[i+1][j] = 2
- elif (tab[i][j] == 3) and tab[i+1][j] == 0 :
- tab[i][j] = 0
- tab[i+1][j] = 3
- elif (tab[i][j] == 4) and tab[i+1][j] == 0 :
- tab[i][j] = 0
- tab[i+1][j] = 4
- elif (tab[i][j] == 5) and tab[i+1][j] == 0 :
- tab[i][j] = 0
- tab[i+1][j] = 5
- elif (tab[i][j] == 6) and tab[i+1][j] == 0 :
- tab[i][j] = 0
- tab[i+1][j] = 6
- elif (tab[i][j] == 7) and tab[i+1][j] == 0 :
- tab[i][j] = 0
- tab[i+1][j] = 7
- return(tab)
- def arret(tab) :
- '''
- Permet d'arrêter l'affichage lorsque la pièce arrive en bas de la grille
- Permet d'éviter des prints inutiles
- Sera utile dans le futur(pour remettre une piece lorque l'autre arrive en bas)
- Entrée :
- Sortie :
- '''
- ar = False
- for i in range (len(tab)) :
- i = len(tab)-i-2
- for j in range (len(tab[0])):
- if (tab[i][j] > 0 and tab[i][j]<8) and tab[i+1][j] == 9 :
- ar = True
- return(ar)
- def affichage(tab) :
- '''
- Permet d'afficher la grille toute les secondes
- Entrée : la grille
- Sortie : la grille
- '''
- ent = int(input('appuyer sur 0 pour commencer'))
- while ent != 0 :
- ent = int(input('appuyer sur 0 pour commencer'))
- pl = placer_piece(tab, piece)
- return(pl)
- def colision(tab):
- for i,valeur in enumerate(tab):
- pass
- # Programme
- """
- af = affichage(tab)
- for i in range (len(tab)) : #permet de print les lignes de la liste 2D une à une pour créer un tableau
- print (af[i])
- arr = arret(tab)
- while arr == False:
- ds = descendre_piece(tab)
- for i in range(len(tab)) :
- print (ds[i])
- print("==============================")
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement