Merge pull request 'garbageCan instantions' (#20) from s464933/sztuczna_inteligencja_2023_smieciarka:master into master

Reviewed-on: #20
This commit is contained in:
Paweł Felcyn 2023-04-23 16:16:40 +02:00
commit ef1b0c23a9
2 changed files with 25 additions and 4 deletions

View File

@ -12,14 +12,14 @@ class Node:
self.can = can self.can = can
class City: class City:
nodes: List[Node] nodes: List[GarbageCan]
streets: List[Street] streets: List[Street]
def __init__(self) -> None: def __init__(self) -> None:
self.nodes = [] self.nodes = []
self.streets = [] self.streets = []
def add_node(self, node: Node) -> None: def add_node(self, node: GarbageCan) -> None:
self.nodes.append(node) self.nodes.append(node)
def add_street(self, street: Street) -> None: def add_street(self, street: Street) -> None:
@ -27,7 +27,12 @@ class City:
def render_city(self, game_context: GameContext) -> None: def render_city(self, game_context: GameContext) -> None:
self._render_streets(game_context) self._render_streets(game_context)
self._render_nodes(game_context)
def _render_streets(self, game_context: GameContext) -> None: def _render_streets(self, game_context: GameContext) -> None:
for street in self.streets: 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 typing import Tuple, List
from street import Street, StreetType from street import Street, StreetType
from garbageTruck import GarbageTruck from garbageTruck import GarbageTruck
from garbageCan import GarbageCan
def startup(game_context: GameContext): def startup(game_context: GameContext):
render_background(game_context) render_background(game_context)
@ -25,8 +27,11 @@ def render_background(game_context: GameContext):
def create_city() -> City: def create_city() -> City:
city: City = City() city: City = City()
streets = create_streets() streets = create_streets()
trashcans = create_trashcans()
for s in streets: for s in streets:
city.add_street(s) city.add_street(s)
for t in trashcans:
city.add_node(t)
return city return city
def create_streets() -> List[Street]: def create_streets() -> List[Street]:
@ -42,3 +47,14 @@ def create_streets() -> List[Street]:
streets.append(Street(17, 30, 13, StreetType.VERTICAL)) streets.append(Street(17, 30, 13, StreetType.VERTICAL))
streets.append(Street(17, 23, 25, 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