def client_main(): """ connects to server, logs in / register, and starts game """ print('Connecting to server...') game_session = GameSession() game_session.connect() # Login / Register loop while True: choice = input('login or register? l / r -> ') username, password = input('Enter username and password: '******'l' or choice == 'login': if game_session.login(username, password): break print('Failed to login') elif choice == 'r' or choice == 'register': if game_session.register(username, password): break print('Failed to register') else: print('Please enter l,r,login or register') # Wait to start game (blocking call) game_session.wait_for_game_start() while True: print("game started") game = Game(game_session) game.start()
def main(argv=None): game = Game() game.start() return 0
import sys import asyncio import websockets from client.game import Game import server.server as server if __name__ == '__main__': if sys.argv[1] == "s": server.game = server.Game() start_server = websockets.serve(server.handler, 'localhost', 8080) asyncio.get_event_loop().run_until_complete(start_server) asyncio.get_event_loop().run_forever() elif sys.argv[1] == "c": ip = sys.argv[2] username = sys.argv[3] game = Game(ip, username) asyncio.get_event_loop().run_until_complete(game.start())