Exemplo n.º 1
0
def app_main():
    action = sys.argv[1] if sys.argv[1:] else None

    if action == "load":
        savename = sys.argv[2]
        save.load_game(savename)
    elif action == "connect":
        host, port, username = sys.argv[2:]
        save.connect(host, int(port), username)
    elif action == "eval":
        exec sys.argv[2] in globals()
    elif action == "loadmeet":
        savename = sys.argv[2]
        ident = int(sys.argv[3])

        def callback():
            client.freeciv.func.py_init_meeting(ident)

        save.load_game(savename, callback)
    elif action == "help":
        import help

        help.show()
    else:
        if action:
            print "unknown action %r, see lib/main.py for actions" % action
        menus.main_menu()
Exemplo n.º 2
0
def app_main():
    action = sys.argv[1] if sys.argv[1:] else None

    if action == 'load':
        savename = sys.argv[2]
        save.load_game(savename)
    elif action == 'connect':
        host, port, username = sys.argv[2:]
        save.connect(host, int(port), username)
    elif action == 'eval':
        exec sys.argv[2] in globals()
    elif action == 'loadmeet':
        savename = sys.argv[2]
        ident = int(sys.argv[3])

        def callback():
            client.freeciv.func.py_init_meeting(ident)

        save.load_game(savename, callback)
    elif action == 'help':
        import help
        help.show()
    else:
        if action:
            print 'unknown action %r, see lib/main.py for actions' % action
        menus.main_menu()
def main_menu():
    """ Display the main menu and wait for input """
    render.animate_background('main_menu', 0.5)

    while not libtcod.console_is_window_closed():
        #show the background image, at twice the regular console resolution

        choice = render.menu('', ['New game', 'Continue', 'Quit'],
                             24,
                             center=True,
                             alpha=0,
                             xOffset=18,
                             yOffset=12)

        if choice == 0:
            new_game()
        elif choice == 1:
            try:
                save.load_game()
            except:
                render.menu('Couldnt load savegame.', ["ok"], 24)
                continue
            play_game()
        elif choice == 2:
            save.save_game()
            raise SystemExit
Exemplo n.º 4
0
 def test_quit_game_save_game(self):
     character.set_hp(5)
     try:
         quit_game()
     except SystemExit:
         pass
     character.set_hp(10)
     load_game()
     self.assertEqual(5, character.get_hp())
Exemplo n.º 5
0
def start_game():
    """
    Start the game.

    POST-CONDITION load game
    POST-CONDITION begin game play loop
    """

    save.load_game()
    play_game()
Exemplo n.º 6
0
def start():
    def callback():
        client.client.chat('/novice')
        found_nations = [ (name, style, id) for name, style, id in client.get_nations() if name == 'Poles' ]
        if found_nations:
            name, style, id = found_nations[0]
            print 'change nation to', name, style, id
            client.freeciv.func.set_nation_settings(id, 'Player', style, 2)
        return True

    save.load_game('data/tutorial.sav', before_callback=callback)
    def test_load_game(self):
        character_dictionary = {'hp': 5, 'column': 20, 'row': 20}
        with open('character.json', 'w') as file_object:
            json.dump(character_dictionary, file_object, sort_keys=True, indent=4)

        save.load_game()

        current_character = {"hp": character.get_hp(),
                             "column": character.get_coordinates()[0],
                             "row": character.get_coordinates()[1]}
        self.assertEqual({"hp": 5, "column": 20, "row": 20}, current_character)
Exemplo n.º 8
0
def downloaded(data):
    ui.set_dialog(ui.Label('Loading save...'))
    uncompressed = lzma.decompress(data)
    print 'Uncompressed size', len(uncompressed)
    dl_path = save.get_save_dir() + '/downloaded_save'
    try:
        os.remove(dl_path)
    except OSError:
        print 'not removed...'
    with open(dl_path, 'wb') as f:
        f.write(uncompressed)
    ui.back(anim=False)
    save.load_game(dl_path)
Exemplo n.º 9
0
def downloaded(data):
    ui.set_dialog(ui.Label("Loading save..."))
    uncompressed = lzma.decompress(data)
    print "Uncompressed size", len(uncompressed)
    dl_path = save.get_save_dir() + "/downloaded_save"
    try:
        os.remove(dl_path)
    except OSError:
        print "not removed..."
    with open(dl_path, "wb") as f:
        f.write(uncompressed)
    ui.back(anim=False)
    save.load_game(dl_path)
Exemplo n.º 10
0
def resume():
    name = get_resume_data()
    if name:
        remove_pause_file()
        try:
            show_main_menu()
            save.load_game(name)
        except IOError:
            # loading save failed
            return False
        return True
    else:
        return False
Exemplo n.º 11
0
def downloaded(data):
    ui.set_dialog(ui.Label('Loading save...'))
    uncompressed = lzma.decompress(data)
    print 'Uncompressed size', len(uncompressed)
    dl_path = save.get_save_dir() + '/downloaded_save'
    try:
        os.remove(dl_path)
    except OSError:
        print 'not removed...'
    with open(dl_path, 'wb') as f:
        f.write(uncompressed)
    ui.back(anim=False)
    save.load_game(dl_path)
Exemplo n.º 12
0
def resume():
    name = get_resume_data()
    if name:
        remove_pause_file()
        try:
            menus.main_menu()
            ui.set(ui.Label('dummy'))
            save.load_game(name)
        except IOError:
            # loading save failed
            return False
        return True
    else:
        return False
Exemplo n.º 13
0
def resume():
    name = get_resume_data()
    if name:
        remove_pause_file()
        try:
            menus.main_menu()
            ui.set(ui.Label('dummy'))
            save.load_game(name)
        except IOError:
            # loading save failed
            return False
        return True
    else:
        return False
Exemplo n.º 14
0
def client_main():
    action = sys.argv[1] if sys.argv[1:] else None
    if try_resume():
        ui.main()
        return
    
    if action == 'load':
        savename = sys.argv[2]
        save.load_game(savename)
    elif action == 'connect':
        host, port = sys.argv[2:]
        save.connect(host, int(port))
    else:
        show_main_menu()
    
    if features.get('app.profile'):
        profile_main()
    else:
        ui.main()
Exemplo n.º 15
0
def main_menu():
	""" Display the main menu and wait for input """
	render.animate_background('main_menu', 0.5)

	while not libtcod.console_is_window_closed():
		#show the background image, at twice the regular console resolution

		choice = render.menu('', ['New game', 'Continue', 'Quit'], 24, center=True, alpha=0, xOffset=18, yOffset=12)

		if choice == 0:
			new_game()
		elif choice == 1:
			try:
				save.load_game()
			except:
				render.menu('Couldnt load savegame.', ["ok"], 24)
				continue
			play_game()
		elif choice == 2:
			save.save_game()
			raise SystemExit
Exemplo n.º 16
0
    def __init__(self):
        self.render_engine = RenderEngine()
        self.input_manager = InputManager()
        self.player = load_game()
        if self.player is None:
            self.player = Player()
            game_map = generate_map(1)
            game_map.take_over_monster(self.player)
        game_map = self.player.entity.game_map

        map_scene = MapScene(self.player, game_map)
        self.current_scene = map_scene
Exemplo n.º 17
0
def handle_main_menu():
    img = tcod.image_load(b"menu_background.png")

    while not tcod.console_is_window_closed():
        # show the background image, at twice the regular console resolution
        tcod.image_blit_2x(img, 0, 0, 0)

        # show the game's title, and some credits!
        tcod.console_set_default_foreground(0, tcod.white)
        tcod.console_print_ex(
            0, SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2 - 4, tcod.BKGND_NONE, tcod.CENTER, bytes(GAME_NAME, "utf-8")
        )
        tcod.console_print_ex(
            0,
            SCREEN_WIDTH // 2,
            SCREEN_HEIGHT - 2,
            tcod.BKGND_NONE,
            tcod.CENTER,
            b"By Matthew Pfeiffer ([email protected])",
        )

        # show options and wait for the player's choice
        choice = menu("", ["Play a new game", "Continue last game", "Quit"], 24)

        if choice == 0:  # new game
            game.new_game()
            game.run()
        elif choice == 1:  # load last game
            try:
                save.load_game()
            except:
                msgbox("\n No saved game to load.\n", 24)
                continue
            game.run()
        elif choice == 2 or choice == "escape":  # quit
            break
Exemplo n.º 18
0
 def load_save(data):
     with open(get_download_path(), 'wb') as f:
         f.write(data)
     _save.load_game(get_download_path())
Exemplo n.º 19
0
def download_success():
    _save.load_game(get_download_path())
Exemplo n.º 20
0
def start():
    save.load_game('data/tutorial.sav')
Exemplo n.º 21
0
def download_success():
    _save.load_game(get_download_path())
Exemplo n.º 22
0
    def start_screen(self):
        show_main_menu = True

        while show_main_menu:
            libtcod.sys_check_for_event(
                libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, self.key,
                self.mouse)
            main_menu(self.con, game_constants.main_menu_background_image)

            libtcod.console_flush()

            action = handle_keys(self.key, GameStates.MAIN_MENU)
            game_type = action.get('game_start')
            exit_game = action.get('action') == 'exit'

            if exit_game:
                return False
            elif game_type == 'from_scratch':
                return True
            elif game_type == 'from_save':
                self.player, self.entities, self.game_map, self.message_log, self.game_state = load_game(
                )
                self.fov_map = initialize_fov(self.game_map)
                self.entities.set_log_all(self.message_log)
                return True
 def load_save(data):
     with open(get_download_path(), 'wb') as f:
         f.write(data)
     _save.load_game(get_download_path())