Skip to content

Commit

Permalink
Fix: grid now enlarges visually
Browse files Browse the repository at this point in the history
  • Loading branch information
Godsmith committed Aug 30, 2023
1 parent 5e710d0 commit c2e9321
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 23 deletions.
16 changes: 2 additions & 14 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,8 @@ def update_score(self, value, level, score_to_grid_increase):


@pytest.fixture
def mock_drawer():
class MockDrawer:
def __init__(self, width, height) -> None:
pass

def enlarge_grid(self):
pass

return MockDrawer


@pytest.fixture
def player(mock_gui, mock_drawer):
return Player(mock_gui(), mock_drawer(800, 600))
def player(mock_gui):
return Player(mock_gui(), lambda: None)


@pytest.fixture
Expand Down
6 changes: 5 additions & 1 deletion trainfinity2/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def setup(self, terrain: Terrain):
self.grid.add_observer(self.drawer, RailsBeingBuiltEvent)
self.grid.create_buildings()

self.player = Player(self.gui, self.grid)
self.player = Player(self.gui, self.enlarge_grid)

self.iron_counter = 0

Expand Down Expand Up @@ -297,3 +297,7 @@ def on_resize(self, width, height):
self.camera.resize(width, height)
self.gui_camera.resize(width, height)
self.camera.set_viewport()

def enlarge_grid(self):
self.grid.enlarge_grid()
self.drawer.upsert(self.grid)
6 changes: 3 additions & 3 deletions trainfinity2/model.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from dataclasses import dataclass, replace
from enum import Enum, auto
from typing import Callable

from pyglet.math import Vec2

from .gui import Gui
from .observer import ChangeEvent, Event, Subject
from .protocols import GridEnlarger


@dataclass
Expand Down Expand Up @@ -80,7 +80,7 @@ def get_level_scores() -> list[int]:
@dataclass
class Player:
gui: Gui
grid_enlarger: GridEnlarger
enlarge_grid: Callable[[], None]
_score: int = 0
_level = 0

Expand All @@ -98,7 +98,7 @@ def score(self, value):
self._score = value
while self._score >= self.LEVELS[self._level + 1]:
self._level += 1
self.grid_enlarger.enlarge_grid()
self.enlarge_grid()
self.gui.update_score(value, self._level, self.score_to_grid_increase())


Expand Down
5 changes: 0 additions & 5 deletions trainfinity2/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
from trainfinity2.model import Rail # pragma: no cover


class GridEnlarger(Protocol):
def enlarge_grid(self):
raise NotImplementedError


class RailCollection(Protocol):
rails: list["Rail"]

Expand Down

0 comments on commit c2e9321

Please sign in to comment.