propertize just Point.x and y
This commit is contained in:
parent
174af377ae
commit
68cf21392c
@ -95,7 +95,7 @@ class Matrix(Grid):
|
||||
|
||||
ROWS = consts.MATRIX_ROWS + consts.GRID_INVISIBLE_ROWS
|
||||
COLUMNS = consts.MATRIX_COLUMNS
|
||||
STARTING_POSITION = Point(COLUMNS // 2, consts.GRID_INVISIBLE_ROWS - 1)
|
||||
STARTING_POSITION = Point(COLUMNS // 2 - 1, consts.GRID_INVISIBLE_ROWS - 1)
|
||||
TEXT_COLOR = consts.MATRIX_TEXT_COLOR
|
||||
|
||||
drop_signal = QtCore.Signal(int)
|
||||
@ -153,7 +153,7 @@ class Matrix(Grid):
|
||||
return [None for x in range(self.COLUMNS)]
|
||||
|
||||
def is_empty_cell(self, coord):
|
||||
x, y = coord.x(), coord.y()
|
||||
x, y = coord.x, coord.y
|
||||
return (
|
||||
0 <= x < self.COLUMNS
|
||||
and y < self.ROWS
|
||||
@ -336,14 +336,14 @@ class Matrix(Grid):
|
||||
|
||||
# Enter minoes into the matrix
|
||||
for mino in self.piece.minoes:
|
||||
if mino.coord.y() >= 0:
|
||||
self.cells[mino.coord.y()][mino.coord.x()] = mino
|
||||
if mino.coord.y >= 0:
|
||||
self.cells[mino.coord.y][mino.coord.x] = mino
|
||||
mino.shine(glowing=2, delay=consts.ANIMATION_DELAY)
|
||||
QtCore.QTimer.singleShot(consts.ANIMATION_DELAY, self.update)
|
||||
self.update()
|
||||
|
||||
if all(
|
||||
mino.coord.y() < consts.GRID_INVISIBLE_ROWS for mino in self.piece.minoes
|
||||
mino.coord.y < consts.GRID_INVISIBLE_ROWS for mino in self.piece.minoes
|
||||
):
|
||||
self.frames.game_over()
|
||||
return
|
||||
|
15
point.py
15
point.py
@ -11,6 +11,9 @@ class Point(QtCore.QPoint):
|
||||
Point of coordinates (x, y)
|
||||
"""
|
||||
|
||||
x = property(QtCore.QPoint.x, QtCore.QPoint.setX)
|
||||
y = property(QtCore.QPoint.y, QtCore.QPoint.setY)
|
||||
|
||||
def rotate(self, center, direction=CLOCKWISE):
|
||||
""" Returns the Point image of the rotation of self
|
||||
through 90° CLOKWISE or COUNTERCLOCKWISE around center"""
|
||||
@ -18,21 +21,21 @@ class Point(QtCore.QPoint):
|
||||
return self
|
||||
|
||||
p = self - center
|
||||
p = Point(-direction * p.y(), direction * p.x())
|
||||
p = Point(-direction * p.y, direction * p.x)
|
||||
p += center
|
||||
return p
|
||||
|
||||
def __add__(self, o):
|
||||
return Point(self.x() + o.x(), self.y() + o.y())
|
||||
return Point(self.x + o.x, self.y + o.y)
|
||||
|
||||
def __sub__(self, o):
|
||||
return Point(self.x() - o.x(), self.y() - o.y())
|
||||
return Point(self.x - o.x, self.y - o.y)
|
||||
|
||||
def __mul__(self, k):
|
||||
return Point(k * self.x(), k * self.y())
|
||||
return Point(k * self.x, k * self.y)
|
||||
|
||||
def __truediv__(self, k):
|
||||
return Point(self.x() / k, self.y() / k)
|
||||
return Point(self.x / k, self.y / k)
|
||||
|
||||
__radd__ = __add__
|
||||
__rsub__ = __sub__
|
||||
@ -40,6 +43,6 @@ class Point(QtCore.QPoint):
|
||||
__rtruediv__ = __truediv__
|
||||
|
||||
def __repr__(self):
|
||||
return "Point({}, {})".format(self.x(), self.y())
|
||||
return "Point({}, {})".format(self.x, self.y)
|
||||
|
||||
__str__ = __repr__
|
||||
|
14
tetromino.py
14
tetromino.py
@ -54,8 +54,8 @@ class Block:
|
||||
painter.setBrush(fill)
|
||||
painter.setPen(QtCore.Qt.NoPen)
|
||||
painter.drawRoundedRect(
|
||||
start.x(),
|
||||
start.y(),
|
||||
start.x,
|
||||
start.y,
|
||||
Block.side,
|
||||
Block.side * (1 + self.trail),
|
||||
20,
|
||||
@ -71,8 +71,8 @@ class Block:
|
||||
painter.setBrush(QtGui.QBrush(fill))
|
||||
painter.setPen(QtCore.Qt.NoPen)
|
||||
painter.drawEllipse(
|
||||
self.center.x() - self.glowing * Block.side,
|
||||
self.center.y() - self.glowing * Block.side,
|
||||
self.center.x - self.glowing * Block.side,
|
||||
self.center.y - self.glowing * Block.side,
|
||||
2 * self.glowing * Block.side,
|
||||
2 * self.glowing * Block.side,
|
||||
)
|
||||
@ -80,8 +80,8 @@ class Block:
|
||||
painter.setBrush(self.brush())
|
||||
painter.setPen(self.pen())
|
||||
painter.drawRoundedRect(
|
||||
p.x() + 1,
|
||||
p.y() + 1,
|
||||
p.x + 1,
|
||||
p.y + 1,
|
||||
Block.side - 2,
|
||||
Block.side - 2,
|
||||
20,
|
||||
@ -417,6 +417,6 @@ class GhostPiece(Tetromino):
|
||||
def __init__(self, piece):
|
||||
self.matrix = piece.matrix
|
||||
self.minoes = tuple(
|
||||
GhostBlock(Point(mino.coord.x(), mino.coord.y())) for mino in piece.minoes
|
||||
GhostBlock(Point(mino.coord.x, mino.coord.y)) for mino in piece.minoes
|
||||
)
|
||||
self.hard_drop(show_trail=False, update=False)
|
||||
|
Loading…
x
Reference in New Issue
Block a user