Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified .gitattributes
100644 → 100755
Empty file.
Empty file modified .github/FUNDING.yml
100644 → 100755
Empty file.
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Virtual environments
.venv/
venv/
env/

# Python bytecode
__pycache__/
*.py[cod]
*.pyo

# Distribution / packaging
dist/
build/
*.egg-info/
*.egg

# Tool caches
.mypy_cache/
.ruff_cache/
.pytest_cache/

# Misc
*.log
.DS_Store
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified Sounds/clear.ogg
100644 → 100755
Empty file.
Empty file modified Sounds/music.ogg
100644 → 100755
Empty file.
Empty file modified Sounds/rotate.ogg
100644 → 100755
Empty file.
65 changes: 33 additions & 32 deletions block.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,42 @@
import pygame
from position import Position


class Block:
def __init__(self, id):
self.id = id
self.cells = {}
self.cell_size = 30
self.row_offset = 0
self.column_offset = 0
self.rotation_state = 0
self.colors = Colors.get_cell_colors()
def __init__(self, id: int) -> None:
self.id: int = id
self.cells: dict[int, list[Position]] = {}
self.cell_size: int = 30
self.row_offset: int = 0
self.column_offset: int = 0
self.rotation_state: int = 0
self.colors: list[tuple[int, int, int]] = Colors.get_cell_colors()

def move(self, rows, columns):
self.row_offset += rows
self.column_offset += columns
def move(self, rows: int, columns: int) -> None:
self.row_offset += rows
self.column_offset += columns

def get_cell_positions(self):
tiles = self.cells[self.rotation_state]
moved_tiles = []
for position in tiles:
position = Position(position.row + self.row_offset, position.column + self.column_offset)
moved_tiles.append(position)
return moved_tiles
def get_cell_positions(self) -> list[Position]:
tiles = self.cells[self.rotation_state]
moved_tiles: list[Position] = []
for position in tiles:
position = Position(position.row + self.row_offset, position.column + self.column_offset)
moved_tiles.append(position)
return moved_tiles

def rotate(self):
self.rotation_state += 1
if self.rotation_state == len(self.cells):
self.rotation_state = 0
def rotate(self) -> None:
self.rotation_state += 1
if self.rotation_state == len(self.cells):
self.rotation_state = 0

def undo_rotation(self):
self.rotation_state -= 1
if self.rotation_state == -1:
self.rotation_state = len(self.cells) - 1
def undo_rotation(self) -> None:
self.rotation_state -= 1
if self.rotation_state == -1:
self.rotation_state = len(self.cells) - 1

def draw(self, screen, offset_x, offset_y):
tiles = self.get_cell_positions()
for tile in tiles:
tile_rect = pygame.Rect(offset_x + tile.column * self.cell_size,
offset_y + tile.row * self.cell_size, self.cell_size -1, self.cell_size -1)
pygame.draw.rect(screen, self.colors[self.id], tile_rect)
def draw(self, screen: pygame.Surface, offset_x: int, offset_y: int) -> None:
tiles = self.get_cell_positions()
for tile in tiles:
tile_rect = pygame.Rect(offset_x + tile.column * self.cell_size,
offset_y + tile.row * self.cell_size, self.cell_size - 1, self.cell_size - 1)
pygame.draw.rect(screen, self.colors[self.id], tile_rect)
51 changes: 29 additions & 22 deletions blocks.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
from block import Block
from position import Position


class LBlock(Block):
def __init__(self):
super().__init__(id = 1)
self.cells = {
0: [Position(0, 2), Position(1, 0), Position(1, 1), Position(1, 2)],
1: [Position(0, 1), Position(1, 1), Position(2, 1), Position(2, 2)],
2: [Position(1, 0), Position(1, 1), Position(1, 2), Position(2, 0)],
3: [Position(0, 0), Position(0, 1), Position(1, 1), Position(2, 1)]
}
self.move(0, 3)
def __init__(self) -> None:
super().__init__(id=1)
self.cells = {
0: [Position(0, 2), Position(1, 0), Position(1, 1), Position(1, 2)],
1: [Position(0, 1), Position(1, 1), Position(2, 1), Position(2, 2)],
2: [Position(1, 0), Position(1, 1), Position(1, 2), Position(2, 0)],
3: [Position(0, 0), Position(0, 1), Position(1, 1), Position(2, 1)]
}
self.move(0, 3)


class JBlock(Block):
def __init__(self):
super().__init__(id = 2)
def __init__(self) -> None:
super().__init__(id=2)
self.cells = {
0: [Position(0, 0), Position(1, 0), Position(1, 1), Position(1, 2)],
1: [Position(0, 1), Position(0, 2), Position(1, 1), Position(2, 1)],
Expand All @@ -23,9 +25,10 @@ def __init__(self):
}
self.move(0, 3)


class IBlock(Block):
def __init__(self):
super().__init__(id = 3)
def __init__(self) -> None:
super().__init__(id=3)
self.cells = {
0: [Position(1, 0), Position(1, 1), Position(1, 2), Position(1, 3)],
1: [Position(0, 2), Position(1, 2), Position(2, 2), Position(3, 2)],
Expand All @@ -34,17 +37,19 @@ def __init__(self):
}
self.move(-1, 3)


class OBlock(Block):
def __init__(self):
super().__init__(id = 4)
def __init__(self) -> None:
super().__init__(id=4)
self.cells = {
0: [Position(0, 0), Position(0, 1), Position(1, 0), Position(1, 1)]
}
self.move(0, 4)


class SBlock(Block):
def __init__(self):
super().__init__(id = 5)
def __init__(self) -> None:
super().__init__(id=5)
self.cells = {
0: [Position(0, 1), Position(0, 2), Position(1, 0), Position(1, 1)],
1: [Position(0, 1), Position(1, 1), Position(1, 2), Position(2, 2)],
Expand All @@ -53,9 +58,10 @@ def __init__(self):
}
self.move(0, 3)


class TBlock(Block):
def __init__(self):
super().__init__(id = 6)
def __init__(self) -> None:
super().__init__(id=6)
self.cells = {
0: [Position(0, 1), Position(1, 0), Position(1, 1), Position(1, 2)],
1: [Position(0, 1), Position(1, 1), Position(1, 2), Position(2, 1)],
Expand All @@ -64,13 +70,14 @@ def __init__(self):
}
self.move(0, 3)


class ZBlock(Block):
def __init__(self):
super().__init__(id = 7)
def __init__(self) -> None:
super().__init__(id=7)
self.cells = {
0: [Position(0, 0), Position(0, 1), Position(1, 1), Position(1, 2)],
1: [Position(0, 2), Position(1, 1), Position(1, 2), Position(2, 1)],
2: [Position(1, 0), Position(1, 1), Position(2, 1), Position(2, 2)],
3: [Position(0, 1), Position(1, 0), Position(1, 1), Position(2, 0)]
}
self.move(0, 3)
self.move(0, 3)
28 changes: 14 additions & 14 deletions colors.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
class Colors:
dark_grey = (26, 31, 40)
green = (47, 230, 23)
red = (232, 18, 18)
orange = (226, 116, 17)
yellow = (237, 234, 4)
purple = (166, 0, 247)
cyan = (21, 204, 209)
blue = (13, 64, 216)
white = (255, 255, 255)
dark_blue = (44, 44, 127)
light_blue = (59, 85, 162)
dark_grey: tuple[int, int, int] = (26, 31, 40)
green: tuple[int, int, int] = (47, 230, 23)
red: tuple[int, int, int] = (232, 18, 18)
orange: tuple[int, int, int] = (226, 116, 17)
yellow: tuple[int, int, int] = (237, 234, 4)
purple: tuple[int, int, int] = (166, 0, 247)
cyan: tuple[int, int, int] = (21, 204, 209)
blue: tuple[int, int, int] = (13, 64, 216)
white: tuple[int, int, int] = (255, 255, 255)
dark_blue: tuple[int, int, int] = (44, 44, 127)
light_blue: tuple[int, int, int] = (59, 85, 162)

@classmethod
def get_cell_colors(cls):
return [cls.dark_grey, cls.green, cls.red, cls.orange, cls.yellow, cls.purple, cls.cyan, cls.blue]
@classmethod
def get_cell_colors(cls) -> list[tuple[int, int, int]]:
return [cls.dark_grey, cls.green, cls.red, cls.orange, cls.yellow, cls.purple, cls.cyan, cls.blue]
Loading