Skip to content

Commit

Permalink
Merge pull request #7 from CogitoNTNU/feature/4-tetris-block
Browse files Browse the repository at this point in the history
Feature/4 tetris block
  • Loading branch information
JonBergland authored Mar 19, 2024
2 parents 612991a + 86e9011 commit b0aec4b
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/game/block.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
class Block:
def __init__(self, x, y, blockType):
self.x = x
self.y = y
self.type = blockType
self.color = self.colors[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

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):
return
# If the block is in the figure, calculate the coordinates
## TODO: Fix the coordinates

0 comments on commit b0aec4b

Please sign in to comment.