Tetrominoes out of class
This commit is contained in:
parent
afcb919018
commit
759c6f2054
@ -10,19 +10,26 @@ class Mino:
|
|||||||
self.coord = coord
|
self.coord = coord
|
||||||
|
|
||||||
|
|
||||||
|
class MetaTetromino(type):
|
||||||
|
|
||||||
|
def __init__(cls, name, bases, dct):
|
||||||
|
super().__init__(name, bases, dct)
|
||||||
|
Tetromino.shapes.append(cls)
|
||||||
|
|
||||||
|
|
||||||
class Tetromino:
|
class Tetromino:
|
||||||
|
|
||||||
|
shapes = []
|
||||||
random_bag = []
|
random_bag = []
|
||||||
|
|
||||||
|
def __new__(cls):
|
||||||
class MetaTetromino(type):
|
if not cls.random_bag:
|
||||||
|
cls.random_bag = list(cls.shapes)
|
||||||
def __init__(cls, name, bases, dico):
|
random.shuffle(cls.random_bag)
|
||||||
super().__init__(name, bases, dico)
|
return cls.random_bag.pop()()
|
||||||
cls.classes.append(cls)
|
|
||||||
|
|
||||||
|
|
||||||
class AbstractTetromino(list):
|
class AbstractTetromino(list):
|
||||||
|
|
||||||
# Super rotation system
|
# Super rotation system
|
||||||
SRS = {
|
SRS = {
|
||||||
@ -39,7 +46,6 @@ class Tetromino:
|
|||||||
(Coord(0, 0), Coord(-1, 0), Coord(-1, -1), Coord(0, 2), Coord(-1, 2)),
|
(Coord(0, 0), Coord(-1, 0), Coord(-1, -1), Coord(0, 2), Coord(-1, 2)),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
classes = []
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
@ -54,7 +60,7 @@ class Tetromino:
|
|||||||
def ghost(self):
|
def ghost(self):
|
||||||
return self.__class__()
|
return self.__class__()
|
||||||
|
|
||||||
class O(AbstractTetromino, metaclass=MetaTetromino):
|
class O(AbstractTetromino, metaclass=MetaTetromino):
|
||||||
|
|
||||||
SRS = {
|
SRS = {
|
||||||
Rotation.CLOCKWISE: (tuple(), tuple(), tuple(), tuple()),
|
Rotation.CLOCKWISE: (tuple(), tuple(), tuple(), tuple()),
|
||||||
@ -67,7 +73,7 @@ class Tetromino:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
class I(AbstractTetromino, metaclass=MetaTetromino):
|
class I(AbstractTetromino, metaclass=MetaTetromino):
|
||||||
|
|
||||||
SRS = {
|
SRS = {
|
||||||
Rotation.CLOCKWISE: (
|
Rotation.CLOCKWISE: (
|
||||||
@ -87,38 +93,31 @@ class Tetromino:
|
|||||||
MINOES_COLOR = "cyan"
|
MINOES_COLOR = "cyan"
|
||||||
|
|
||||||
|
|
||||||
class T(AbstractTetromino, metaclass=MetaTetromino):
|
class T(AbstractTetromino, metaclass=MetaTetromino):
|
||||||
|
|
||||||
MINOES_COORDS = (Coord(-1, 0), Coord(0, 0), Coord(0, 1), Coord(1, 0))
|
MINOES_COORDS = (Coord(-1, 0), Coord(0, 0), Coord(0, 1), Coord(1, 0))
|
||||||
MINOES_COLOR = "magenta"
|
MINOES_COLOR = "magenta"
|
||||||
|
|
||||||
|
|
||||||
class L(AbstractTetromino, metaclass=MetaTetromino):
|
class L(AbstractTetromino, metaclass=MetaTetromino):
|
||||||
|
|
||||||
MINOES_COORDS = (Coord(-1, 0), Coord(0, 0), Coord(1, 0), Coord(1, 1))
|
MINOES_COORDS = (Coord(-1, 0), Coord(0, 0), Coord(1, 0), Coord(1, 1))
|
||||||
MINOES_COLOR = "orange"
|
MINOES_COLOR = "orange"
|
||||||
|
|
||||||
|
|
||||||
class J(AbstractTetromino, metaclass=MetaTetromino):
|
class J(AbstractTetromino, metaclass=MetaTetromino):
|
||||||
|
|
||||||
MINOES_COORDS = (Coord(-1, 1), Coord(-1, 0), Coord(0, 0), Coord(1, 0))
|
MINOES_COORDS = (Coord(-1, 1), Coord(-1, 0), Coord(0, 0), Coord(1, 0))
|
||||||
MINOES_COLOR = "blue"
|
MINOES_COLOR = "blue"
|
||||||
|
|
||||||
|
|
||||||
class S(AbstractTetromino, metaclass=MetaTetromino):
|
class S(AbstractTetromino, metaclass=MetaTetromino):
|
||||||
|
|
||||||
MINOES_COORDS = (Coord(-1, 0), Coord(0, 0), Coord(0, 1), Coord(1, 1))
|
MINOES_COORDS = (Coord(-1, 0), Coord(0, 0), Coord(0, 1), Coord(1, 1))
|
||||||
MINOES_COLOR = "green"
|
MINOES_COLOR = "green"
|
||||||
|
|
||||||
|
|
||||||
class Z(AbstractTetromino, metaclass=MetaTetromino):
|
class Z(AbstractTetromino, metaclass=MetaTetromino):
|
||||||
|
|
||||||
MINOES_COORDS = (Coord(-1, 1), Coord(0, 1), Coord(0, 0), Coord(1, 0))
|
MINOES_COORDS = (Coord(-1, 1), Coord(0, 1), Coord(0, 0), Coord(1, 0))
|
||||||
MINOES_COLOR = "red"
|
MINOES_COLOR = "red"
|
||||||
|
|
||||||
|
|
||||||
def __new__(cls):
|
|
||||||
if not cls.random_bag:
|
|
||||||
cls.random_bag = list(Tetromino.AbstractTetromino.classes)
|
|
||||||
random.shuffle(cls.random_bag)
|
|
||||||
return cls.random_bag.pop()()
|
|
Loading…
x
Reference in New Issue
Block a user