def __init__(self): GameEngineElement.__init__(self, has_draw=True, has_event=True) self.__font = self.game_engine.get_object('font') self.add_to_engine() self.game_mode = 0 self.__input_keys = [ITEMS.keys(), CURRENCY.keys(), [None]] self.__input_mode = [0, 0, 0] self.__input_string = [] for key in self.__input_keys: self.__input_string.append(['0'] * len(key))
def __init__(self): GameEngineElement.__init__(self, has_draw=True, has_event=True) self.__font = self.game_engine.get_object('font') self.add_to_engine() self.game_mode = 2 self.__input_keys = [ITEMS.keys(), CURRENCY.keys(), [None]] self.__input_mode = [0, 0, 0] self.__input_string = [] for key in self.__input_keys: self.__input_string.append(['0'] * len(key))
def decay_items(self): """ Decays items and removes expired items. """ # Loop through all items for item_key in ITEMS.keys(): new_list = [] # Loops through all items stored in item list for item in self.__resources[item_key]: # Decrement decay and add to new list # ignore it if has expired if item[0] != 1: # If item is 0, then it doesn't decay if item[0] == 0: new_list.append([item[0], item[1]]) else: new_list.append([item[0]-1, item[1]]) elif item[1] != 0: self.add_msg("%d %ss have gone bad" % (item[1], item_key)) # Place item back into resource list self.__resources[item_key] = new_list
def decay_items(self): """ Decays items and removes expired items. """ # Loop through all items for item_key in ITEMS.keys(): new_list = [] # Loops through all items stored in item list for item in self.__resources[item_key]: # Decrement decay and add to new list # ignore it if has expired if item[0] != 1: # If item is 0, then it doesn't decay if item[0] == 0: new_list.append([item[0], item[1]]) else: new_list.append([item[0] - 1, item[1]]) elif item[1] != 0: self.add_msg("%d %ss have gone bad" % (item[1], item_key)) # Place item back into resource list self.__resources[item_key] = new_list
def __init__(self, difficulty_level=0): self.splash = True self.__day = 1 self.__difficulty = difficulty_level self.__resources = { 'money': STARTING_MONEY, 'last_income': 0, 'last_profit': 0, 'price': STARTING_PRICE, 'recipe': RECIPES['basic'] } # Populate resources with item keys for item_key in ITEMS.keys(): self.__resources[item_key] = [] self.__weather = 1 self.__msg_queue = [] # run weather self.weather_change() # run random self.random_event()
def resource_list(self): resources = {} for item_key in ITEMS.keys(): resources[item_key] = self.count_item(item_key) return resources
def process_day_logic(self, items): self.clear_queue() self.__day += 1 start_money = self.__resources['money'] self.add_msg(_("Starting Money: %s" % format_money(start_money))) # Process Item Payment for item in items: status = self.buy_item(item, items[item]) if status == -1: self.add_msg(_("You can't afford any units of %s.") % \ ITEMS[item]['name']) else: self.add_msg(_("Bought %d units of %s.") % \ (items[item], ITEMS[item]['name'])) # Calculate how many can be bought inventory_hold = [] for item_key in ITEMS.keys(): if self.recipe(item_key) == 0: continue inventory_hold.append(\ self.count_item(item_key) / self.recipe(item_key)) sales = min(inventory_hold) # Calculate how many will be bought by weather if sales != 0: if self.__weather == 0: sales = int(sales * .8) elif self.__weather == -1: sales = int(sales * .6) # Remove items required per cup sold for item_key in ITEMS.keys(): self.remove_item(item_key, sales * self.recipe(item_key)) self.__resources['last_income'] = sales * self.__resources['price'] self.add_msg(_("Sold %d cups, at %s each") % \ (sales, format_money(self.__resources['price']))) # Show profit and expenses if the difficuly is less than impossible if self.__difficulty < DIFFICULTY.index("Impossible"): self.add_msg("You spent %s on supplies" % \ format_money(self.__resources['money'] - start_money)) self.add_msg("and made %s in sales" % \ format_money(self.__resources['last_income'])) profit_to_calculate = (self.__resources['money'] - start_money)\ + self.__resources['last_income'] self.__resources['last_profit'] = profit_to_calculate if profit_to_calculate > 0: # Show the net porfit if difficulty is less than normal if self.__difficulty < DIFFICULTY.index("Hard"): self.add_msg("That comes to %s in profit" % \ (format_money(self.__resources['last_profit']))) return True else: self.__resources['money'] += self.__resources['last_income'] self.process_day_end() return False