random choose shape in tetrislogic

This commit is contained in:
adrienmalin
2019-10-01 01:40:25 +02:00
parent 59b21145f4
commit f7a47efecf
2 changed files with 16 additions and 22 deletions

View File

@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
import random
from .utils import Coord, Movement, Rotation, T_Spin, Line
from .tetromino import Tetromino, T
from .consts import (
@ -32,6 +34,8 @@ class Matrix(list):
class TetrisLogic():
random_bag = []
def __init__(self):
self.load_high_score()
self.state = State.STARTING
@ -79,7 +83,10 @@ class TetrisLogic():
self.new_level()
def new_tetromino(self):
return Tetromino()
if not self.random_bag:
self.random_bag = list(Tetromino.shapes)
random.shuffle(self.random_bag)
return self.random_bag.pop()()
def append_new_line_to_matrix(self):
self.matrix.append(Line(None for x in range(NB_COLS)))