def update(self, cursor, time): Area.update(self, cursor, time) if self.time > 2000: if random.random() > 0.75: self.objects.append( entities.Person(random.choice([-20, 820]), True, (0.01, 0.05))) self.time = 0
def init(self, begin=60): Area.init(self, begin) self.objects.append(entities.College(125)) self.objects.append(entities.JobCentre(350, self)) self.objects.append(entities.Gym(600)) self.objects.append(entities.Boundary("right", City)) for i in range(0, random.randint(0, 10)): self.objects.append(entities.Person(random.randint(-20, 820)))
def init(self, begin=60): Area.init(self, begin) self.objects.append(entities.DrugDealer(100)) self.objects.append(entities.Bar(300)) self.objects.append(entities.EstateAgent(500, self)) self.house = entities.House(700, self) self.objects.append(self.house) self.objects.append(entities.Boundary("left", Street)) for i in range(0, random.randint(0, 10)): self.objects.append(entities.Person(random.randint(-20, 820)))
def init(self, begin=60): Area.init(self, begin) self.objects.append(entities.BarInside(400)) if not self.state.achievements["Girlfriend"]: self.her = entities.Her(700, self) self.her.sprite.flip_x(True) self.objects.append(self.her) self.objects.append(entities.Boundary("left", City, 300)) for i in range(0, random.randint(0, 4)): self.objects.append( entities.Person(random.randint(-20, 820), True, (0, 0.05)))
def update(self, cursor, time): Area.update(self, cursor, time) if self.time > 500: if random.random() > 0.5: self.objects.append(entities.Person(random.choice([-20, 820]))) self.time = 0
def get_entity(self, raw_object, entity_keys=ENTITY_KEYS): record_key = get_record_key(raw_object) #100 is person if record_key == '100': name = '' name_in_langs = dict() bio_data = list() comment_list = list() eng_name = '' profession = list() name_diff = '' date_of_birth = '' date_of_death = '' viaf = '' national_lib_id = '' #get the names and date of birth and bio data for field in raw_object.getroot(): key = field.attrib.get('tag') tag = entity_keys.get(key) if tag == 'name': name = field.text elif tag == 'name_langindic': # chack if this english name if field.text == 'lat': eng_name = name # else add it to name_in_langs else: if field.text in name_in_langs: name_in_langs.get(field.text).append(name) else: name_in_langs.update({field.text: [name]}) elif tag == 'date_of_birth': date_of_birth = field.text elif tag == 'date_of_death': date_of_death = field.text elif tag == 'name_in_langs': name_diff = field.text elif tag == 'langs_langindic': if field.text in name_in_langs: name_in_langs.get(field.text).append(name_diff) else: name_in_langs.update({field.text: [name_diff]}) elif tag == 'bio_data': bio_data.append(field.text) elif tag == 'comment': comment_list.append(field.text) elif tag == 'profession': profession.append(field.text) elif tag == 'viaf': viaf = field.text elif tag == 'national_lib_id': national_lib_id = field.text return entities.Person(eng_name, date_of_birth, date_of_death, name_in_langs, bio_data, comment_list, profession, viaf, national_lib_id) #110 is institue elif record_key == '110': return entities.Institution() #151 is location elif record_key == '151': name_in_langs = dict() types_of_place = list() comment_list = list() eng_name = '' name_diff = '' viaf = '' for field in raw_object.getroot(): key = field.attrib.get('tag') tag = entity_keys.get(key) if tag == 'name': name = field.text elif tag == 'name_langindic': # chack if this english name if field.text == 'lat': eng_name = name # else add it to name_in_langs else: if field.text in name_in_langs: name_in_langs.get(field.text).append(name) else: name_in_langs.update({field.text: [name]}) elif tag == 'type_of_place': types_of_place.append(field.text) elif tag == 'name_in_langs': name_diff = field.text elif tag == 'langs_langindic': if field.text in name_in_langs: name_in_langs.get(field.text).append(name_diff) else: name_in_langs.update({field.text: [name_diff]}) elif tag == 'comment': comment_list.append(field.text) elif tag == 'viaf': viaf = field.text return entities.Location(eng_name, types_of_place, name_in_langs, comment_list, viaf) else: return None
import entities p = entities.Person('S123x', 'John Lim') e = entities.Employee('S333y', 'Mary Tan', 1235) s = entities.Student('S876z', 'Tommy Teo', 4.0) print(p)
import datetime import entities as et me = et.Person('Michael Guttag') him = et.Person('Barack Hussein Obama') her = et.Person('Madonna') print(him.getLastName()) him.setBirthday(datetime.date(1961, 8, 4)) her.setBirthday(datetime.date(1958, 8, 16)) print(him.getName(), 'is', him.getAge(), 'days') p1 = et.MITPerson('Barbara Beaver') print(str(p1) + '\'s id number is ' + str(p1.getIdNum())) p1 = et.MITPerson('Mark Guttag') p2 = et.MITPerson('Billy Bob Beaver') p3 = et.MITPerson('Billy Bob Beaver') p4 = et.Person('Billy Bob Beaver') print('p1 < p2 =', p1 < p2) print('p3 < p2 =', p3 < p2) print('p4 < p1 =', p4 < p1) p5 = et.Grad('Buzz Aldrin') p6 = et.UG('Billy Beaver', 1984) print(p5, 'is a graduate student is', type(p5) == et.Grad) print(p5, 'is an undergraduate student is', type(p5) == et.UG)