def gather(self, resource, place, num_people): logsystem.log("gather resource %s at %s with %s people" % (resource, place, num_people)) if self.gathering.can_gather(resource, place, num_people, self): self.gathering.assign_people(resource, place, num_people, self) say('%s people starts to gather %s' % (num_people, resource))
def status(self): self.population.show_status() for r in self.resources: say('%s: %s' % (r.capitalize(), self.resources[r])) say("Current day: %s" % (self.current_day))
def build(self, building_obj): b = building_obj if self.verify_cost(b.cost): self.pay_cost(b.cost) logsystem.log('create_building - lets create a ' + b.name) new_building = b.create_new(self) self.buildings.append(new_building) say('You %s building is ready!' % (new_building.type)) else: say("You don't have %s gold" % (b.cost['gold']))
def show_buildings(self): if len(self.buildings) == 0: say('There is not a single building. Let\'s create a new one') buildings_to_show = {} for b in self.available_buildings: buildings_to_show[b.type] = 0 for b in self.buildings: buildings_to_show[b.type] = buildings_to_show[b.type] + 1 for b in buildings_to_show: if buildings_to_show[b] == 1: say('%s (only %s building)' % (b, buildings_to_show[b])) elif buildings_to_show[b] > 1: say('%s (%s buildings)' % (b, buildings_to_show[b]))
def increase_limit(self, increment): self.limit = self.limit + increment say("Your population limit increased in %s units" % (increment,))
def show_status(self): say('Population: %s/%s' % (self.current, self.limit,))
def test(): # Method is handled before. So that line is not executed say("Test commands works!")
import txtgamelib from txtgamelib import when, say @when('test') def test(): # Method is handled before. So that line is not executed say("Test commands works!") say('Testing say') txtgamelib.start()
def toggle_debug(): gameData.toggle_debug() say('Debug mode is %s' % (gameData.debug_mode, ))
def show_buildings(): gameData.show_buildings() @when('workers') def show_workers(): gameData.show_workers() @when('build list') def list_what_can_be_built(): gameData.show_what_can_be_built() @when('build BUILDING') def create_building(building): gameData.create_building(building) @when('debug toggle') def toggle_debug(): gameData.toggle_debug() say('Debug mode is %s' % (gameData.debug_mode, )) say('Try to build a great empire') gameData.add_workers() gameData.start_update_loop() txtgamelib.start()
def show_what_can_be_built(self): say('You can build:') index = 0 for b in self.available_buildings: say('%s - %s' % (index, b.name)) index = index + 1
def show_workers(self): say('workers: %s' % (self.total_workers, ))
def pay_cost(self, cost): for c in cost: say('You spend %s %s' % (cost[c], c)) self.resources[c] = self.resources[c] - cost[c]