garbageCan instantions #20

Merged
s473616 merged 5 commits from :master into master 2023-04-23 16:16:40 +02:00
2 changed files with 25 additions and 4 deletions

11
city.py
View File

@ -12,14 +12,14 @@ class Node:
self.can = can
class City:
nodes: List[Node]
nodes: List[GarbageCan]
streets: List[Street]
def __init__(self) -> None:
self.nodes = []
self.streets = []
def add_node(self, node: Node) -> None:
def add_node(self, node: GarbageCan) -> None:
self.nodes.append(node)
def add_street(self, street: Street) -> None:
@ -27,7 +27,12 @@ class City:
def render_city(self, game_context: GameContext) -> None:
self._render_streets(game_context)
self._render_nodes(game_context)
def _render_streets(self, game_context: GameContext) -> None:
for street in self.streets:
street.render(game_context)
street.render(game_context)
def _render_nodes(self, game_context: GameContext) -> None:
for node in self.nodes:
node.render(game_context)

View File

@ -5,6 +5,8 @@ import pygame
from typing import Tuple, List
from street import Street, StreetType
from garbageTruck import GarbageTruck
from garbageCan import GarbageCan
def startup(game_context: GameContext):
render_background(game_context)
@ -25,8 +27,11 @@ def render_background(game_context: GameContext):
def create_city() -> City:
city: City = City()
streets = create_streets()
trashcans = create_trashcans()
for s in streets:
city.add_street(s)
for t in trashcans:
city.add_node(t)
return city
def create_streets() -> List[Street]:
@ -41,4 +46,15 @@ def create_streets() -> List[Street]:
streets.append(Street(3, 25, 23, StreetType.HORIZONTAL))
streets.append(Street(17, 30, 13, StreetType.VERTICAL))
streets.append(Street(17, 23, 25, StreetType.VERTICAL))
return streets
return streets
def create_trashcans() -> List[GarbageCan]:
trashcans = []
trashcans.append(GarbageCan((9, 4)))
trashcans.append(GarbageCan((9, 15)))
trashcans.append(GarbageCan((12, 22)))
trashcans.append(GarbageCan((3, 24)))
trashcans.append(GarbageCan((17, 9)))
trashcans.append(GarbageCan((24, 17)))
trashcans.append(GarbageCan((26, 4)))
return trashcans