This commit is contained in:
Kristofers Solo 2024-01-08 18:46:23 +02:00
parent e6a2b474e6
commit 12776ee181
14 changed files with 23 additions and 78 deletions

View File

@ -1,8 +1,5 @@
from abc import ABC, ABCMeta, abstractmethod from abc import ABC, ABCMeta, abstractmethod
from typing import TYPE_CHECKING from typing import Any
if TYPE_CHECKING:
from typing import Any
class BaseScreen(ABC, metaclass=ABCMeta): class BaseScreen(ABC, metaclass=ABCMeta):

View File

@ -1,8 +1,5 @@
from abc import ABC, ABCMeta, abstractmethod from abc import ABC, ABCMeta, abstractmethod
from typing import TYPE_CHECKING from typing import Any, Callable, Optional
if TYPE_CHECKING:
from typing import Any, Callable, Optional
import pygame import pygame

View File

@ -1,4 +1,4 @@
from typing import TYPE_CHECKING from typing import Any, Callable, Optional
import pygame import pygame
from utils import CONFIG from utils import CONFIG
@ -6,9 +6,6 @@ from utils import CONFIG
from .base import BaseScreen, SceenElement, TextScreen from .base import BaseScreen, SceenElement, TextScreen
from .base_button import BaseButton from .base_button import BaseButton
if TYPE_CHECKING:
from typing import Any, Callable, Optional
class Button(BaseButton, BaseScreen, SceenElement, TextScreen): class Button(BaseButton, BaseScreen, SceenElement, TextScreen):
def __init__(self, text: str, action: Optional[Callable[[], Optional[Any]]]) -> None: def __init__(self, text: str, action: Optional[Callable[[], Optional[Any]]]) -> None:

View File

@ -1,18 +1,13 @@
from typing import TYPE_CHECKING from typing import Any
import pygame import pygame
from utils import CONFIG, GameMode from utils import CONFIG, Figure, GameMode
from .base import BaseScreen from .base import BaseScreen
from .preview import Preview from .preview import Preview
from .score import Score from .score import Score
from .tetris import Tetris from .tetris import Tetris
if TYPE_CHECKING:
from typing import Any
from utils import Figure
class Game(BaseScreen): class Game(BaseScreen):
""" """
@ -56,14 +51,12 @@ class Game(BaseScreen):
def run(self) -> None: def run(self) -> None:
"""Run a single iteration of the game loop.""" """Run a single iteration of the game loop."""
self.draw()
self.tetris.run() self.tetris.run()
self.score.run() self.score.run()
self.preview.update(self.next_figure) self.preview.update(self.next_figure)
self.preview.run() self.preview.run()
self.draw()
self.clock.tick(CONFIG.game.fps) self.clock.tick(CONFIG.game.fps)
def mute(self) -> None: def mute(self) -> None:

View File

@ -1,19 +1,14 @@
import sys import sys
from typing import TYPE_CHECKING from typing import Optional
import pygame import pygame
from loguru import logger from loguru import logger
from utils import CONFIG, read_settings from utils import CONFIG, GameMode, read_settings
from .base import BaseScreen, SceenElement, TextScreen from .base import BaseScreen, SceenElement, TextScreen
from .button import Button from .button import Button
from .game import Game from .game import Game
if TYPE_CHECKING:
from typing import Optional
from utils import GameMode
class Main(BaseScreen, SceenElement, TextScreen): class Main(BaseScreen, SceenElement, TextScreen):
""" """

View File

@ -1,13 +1,8 @@
from typing import TYPE_CHECKING
import pygame import pygame
from utils import CONFIG from utils import CONFIG, Figure
from .base import BaseScreen, SceenElement from .base import BaseScreen, SceenElement
if TYPE_CHECKING:
from utils import Figure
class Preview(BaseScreen, SceenElement): class Preview(BaseScreen, SceenElement):
""" """

View File

@ -1,20 +1,15 @@
from typing import TYPE_CHECKING from typing import Any, Callable, Optional
import numpy as np import numpy as np
import pygame import pygame
from loguru import logger from loguru import logger
from utils import CONFIG, Direction, Figure, GameMode, Rotation from utils import CONFIG, Direction, Figure, GameMode, Rotation
from game.sprites import Tetromino from game.sprites import Block, Tetromino
from game.timer import Timer, Timers from game.timer import Timer, Timers
from .base import BaseScreen from .base import BaseScreen
if TYPE_CHECKING:
from typing import Any, Callable, Optional
from game.sprites import Block
class Tetris(BaseScreen): class Tetris(BaseScreen):
""" """

View File

@ -1,13 +1,9 @@
from typing import TYPE_CHECKING from typing import Any, Optional
import numpy as np
import pygame import pygame
from utils import CONFIG, Rotation from utils import CONFIG, Rotation
if TYPE_CHECKING:
from typing import Any, Optional
import numpy as np
class Block(pygame.sprite.Sprite): class Block(pygame.sprite.Sprite):
""" """

View File

@ -1,14 +1,10 @@
from typing import TYPE_CHECKING from typing import Any, Callable, Optional
import numpy as np
import pygame import pygame
from utils import CONFIG, Direction, Figure, Rotation from utils import CONFIG, Direction, Figure, Rotation
if TYPE_CHECKING: from .block import Block
from typing import Any, Callable, Optional
import numpy as np
from .block import Block
class Tetromino: class Tetromino:

View File

@ -1,11 +1,8 @@
from typing import TYPE_CHECKING from typing import Any, Callable, NamedTuple, Optional
import pygame import pygame
from attrs import define, field from attrs import define, field
if TYPE_CHECKING:
from typing import Any, Callable, NamedTuple, Optional
@define @define
class Timer: class Timer:

View File

@ -1,6 +1,7 @@
from typing import TYPE_CHECKING from pathlib import Path
from attr import define from attr import define
from pygame import Vector2 as Vec2
from .colors import COLOR_DICT, TokyoNightNight from .colors import COLOR_DICT, TokyoNightNight
from .colors.tokyonight.base import Color from .colors.tokyonight.base import Color
@ -8,12 +9,6 @@ from .path import BASE_PATH
from .settings import read_settings from .settings import read_settings
from .tuples import Size from .tuples import Size
if TYPE_CHECKING:
from pathlib import Path
from pygame import Vector2 as Vec2
PADDING = 20 PADDING = 20

View File

@ -1,15 +1,13 @@
import random import random
from enum import Enum from enum import Enum
from typing import TYPE_CHECKING, NamedTuple from typing import NamedTuple
import pygame import pygame
from pygame import Vector2 as Vec2
from .colors import TokyoNightNight from .colors import TokyoNightNight
from .path import BASE_PATH from .path import BASE_PATH
if TYPE_CHECKING:
from pygame import Vector2 as Vec2
class FigureConfig(NamedTuple): class FigureConfig(NamedTuple):
""" """

View File

@ -1,14 +1,11 @@
from typing import TYPE_CHECKING from pathlib import Path
from typing import Any
import toml import toml
from loguru import logger from loguru import logger
from .path import BASE_PATH from .path import BASE_PATH
if TYPE_CHECKING:
from pathlib import Path
from typing import Any
def save_settings(settings: dict[str, Any], file_path: Path) -> None: def save_settings(settings: dict[str, Any], file_path: Path) -> None:
""" """

View File

@ -1,7 +1,4 @@
from typing import TYPE_CHECKING, NamedTuple from typing import NamedTuple, Union
if TYPE_CHECKING:
from typing import Union
class Size(NamedTuple): class Size(NamedTuple):