mirror of
https://github.com/kuhyx/testsAndMisc-archive.git
synced 2026-11-24 20:56:18 +01:00
refactor: clean up pyproject.toml - remove defaults and redundant configs
This commit is contained in:
parent
134d606db0
commit
f7839ddff2
@ -93,6 +93,15 @@ class KeyboardState:
|
|||||||
positions: dict[str, pygame.Rect] = field(default_factory=dict)
|
positions: dict[str, pygame.Rect] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class FontSet:
|
||||||
|
"""Collection of fonts used in the game."""
|
||||||
|
|
||||||
|
normal: pygame.font.Font
|
||||||
|
large: pygame.font.Font
|
||||||
|
small: pygame.font.Font
|
||||||
|
|
||||||
|
|
||||||
class KeyboardCoopGame:
|
class KeyboardCoopGame:
|
||||||
"""Main game class for the keyboard cooperative word game."""
|
"""Main game class for the keyboard cooperative word game."""
|
||||||
|
|
||||||
@ -101,9 +110,11 @@ class KeyboardCoopGame:
|
|||||||
self.screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
self.screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
||||||
pygame.display.set_caption("Keyboard Coop Game")
|
pygame.display.set_caption("Keyboard Coop Game")
|
||||||
self.clock = pygame.time.Clock()
|
self.clock = pygame.time.Clock()
|
||||||
self.font = pygame.font.Font(None, 24)
|
self.fonts = FontSet(
|
||||||
self.large_font = pygame.font.Font(None, 32)
|
normal=pygame.font.Font(None, 24),
|
||||||
self.small_font = pygame.font.Font(None, 20)
|
large=pygame.font.Font(None, 32),
|
||||||
|
small=pygame.font.Font(None, 20),
|
||||||
|
)
|
||||||
|
|
||||||
# Load dictionary
|
# Load dictionary
|
||||||
self.dictionary = self._load_dictionary()
|
self.dictionary = self._load_dictionary()
|
||||||
@ -397,7 +408,7 @@ class KeyboardCoopGame:
|
|||||||
pygame.draw.rect(self.screen, TEXT_COLOR, rect, 2)
|
pygame.draw.rect(self.screen, TEXT_COLOR, rect, 2)
|
||||||
|
|
||||||
# Draw letter
|
# Draw letter
|
||||||
text = self.small_font.render(letter.upper(), True, TEXT_COLOR)
|
text = self.fonts.small.render(letter.upper(), True, TEXT_COLOR)
|
||||||
text_rect = text.get_rect(center=rect.center)
|
text_rect = text.get_rect(center=rect.center)
|
||||||
self.screen.blit(text, text_rect)
|
self.screen.blit(text, text_rect)
|
||||||
|
|
||||||
@ -412,27 +423,29 @@ class KeyboardCoopGame:
|
|||||||
"""Draw a button with the given label."""
|
"""Draw a button with the given label."""
|
||||||
pygame.draw.rect(self.screen, KEY_COLOR, rect)
|
pygame.draw.rect(self.screen, KEY_COLOR, rect)
|
||||||
pygame.draw.rect(self.screen, TEXT_COLOR, rect, 2)
|
pygame.draw.rect(self.screen, TEXT_COLOR, rect, 2)
|
||||||
text = self.small_font.render(label, True, TEXT_COLOR)
|
text = self.fonts.small.render(label, True, TEXT_COLOR)
|
||||||
self.screen.blit(text, text.get_rect(center=rect.center))
|
self.screen.blit(text, text.get_rect(center=rect.center))
|
||||||
|
|
||||||
def _draw_ui(self) -> tuple[pygame.Rect, pygame.Rect]:
|
def _draw_ui(self) -> tuple[pygame.Rect, pygame.Rect]:
|
||||||
"""Draw the user interface."""
|
"""Draw the user interface."""
|
||||||
# Title and status
|
# Title and status
|
||||||
self._draw_text_line("Keyboard Coop Game", (30, 20), self.large_font)
|
self._draw_text_line("Keyboard Coop Game", (30, 20), self.fonts.large)
|
||||||
self._draw_text_line(
|
self._draw_text_line(
|
||||||
f"Current Word: {self.state.current_word.upper()}", (30, 50), self.font
|
f"Current Word: {self.state.current_word.upper()}",
|
||||||
|
(30, 50),
|
||||||
|
self.fonts.normal,
|
||||||
)
|
)
|
||||||
self._draw_text_line(f"Score: {self.state.score}", (30, 75), self.font)
|
self._draw_text_line(f"Score: {self.state.score}", (30, 75), self.fonts.normal)
|
||||||
|
|
||||||
# Current player with color
|
# Current player with color
|
||||||
player_color = PLAYER_COLORS[self.state.current_player]
|
player_color = PLAYER_COLORS[self.state.current_player]
|
||||||
player_text = self.font.render(
|
player_text = self.fonts.normal.render(
|
||||||
f"Current Player: {self.state.current_player + 1}", True, player_color
|
f"Current Player: {self.state.current_player + 1}", True, player_color
|
||||||
)
|
)
|
||||||
self.screen.blit(player_text, (30, 100))
|
self.screen.blit(player_text, (30, 100))
|
||||||
|
|
||||||
# Message
|
# Message
|
||||||
self._draw_text_line(self.state.message, (30, 125), self.font)
|
self._draw_text_line(self.state.message, (30, 125), self.fonts.normal)
|
||||||
|
|
||||||
# Instructions
|
# Instructions
|
||||||
instructions = [
|
instructions = [
|
||||||
@ -446,7 +459,7 @@ class KeyboardCoopGame:
|
|||||||
"• Keyboard randomizes after each valid word!",
|
"• Keyboard randomizes after each valid word!",
|
||||||
]
|
]
|
||||||
for idx, instruction in enumerate(instructions):
|
for idx, instruction in enumerate(instructions):
|
||||||
self._draw_text_line(instruction, (750, 20 + idx * 22), self.small_font)
|
self._draw_text_line(instruction, (750, 20 + idx * 22), self.fonts.small)
|
||||||
|
|
||||||
# Buttons
|
# Buttons
|
||||||
enter_rect = pygame.Rect(750, 190, 120, 40)
|
enter_rect = pygame.Rect(750, 190, 120, 40)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user