diff options
| author | troido <troido@hotmail.com> | 2017-10-28 12:31:42 +0200 |
|---|---|---|
| committer | troido <troido@hotmail.com> | 2017-10-28 12:31:42 +0200 |
| commit | a8fd6fc77a3c5af06727a68684e61c63553679a8 (patch) | |
| tree | cde31f96a13907b3b5889d630667084e8dfdbcec /asciifarm/client/start.py | |
| parent | 4fe76206a7b183eaf46268e9dc03916de093f3b9 (diff) | |
better use of __main__ and __init__
Diffstat (limited to 'asciifarm/client/start.py')
| -rw-r--r-- | asciifarm/client/start.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/asciifarm/client/start.py b/asciifarm/client/start.py new file mode 100644 index 0000000..4084f7f --- /dev/null +++ b/asciifarm/client/start.py @@ -0,0 +1,41 @@ + +import curses +import json +import os +import getpass +import sys +from .connection import Connection +from .gameclient import Client +from .display import Display + +defaultAdresses = { + "abstract": "asciifarm", + "unix": "asciifarm.socket", + "inet": "localhost:9021", + } + +def main(name, socketType, address, keybindings, characters, colours=False): + + connection = Connection(socketType) + try: + connection.connect(address) + except ConnectionRefusedError: + print("ERROR: Could not connect to server.\nAre you sure that the server is running and that you're connecting to the right address?", file=sys.stderr) + return + + caught_ctrl_c = False + + def start(stdscr): + display = Display(stdscr, characters, colours) + client = Client(stdscr, display, name, connection, keybindings) + nonlocal caught_ctrl_c + try: + client.start() + except KeyboardInterrupt: + caught_ctrl_c = True + client.keepAlive = False + + curses.wrapper(start) + + if caught_ctrl_c: + print('^C caught, goodbye!') |
