-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcity.py
51 lines (40 loc) · 1.57 KB
/
city.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import random
class Disease:
def __init__(self, name,color):
self.name = name
self.color = color
self.outbreak_chance = 0.1
self.cured = False
def cure(self):
self.cured = True
class City:
def __init__(self, name,color):
self.name = name
self.color = color
self.diseases = {}
self.connected_cities = []
self.research_station = False
def add_disease(self, disease, infection_level=0):
self.diseases[disease] = infection_level
def connect(self, city):
self.connected_cities.append(city)
city.connected_cities.append(self)
def infect(self, disease, infection_level=1,outbreak_from=None):
if game.disease_cubes[disease] == 0:
print(f"No more {disease.name} cubes left. The players have lost!")
return
if disease not in self.diseases:
self.add_disease(disease)
self.diseases[disease] += infection_level
if self.diseases[disease] > 3:
self.outbreak(disease,outbreak_from)
def outbreak(self, disease, outbreak_from):
print(f"Outbreak in {self.name}!")
for city in self.connected_cities:
if city != outbreak_from:
city.infect(disease, outbreak_from=self)
def treat(self, disease, treatment_level=1):
assert disease in self.diseases, "Disease not present in this city."
self.diseases[disease] = max(0, self.diseases[disease] - treatment_level)
def build_research_station(self):
self.research_station = True