import argparse
import config

from factories.NetworkFactory import NetworkFactory
from factories.GameFactory import GameFactory


def main():
    args = parseCommandLine()
    game = createGame(args)
    game.run()

def parseCommandLine():
    parser = argparse.ArgumentParser(description='A game for the flippR')
    parser.add_argument('-o', '--OutputServerAddress', dest='OutputServerAddress', default=defaultOutputServerAddress())
    parser.add_argument('-i', '--InputServerAddress', dest='InputServerAddress', default=defaultInputServerAddress())

    return parser.parse_args()

def defaultOutputServerAddress():
    return config.SOCKET_PATH + config.OUTPUT_SOCKET_NAME

def defaultInputServerAddress():
    return config.SOCKET_PATH + config.INPUT_SOCKET_NAME

def createGame(args):
    print(args)
    NetworkFactory.createNetwork(args.OutputServerAddress, args.InputServerAddress)
    gameFactory = GameFactory()
    game = gameFactory.createGame()
    return game

if __name__ == '__main__':
    main()
