use texture, import from, black
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from .consts import NB_LINES, NB_COLS, NB_NEXT
|
||||
from .utils import Movement, Rotation
|
||||
from .utils import Movement, Rotation, Color
|
||||
from .tetromino import Mino, Tetromino
|
||||
from .tetrislogic import TetrisLogic, State, Matrix
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
import random
|
||||
import pickle
|
||||
|
||||
from .utils import Coord, Movement, Rotation, T_Spin, Line
|
||||
from .utils import Coord, Movement, Rotation, T_Spin
|
||||
from .tetromino import Tetromino, T, I
|
||||
from .consts import (
|
||||
NB_LINES,
|
||||
@ -102,7 +102,7 @@ class TetrisLogic:
|
||||
return self.random_bag.pop()()
|
||||
|
||||
def append_new_line_to_matrix(self):
|
||||
self.matrix.append(Line(None for x in range(self.NB_COLS)))
|
||||
self.matrix.append([None for x in range(self.NB_COLS)])
|
||||
|
||||
def new_level(self):
|
||||
self.level += 1
|
||||
@ -145,9 +145,7 @@ class TetrisLogic:
|
||||
self.ghost.coord = self.current.coord
|
||||
for ghost_mino, current_mino in zip(self.ghost, self.current):
|
||||
ghost_mino.coord = current_mino.coord
|
||||
while self.can_move(
|
||||
self.ghost.coord + Movement.DOWN, (mino.coord for mino in self.ghost)
|
||||
):
|
||||
while self.can_move(self.ghost.coord + Movement.DOWN, (mino.coord for mino in self.ghost)):
|
||||
self.ghost.coord += Movement.DOWN
|
||||
|
||||
def soft_drop(self):
|
||||
@ -181,13 +179,8 @@ class TetrisLogic:
|
||||
return False
|
||||
|
||||
def rotate(self, rotation):
|
||||
rotated_coords = tuple(
|
||||
Coord(rotation * mino.coord.y, -rotation * mino.coord.x)
|
||||
for mino in self.current
|
||||
)
|
||||
for rotation_point, liberty_degree in enumerate(
|
||||
self.current.SRS[rotation][self.current.orientation], start=1
|
||||
):
|
||||
rotated_coords = tuple(Coord(rotation * mino.coord.y, -rotation * mino.coord.x) for mino in self.current)
|
||||
for rotation_point, liberty_degree in enumerate(self.current.SRS[rotation][self.current.orientation], start=1):
|
||||
potential_coord = self.current.coord + liberty_degree
|
||||
if self.can_move(potential_coord, rotated_coords):
|
||||
if self.current.prelocked:
|
||||
@ -215,16 +208,11 @@ class TetrisLogic:
|
||||
self.stop(self.lock)
|
||||
|
||||
# Piece unlocked
|
||||
if self.can_move(
|
||||
self.current.coord + Movement.DOWN, (mino.coord for mino in self.current)
|
||||
):
|
||||
if self.can_move(self.current.coord + Movement.DOWN, (mino.coord for mino in self.current)):
|
||||
return
|
||||
|
||||
# Game over
|
||||
if all(
|
||||
(mino.coord + self.current.coord).y >= self.NB_LINES
|
||||
for mino in self.current
|
||||
):
|
||||
if all((mino.coord + self.current.coord).y >= self.NB_LINES for mino in self.current):
|
||||
self.game_over()
|
||||
return
|
||||
|
||||
@ -296,17 +284,12 @@ class TetrisLogic:
|
||||
self.new_current()
|
||||
|
||||
def can_move(self, potential_coord, minoes_coords):
|
||||
return all(
|
||||
self.matrix.cell_is_free(potential_coord + mino_coord)
|
||||
for mino_coord in minoes_coords
|
||||
)
|
||||
return all(self.matrix.cell_is_free(potential_coord + mino_coord) for mino_coord in minoes_coords)
|
||||
|
||||
T_SLOT_COORDS = (Coord(-1, 1), Coord(1, 1), Coord(-1, 1), Coord(-1, -1))
|
||||
|
||||
def is_t_slot(self, n):
|
||||
t_slot_coord = (
|
||||
self.current.coord + self.T_SLOT_COORDS[(self.current.orientation + n) % 4]
|
||||
)
|
||||
t_slot_coord = self.current.coord + self.T_SLOT_COORDS[(self.current.orientation + n) % 4]
|
||||
return not self.matrix.cell_is_free(t_slot_coord)
|
||||
|
||||
def swap(self):
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from .utils import Coord, Rotation
|
||||
from .utils import Coord, Rotation, Color
|
||||
|
||||
|
||||
class Mino:
|
||||
@ -51,7 +51,7 @@ class O(Tetromino, metaclass=MetaTetromino):
|
||||
Rotation.COUNTER: (tuple(), tuple(), tuple(), tuple()),
|
||||
}
|
||||
MINOES_COORDS = (Coord(0, 0), Coord(1, 0), Coord(0, 1), Coord(1, 1))
|
||||
MINOES_COLOR = "yellow"
|
||||
MINOES_COLOR = Color.YELLOW
|
||||
|
||||
def rotate(self, direction):
|
||||
return False
|
||||
@ -74,34 +74,34 @@ class I(Tetromino, metaclass=MetaTetromino):
|
||||
),
|
||||
}
|
||||
MINOES_COORDS = (Coord(-1, 0), Coord(0, 0), Coord(1, 0), Coord(2, 0))
|
||||
MINOES_COLOR = "cyan"
|
||||
MINOES_COLOR = Color.CYAN
|
||||
|
||||
|
||||
class T(Tetromino, metaclass=MetaTetromino):
|
||||
|
||||
MINOES_COORDS = (Coord(-1, 0), Coord(0, 0), Coord(0, 1), Coord(1, 0))
|
||||
MINOES_COLOR = "magenta"
|
||||
MINOES_COLOR = Color.MAGENTA
|
||||
|
||||
|
||||
class L(Tetromino, metaclass=MetaTetromino):
|
||||
|
||||
MINOES_COORDS = (Coord(-1, 0), Coord(0, 0), Coord(1, 0), Coord(1, 1))
|
||||
MINOES_COLOR = "orange"
|
||||
MINOES_COLOR = Color.ORANGE
|
||||
|
||||
|
||||
class J(Tetromino, metaclass=MetaTetromino):
|
||||
|
||||
MINOES_COORDS = (Coord(-1, 1), Coord(-1, 0), Coord(0, 0), Coord(1, 0))
|
||||
MINOES_COLOR = "blue"
|
||||
MINOES_COLOR = Color.BLUE
|
||||
|
||||
|
||||
class S(Tetromino, metaclass=MetaTetromino):
|
||||
|
||||
MINOES_COORDS = (Coord(-1, 0), Coord(0, 0), Coord(0, 1), Coord(1, 1))
|
||||
MINOES_COLOR = "green"
|
||||
MINOES_COLOR = Color.GREEN
|
||||
|
||||
|
||||
class Z(Tetromino, metaclass=MetaTetromino):
|
||||
|
||||
MINOES_COORDS = (Coord(-1, 1), Coord(0, 1), Coord(0, 0), Coord(1, 0))
|
||||
MINOES_COLOR = "red"
|
||||
MINOES_COLOR = Color.RED
|
||||
|
||||
@ -28,5 +28,12 @@ class T_Spin:
|
||||
T_SPIN = "T-SPIN"
|
||||
|
||||
|
||||
class Line(list):
|
||||
pass
|
||||
class Color:
|
||||
|
||||
BLUE = 0
|
||||
CYAN = 1
|
||||
GREEN = 2
|
||||
MAGENTA = 3
|
||||
ORANGE = 4
|
||||
RED = 5
|
||||
YELLOW = 6
|
||||
|
||||
Reference in New Issue
Block a user