Merge pull request 'add class of a city' (#11) from city_class into master
Reviewed-on: #11 Reviewed-by: Mikołaj Gawor <mikgaw@st.amu.edu.pl>
This commit is contained in:
commit
490b170ee4
39
city.py
Normal file
39
city.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
from typing import List, Tuple
|
||||||
|
from garbageCan import GarbageCan
|
||||||
|
|
||||||
|
class Node:
|
||||||
|
garbageCan: GarbageCan
|
||||||
|
id: int
|
||||||
|
|
||||||
|
def __init__(self, id: int, can: GarbageCan) -> None:
|
||||||
|
self.id = id
|
||||||
|
self.can = can
|
||||||
|
|
||||||
|
class City:
|
||||||
|
nodes: List[Node]
|
||||||
|
streets: List[Tuple[int, int]]
|
||||||
|
|
||||||
|
def __init__(self) -> None:
|
||||||
|
self.nodes = []
|
||||||
|
self.streets = []
|
||||||
|
|
||||||
|
def add_node(self, node: Node) -> None:
|
||||||
|
self.nodes.append(node)
|
||||||
|
|
||||||
|
def add_street(self, street: Tuple[int, int]) -> None:
|
||||||
|
firstFound: bool = False
|
||||||
|
secondFound: bool = False
|
||||||
|
|
||||||
|
for node in self.nodes:
|
||||||
|
if firstFound and secondFound:
|
||||||
|
break
|
||||||
|
if node.id == street.__getitem__(0):
|
||||||
|
firstFound = True
|
||||||
|
continue
|
||||||
|
if node.id == street.__getitem__(1):
|
||||||
|
secondFound = True
|
||||||
|
|
||||||
|
if not firstFound or not secondFound:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.streets.append(street)
|
Loading…
Reference in New Issue
Block a user