mirror of
https://github.com/kristoferssolo/Tetris.git
synced 2025-10-21 20:00:35 +00:00
docs: update docstrings
This commit is contained in:
parent
a0ff4a438d
commit
29cc83a2ac
@ -36,10 +36,18 @@ class Game(BaseScreen):
|
|||||||
self._start_background_music()
|
self._start_background_music()
|
||||||
|
|
||||||
def draw(self) -> None:
|
def draw(self) -> None:
|
||||||
"""Update the display."""
|
"""
|
||||||
|
Raises:
|
||||||
|
NotImplementedError: Not implemented yet.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
def update(self) -> None:
|
def update(self) -> None:
|
||||||
pass
|
"""
|
||||||
|
Raises:
|
||||||
|
NotImplementedError: Not implemented yet.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
"""Run a single iteration of the game loop."""
|
"""Run a single iteration of the game loop."""
|
||||||
|
|||||||
@ -103,7 +103,11 @@ class Main(BaseScreen, SceenElement, TextScreen):
|
|||||||
self.display_surface.fill(CONFIG.colors.bg)
|
self.display_surface.fill(CONFIG.colors.bg)
|
||||||
|
|
||||||
def _draw_border(self) -> None:
|
def _draw_border(self) -> None:
|
||||||
"""Draw a border (not implemented)."""
|
"""
|
||||||
|
Raises:
|
||||||
|
NotImplementedError: Not implemented yet.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
def _initialize_surface(self) -> None:
|
def _initialize_surface(self) -> None:
|
||||||
"""Initialize the display surface."""
|
"""Initialize the display surface."""
|
||||||
@ -114,7 +118,11 @@ class Main(BaseScreen, SceenElement, TextScreen):
|
|||||||
self.rect = self.display_surface.get_rect(topright=(0, 0))
|
self.rect = self.display_surface.get_rect(topright=(0, 0))
|
||||||
|
|
||||||
def _update_display_surface(self) -> None:
|
def _update_display_surface(self) -> None:
|
||||||
"""Update display surface (not implemented)."""
|
"""
|
||||||
|
Raises:
|
||||||
|
NotImplementedError: Not implemented yet.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
def _initialize_increment_height(self) -> None:
|
def _initialize_increment_height(self) -> None:
|
||||||
"""Initialize the increment height for positioning text elements/buttons."""
|
"""Initialize the increment height for positioning text elements/buttons."""
|
||||||
|
|||||||
@ -50,13 +50,7 @@ class Preview(BaseScreen, SceenElement):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def _draw_figure(self) -> None:
|
def _draw_figure(self) -> None:
|
||||||
"""
|
"""Draw a single upcoming figure on the preview surface."""
|
||||||
Draw a single upcoming figure on the preview surface.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
figure (Figure): The upcoming figure to draw.
|
|
||||||
idx (int): Index of the figure in the list.
|
|
||||||
"""
|
|
||||||
figure_surface = self.next_figure.value.image
|
figure_surface = self.next_figure.value.image
|
||||||
x = self.surface.get_width() / 2
|
x = self.surface.get_width() / 2
|
||||||
y = self.surface.get_height() / 2
|
y = self.surface.get_height() / 2
|
||||||
|
|||||||
@ -67,9 +67,9 @@ class Score(BaseScreen, SceenElement, TextScreen):
|
|||||||
Update the score information.
|
Update the score information.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
lines (int): Number of lines cleared.
|
lines: Number of lines cleared.
|
||||||
score (int): Current game score.
|
score: Current game score.
|
||||||
level (int): Current game level.
|
level: Current game level.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if score > self.highscore:
|
if score > self.highscore:
|
||||||
|
|||||||
@ -14,6 +14,27 @@ PADDING = 20
|
|||||||
|
|
||||||
@define
|
@define
|
||||||
class Game:
|
class Game:
|
||||||
|
"""
|
||||||
|
Attributes:
|
||||||
|
columns: The number of columns.
|
||||||
|
rows: The number of rows.
|
||||||
|
line_width: The width of the lines.
|
||||||
|
border_radius: The radius of the border.
|
||||||
|
padding: The padding.
|
||||||
|
cell: The size of a cell.
|
||||||
|
size: The size of the game.
|
||||||
|
pos: The position of the game.
|
||||||
|
offset: The offset of the game.
|
||||||
|
initial_speed: The initial speed of the game.
|
||||||
|
movment_delay: The delay of the movment.
|
||||||
|
rotation_delay: The delay of the rotation.
|
||||||
|
drop_delay: The delay of the drop.
|
||||||
|
score: The score.
|
||||||
|
highscore: The path to the highscore file.
|
||||||
|
fps: The FPS.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
columns: int = 10
|
columns: int = 10
|
||||||
rows: int = 20
|
rows: int = 20
|
||||||
line_width: int = 1
|
line_width: int = 1
|
||||||
@ -34,6 +55,14 @@ class Game:
|
|||||||
|
|
||||||
@define
|
@define
|
||||||
class SideBar:
|
class SideBar:
|
||||||
|
"""
|
||||||
|
Attributes:
|
||||||
|
padding: The padding.
|
||||||
|
size: The size of the sidebar.
|
||||||
|
score: The size of the score.
|
||||||
|
preview: The size of the preview.
|
||||||
|
"""
|
||||||
|
|
||||||
padding: int = PADDING
|
padding: int = PADDING
|
||||||
size: Size = Size(200, Game().size.height)
|
size: Size = Size(200, Game().size.height)
|
||||||
score: Size = Size(size.width, size.height - size.width - padding)
|
score: Size = Size(size.width, size.height - size.width - padding)
|
||||||
@ -42,17 +71,36 @@ class SideBar:
|
|||||||
|
|
||||||
@define
|
@define
|
||||||
class Font:
|
class Font:
|
||||||
|
"""
|
||||||
|
Attributes:
|
||||||
|
family: The font family.
|
||||||
|
size: The font size.
|
||||||
|
"""
|
||||||
|
|
||||||
family: Path = BASE_PATH / "assets" / "fonts" / "ChakraPetch" / "Regular.ttf"
|
family: Path = BASE_PATH / "assets" / "fonts" / "ChakraPetch" / "Regular.ttf"
|
||||||
size: int = 32
|
size: int = 32
|
||||||
|
|
||||||
|
|
||||||
@define
|
@define
|
||||||
class Button:
|
class Button:
|
||||||
|
"""
|
||||||
|
Attributes:
|
||||||
|
size: The size of the button.
|
||||||
|
"""
|
||||||
|
|
||||||
size: Size = Size(200, 50)
|
size: Size = Size(200, 50)
|
||||||
|
|
||||||
|
|
||||||
@define
|
@define
|
||||||
class Window:
|
class Window:
|
||||||
|
"""
|
||||||
|
Attributes:
|
||||||
|
title: The title of the window.
|
||||||
|
padding: The padding.
|
||||||
|
size: The size of the window.
|
||||||
|
button: The button.
|
||||||
|
"""
|
||||||
|
|
||||||
title: str = "Tetris"
|
title: str = "Tetris"
|
||||||
padding: int = PADDING
|
padding: int = PADDING
|
||||||
size: Size = Size(
|
size: Size = Size(
|
||||||
@ -64,12 +112,28 @@ class Window:
|
|||||||
|
|
||||||
@define
|
@define
|
||||||
class Music:
|
class Music:
|
||||||
|
"""
|
||||||
|
Attributes:
|
||||||
|
background: The background music.
|
||||||
|
landing: The landing music.
|
||||||
|
"""
|
||||||
|
|
||||||
background: Path = BASE_PATH / "assets" / "music" / "background.mp3"
|
background: Path = BASE_PATH / "assets" / "music" / "background.mp3"
|
||||||
landing: Path = BASE_PATH / "assets" / "music" / "landing.wav"
|
landing: Path = BASE_PATH / "assets" / "music" / "landing.wav"
|
||||||
|
|
||||||
|
|
||||||
@define
|
@define
|
||||||
class Config:
|
class Config:
|
||||||
|
"""
|
||||||
|
Attributes:
|
||||||
|
game: The game.
|
||||||
|
sidebar: The sidebar.
|
||||||
|
window: The window.
|
||||||
|
font: The font.
|
||||||
|
music: The music.
|
||||||
|
colors: The colors.
|
||||||
|
"""
|
||||||
|
|
||||||
game: Game = Game()
|
game: Game = Game()
|
||||||
sidebar: SideBar = SideBar()
|
sidebar: SideBar = SideBar()
|
||||||
window: Window = Window()
|
window: Window = Window()
|
||||||
|
|||||||
@ -2,6 +2,16 @@ from enum import Enum, auto
|
|||||||
|
|
||||||
|
|
||||||
class Direction(Enum):
|
class Direction(Enum):
|
||||||
|
"""
|
||||||
|
Enum for direction of movement.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
LEFT: Left direction
|
||||||
|
RIGHT: Right direction
|
||||||
|
DOWN: Down direction
|
||||||
|
UP: Up direction
|
||||||
|
"""
|
||||||
|
|
||||||
LEFT = -1
|
LEFT = -1
|
||||||
RIGHT = 1
|
RIGHT = 1
|
||||||
DOWN = 1
|
DOWN = 1
|
||||||
@ -9,11 +19,28 @@ class Direction(Enum):
|
|||||||
|
|
||||||
|
|
||||||
class Rotation(Enum):
|
class Rotation(Enum):
|
||||||
|
"""
|
||||||
|
Enum for rotation of movement.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
CLOCKWISE: Clockwise rotation
|
||||||
|
COUNTER_CLOCKWISE: Counter clockwise rotation
|
||||||
|
"""
|
||||||
|
|
||||||
CLOCKWISE = 90
|
CLOCKWISE = 90
|
||||||
COUNTER_CLOCKWISE = -90
|
COUNTER_CLOCKWISE = -90
|
||||||
|
|
||||||
|
|
||||||
class GameMode(Enum):
|
class GameMode(Enum):
|
||||||
|
"""
|
||||||
|
Enum for game mode.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
PLAYER: Player mode
|
||||||
|
AI_PLAYING: AI playing mode
|
||||||
|
AI_TRAINING: AI training mode
|
||||||
|
"""
|
||||||
|
|
||||||
PLAYER = auto()
|
PLAYER = auto()
|
||||||
AI_PLAYING = auto()
|
AI_PLAYING = auto()
|
||||||
AI_TRAINING = auto()
|
AI_TRAINING = auto()
|
||||||
|
|||||||
@ -10,6 +10,13 @@ from .path import BASE_PATH
|
|||||||
|
|
||||||
|
|
||||||
class FigureConfig(NamedTuple):
|
class FigureConfig(NamedTuple):
|
||||||
|
"""
|
||||||
|
Attributes:
|
||||||
|
shape: The shape of the figure.
|
||||||
|
color: The color of the figure.
|
||||||
|
image: The image of the figure.
|
||||||
|
"""
|
||||||
|
|
||||||
shape: list[Vec2]
|
shape: list[Vec2]
|
||||||
color: str
|
color: str
|
||||||
image: pygame.Surface
|
image: pygame.Surface
|
||||||
@ -23,6 +30,17 @@ def _load_image(filename: str) -> pygame.Surface:
|
|||||||
|
|
||||||
|
|
||||||
class Figure(Enum):
|
class Figure(Enum):
|
||||||
|
"""
|
||||||
|
Attributes:
|
||||||
|
I: The I figure.
|
||||||
|
O: The O figure.
|
||||||
|
T: The T figure.
|
||||||
|
S: The S figure.
|
||||||
|
Z: The Z figure.
|
||||||
|
J: The J figure.
|
||||||
|
L: The L figure.
|
||||||
|
"""
|
||||||
|
|
||||||
I = FigureConfig(
|
I = FigureConfig(
|
||||||
[
|
[
|
||||||
Vec2(0, 0),
|
Vec2(0, 0),
|
||||||
|
|||||||
@ -8,6 +8,13 @@ from .path import BASE_PATH
|
|||||||
|
|
||||||
|
|
||||||
def save_settings(settings: dict[str, Any], file_path: Path) -> None:
|
def save_settings(settings: dict[str, Any], file_path: Path) -> None:
|
||||||
|
"""
|
||||||
|
Save the settings to a TOML file.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
settings: The settings to save.
|
||||||
|
file_path: The path to the TOML file.
|
||||||
|
"""
|
||||||
with open(file_path, "w") as file:
|
with open(file_path, "w") as file:
|
||||||
toml.dump(settings, file)
|
toml.dump(settings, file)
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,14 @@ from typing import NamedTuple, Union
|
|||||||
|
|
||||||
|
|
||||||
class Size(NamedTuple):
|
class Size(NamedTuple):
|
||||||
|
"""
|
||||||
|
A size object.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
width: The width of the object.
|
||||||
|
height: The height of the object.
|
||||||
|
"""
|
||||||
|
|
||||||
width: int | float
|
width: int | float
|
||||||
height: int | float
|
height: int | float
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user