From 1fc3b1870f788a0e9b10483a7e3967175f5694af Mon Sep 17 00:00:00 2001 From: HFossdal <122976119+HFossdal@users.noreply.github.com> Date: Tue, 5 Mar 2024 18:47:45 +0000 Subject: [PATCH 1/4] feat: :sparkles: Created block Created Block class for Tetris game --- src/game/block.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/game/block.py diff --git a/src/game/block.py b/src/game/block.py new file mode 100644 index 0000000..7eab3d0 --- /dev/null +++ b/src/game/block.py @@ -0,0 +1,57 @@ +class Block: + def __init__self(self, x, y, blockType): + self.x = x + self.y = y + self.type = blockType + self.color = blockType + self.rotation = 0 + + + figures = [ + [[1, 5, 9, 13], [4, 5, 6, 7]], # I + [[4, 5, 9, 10], [2, 6, 5, 9]], # Z + [[6, 7, 9, 10], [1, 5, 6, 10]], # S + [[1, 2, 5, 9], [0, 4, 5, 6], [1, 5, 9, 8], [4, 5, 6, 10]], #L + [[1, 2, 6, 10], [5, 6, 7, 9], [2, 6, 10, 11], [3, 5, 6, 7]], # J + [[1, 4, 5, 6], [1, 4, 5, 9], [4, 5, 6, 9], [1, 5, 6, 9]], # T + [[1, 2, 5, 6]] # O + ] + + # Colors for the blocks + colors = [ + (0, 255, 255), # I + (255, 0, 0), # Z + (0, 255, 0), # S + (255, 165, 0), # L + (0, 0, 255), # J + (128, 0, 128), # T + (255, 255, 0) # O + ] + + def rotate_left(self): + self.rotation = (self.rotation + 1) % len(self.figures[self.type]) + + def rotate_right(self): + self.rotation = (self.rotation - 1) % len(self.figures[self.type]) + + def get_block(self): + return self.figures[self.type][self.rotation] + + def get_color(self): + return self.colors[self.type] + + def get_x(self): + return self.x + + def get_y(self): + return self.y + + def set_x(self, x): + self.x = x + + def set_y(self, y): + self.y = y + + + + From fad286a4559e6af5fc8f6374ea7b3fd164907606 Mon Sep 17 00:00:00 2001 From: HFossdal <122976119+HFossdal@users.noreply.github.com> Date: Tue, 12 Mar 2024 19:59:00 +0100 Subject: [PATCH 2/4] feat: :sparkles: added get_coordinates functions for block added get_coordinates functions for block --- src/game/block.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/game/block.py b/src/game/block.py index 7eab3d0..978ba2e 100644 --- a/src/game/block.py +++ b/src/game/block.py @@ -1,9 +1,9 @@ class Block: - def __init__self(self, x, y, blockType): + def __init__(self, x, y, blockType): self.x = x self.y = y self.type = blockType - self.color = blockType + self.color = self.colors[blockType] self.rotation = 0 @@ -52,6 +52,21 @@ def set_x(self, x): def set_y(self, y): self.y = y + def get_position(self): + return self.x, self.y + def image(self): + return self.figures[self.type][self.rotation] + + def get_block_coordinates(self): + # Calculate the coordinates for each block in the figure + positions = self.figures[self.type][self.rotation] + for i in range(4): + for j in range(4): + # If the block is in the figure, calculate the coordinates + ## TODO: Fix the coordinates + + + From 1caa297c01e97c6f31d4cef8d85479f707fe88c0 Mon Sep 17 00:00:00 2001 From: HFossdal <122976119+HFossdal@users.noreply.github.com> Date: Tue, 19 Mar 2024 17:23:46 +0100 Subject: [PATCH 3/4] feat: :sparkles: updated block.py updated block.py --- src/game/block.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/game/block.py b/src/game/block.py index 978ba2e..48e2a9b 100644 --- a/src/game/block.py +++ b/src/game/block.py @@ -65,8 +65,3 @@ def get_block_coordinates(self): for j in range(4): # If the block is in the figure, calculate the coordinates ## TODO: Fix the coordinates - - - - - From 86e9011a2d81e36322f97c3082700e11bb0a95a1 Mon Sep 17 00:00:00 2001 From: HFossdal <122976119+HFossdal@users.noreply.github.com> Date: Tue, 19 Mar 2024 17:24:29 +0100 Subject: [PATCH 4/4] fix: :bug: fixed non return from a class function fixed non return from a class function --- src/game/block.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/game/block.py b/src/game/block.py index 48e2a9b..3d5d574 100644 --- a/src/game/block.py +++ b/src/game/block.py @@ -63,5 +63,6 @@ def get_block_coordinates(self): positions = self.figures[self.type][self.rotation] for i in range(4): for j in range(4): + return # If the block is in the figure, calculate the coordinates ## TODO: Fix the coordinates