summaryrefslogtreecommitdiff
path: root/cameltris.py
diff options
context:
space:
mode:
Diffstat (limited to 'cameltris.py')
-rwxr-xr-xcameltris.py51
1 files changed, 33 insertions, 18 deletions
diff --git a/cameltris.py b/cameltris.py
index 5ee7984..c97f7c7 100755
--- a/cameltris.py
+++ b/cameltris.py
@@ -13,14 +13,13 @@ class WouldCollide(Exception):
class Piece():
- def rotate(self):
- pass
-
def rotate_clockwise(self):
- self.rotate()
+ self.elements = list(zip(*self.elements[::-1]))
def rotate_counter_clockwise(self):
- self.rotate()
+ self.rotate_clockwise()
+ self.rotate_clockwise()
+ self.rotate_clockwise()
class ZPiece(Piece):
@@ -28,6 +27,12 @@ class ZPiece(Piece):
self.elements = (blue_square, blue_square, None), (None, blue_square, blue_square), (None, None, None)
self.vertical = False
+ def rotate_clockwise(self):
+ self.rotate()
+
+ def rotate_counter_clockwise(self):
+ self.rotate()
+
def rotate(self):
if self.vertical:
self.elements = (blue_square, blue_square, None), (None, blue_square, blue_square), (None, None, None)
@@ -42,6 +47,12 @@ class SPiece(Piece):
self.elements = (None, None, None), (None, green_square, green_square), (green_square, green_square, None)
self.vertical = False
+ def rotate_clockwise(self):
+ self.rotate()
+
+ def rotate_counter_clockwise(self):
+ self.rotate()
+
def rotate(self):
if self.vertical:
self.elements = (None, green_square, green_square), (green_square, green_square, None), (None, None, None)
@@ -61,6 +72,12 @@ class IPiece(Piece):
self.elements = (None, None, None, None), (None, None, None, None), (red_square, red_square, red_square, red_square), (None, None, None, None)
self.vertical = False
+ def rotate_clockwise(self):
+ self.rotate()
+
+ def rotate_counter_clockwise(self):
+ self.rotate()
+
def rotate(self):
if self.vertical:
self.elements = (None, None, None, None), (None, None, None, None), (red_square, red_square, red_square, red_square), (None, None, None, None)
@@ -70,21 +87,19 @@ class IPiece(Piece):
self.vertical = not self.vertical
-class TPiece(Piece):
+class LPiece(Piece):
def __init__(self):
- self.elements = [[yellow_square, yellow_square, yellow_square], [None, yellow_square, None], [None, None, None]]
+ self.elements = (None, None, None), (red_square, red_square, red_square), (None, None, red_square)
- def rotate_clockwise(self):
- # Set the corners
- self.elements[0][0], self.elements[0][2], self.elements[2][2], self.elements[2][0] = self.elements[2][0], self.elements[0][0], self.elements[0][2], self.elements[2][2]
- # Set the middle squares
- self.elements[0][1], self.elements[1][2], self.elements[2][1], self.elements[1][0] = self.elements[1][0], self.elements[0][1], self.elements[1][2], self.elements[2][1]
- def rotate_counter_clockwise(self):
- # Set the corners
- self.elements[2][0], self.elements[0][0], self.elements[0][2], self.elements[2][2] = self.elements[0][0], self.elements[0][2], self.elements[2][2], self.elements[2][0]
- # Set the middle squares
- self.elements[1][0], self.elements[0][1], self.elements[1][2], self.elements[2][1] = self.elements[0][1], self.elements[1][2], self.elements[2][1], self.elements[1][0]
+class JPiece(Piece):
+ def __init__(self):
+ self.elements = (None, None, None), (blue_square, blue_square, blue_square), (blue_square, None, None)
+
+
+class TPiece(Piece):
+ def __init__(self):
+ self.elements = [[yellow_square, yellow_square, yellow_square], [None, yellow_square, None], [None, None, None]]
def refresh_game_canvas():
@@ -193,7 +208,7 @@ def rotate_piece_clockwise():
def generate_piece():
- piece = random.choice((TPiece, SPiece, IPiece, ZPiece, SquarePiece))()
+ piece = random.choice((TPiece, SPiece, IPiece, ZPiece, SquarePiece, LPiece, JPiece))()
for row_id, row in enumerate(piece.elements):
if list(filter(lambda x: x is not None, row)):