def __init__(self, app, saver=Saver(), complete_key='tab', std_in=None, std_out=None): Cmd.__init__(self, complete_key, std_in, std_out) self.__country_names = app.get_country_names() self.__game_attributes = ["cells", "funding", "ideology", "lapsing", "marker", "prestige"] self.app = Utils.require_type(app, Labyrinth) self.saver = Utils.require_type(saver, Saver) self.prompt = "Enter command (? for help, Tab to complete): "
def _create_game(): """Factory function for a new game""" print "" scenario_number = Utils.choose_option("Choose Scenario", scenario_names()) print "" ideology_number = choose_ideology() print "" ai_rolls = Utils.getUserYesNoResponse( "Do you want the program to roll dice for you?") return Labyrinth(scenario_number, ideology_number, ai_rolls=ai_rolls)
def main(): """The main function that runs the game""" print "" print "Labyrinth: The War on Terror AI Player" print "" print "Release", RELEASE print "" saver = Saver() saver.new_session() # Ask user if they want to continue previous game if saver.suspended_game_exists() and Utils.getUserYesNoResponse( "Resume suspended game?"): app = saver.load_suspend_file() else: app = _create_game() saver.save_turn_file(app, 0) command = Command(app, saver) while True: command.cmdloop() # The user has quit, or wants to undo or rollback; prevents # issues dealing with save/reloading within class instance. if app.undo: print "Undo to last turn" app = saver.load_undo_file() elif app.roll_turn >= 0: print "Rolling back to turn " + str(app.roll_turn) app = saver.load_turn_file(app.roll_turn) if not app: break else: break
def test_choose_option_with_numeric_input(self): # Set up dogs = ['Boxer', 'Chow', 'Pug'] original_raw_input = __builtin__.raw_input __builtin__.raw_input = lambda _: "1" # Invoke dog_number = Utils.choose_option("Fave dog?", dogs) # Check self.assertEqual(1, dog_number) __builtin__.raw_input = original_raw_input
def __init__(self, app, name, country_type, oil_producing, resources, schengen_link=False): super(MuslimCountry, self).__init__(app, name, None, False, 0, oil_producing, resources, schengen_link) self.__aid = 0 self.__alignment = None self.__besieged = False self.__regime_change = False self.__type = Utils.require_one_of(country_type, [SHIA_MIX, SUNNI])
def _do_set_governance(self, new_governance): self.__governance = Utils.require_type_or_none(new_governance, Governance)
def __init__(self, app, name, posture, governance, schengen, recruit=0, schengen_link=False): super(NonMuslimCountry, self).__init__(app, name, governance, schengen, recruit, False, 0, schengen_link) self.__posture = Utils.require_none_or_one_of(posture, [HARD, SOFT])
def set_posture(self, new_posture): """Sets or clears the posture of this country""" self.__posture = Utils.require_none_or_one_of(new_posture, [HARD, SOFT])
def _get_card_number(card_number_str): if card_number_str: return Utils.parse_card_number(card_number_str) return Utils.prompt_for_card_number()
def do_quit(self, _): """Quits the game and prompts you to save.""" if Utils.getUserYesNoResponse("Save the game?"): print "Saving suspend file." self.saver.save_suspend_file(self.app) print "Exiting."
def choose_ideology(): """Prompts the user to choose an ideology (returns a 1-indexed number)""" descriptions = ["%s: %s" % (i.name(), i.difference()) for i in IDEOLOGIES] return Utils.choose_option("Choose Jihadist Ideology", descriptions)
def _save_game(app, save_file_name): """Saves the given game to the given file""" Utils.require_type(app, Labyrinth) with open(save_file_name, 'wb') as save_file: pickle.dump(app, save_file, 2)
def __init__(self, name): self.__name = Utils.require_type(name, str)