def main(): # Parse command-line options into a namespace for use throughout this # program options = get_options() # Create a star-log for controlling the format of output from within this # program out = StarLog(options.verbosity) out.comment("all messages printed by the client after this begin with a *") out.comment("(any other lines of output must be from your Player class).") out.comment() try: # Import player classes player = PlayerWrapper("your player", options.player_loc, options, out) # We'll start measuring space usage from now, after all # library imports should be finished: set_space_line() # Play the game, catching any errors and displaying them to the # user: connect_and_play(player, options, out) except KeyboardInterrupt: print() # (end the line) out.comment("bye!") except ConnectingException as e: out.print("error connecting to server") out.comment(e) except DisconnectException: out.print("connection lost") except ProtocolException as e: out.print("protocol error!") out.comment(e)
def main(): # Parse command-line options into a namespace for use throughout this # program options = get_options() # Create a star-log for controlling the format of output from within this # program out = StarLog(level=options.verbosity, ansi=options.use_colour) out.comment("all messages printed by the client after this begin with a *") out.comment("(any other lines of output must be from your Player class).") out.comment() try: # Import player classes player = PlayerWrapper("your player", options.player_loc, logfn=out.comment) # Even though we're not limiting space, the display # may still be useful for some users set_space_line() # Play the game, catching any errors and displaying them to the # user: result = connect_and_play(player, options.name, options.channel, options.host, options.port, logfilename=options.logfile, out_function=out.comment, print_state=(options.verbosity > 1), use_debugboard=(options.verbosity > 2), use_colour=options.use_colour, use_unicode=options.use_unicode) out.comment("game over!", depth=-1) out.print(result) except KeyboardInterrupt: print() # (end the line) out.comment("bye!") except ConnectingException as e: out.print("error connecting to server") out.comment(e) except DisconnectException as e: out.print("connection lost", depth=-1) out.comment(e) except ProtocolException as e: out.print("protocol error!", depth=-1) out.comment(e) except ServerEncounteredError as e: out.print("server encountered error!", depth=-1) out.comment(e)