Verteiltesystheme/Code/Main.py

48 lines
1023 B
Python

import sys
import threading
from Code.Communication.Direction import Direction
from Code.Communication.Member import Member
from Code.Communication.Neighbours import Neighbours
from Code.Communication.Server import Server
from Code.UI.PlayingField import run_game, GameState
if __name__ == "__main__":
"""
Getting the args
- own port
Optional: A neighbour:
- ip
- port
- direction
"""
args = sys.argv
print(args)
if len(args) >= 2:
own_port = int(args[1])
else:
print("using default port 8080")
own_port = 8080
neighbours = Neighbours(own_process=Member("0.0.0.0", own_port))
game_state = GameState(neighbours)
server = Server(neighbours, game_state)
n_direction = Direction.LEFT
if len(args) > 4:
n_direction = args[4]
if len(args) >= 4:
n_ip = args[2]
n_port = int(args[3])
neighbours.connect(Direction[n_direction], n_ip, n_port)
serverThread = threading.Thread(target=server.start)
serverThread.start()
run_game(game_state)
print("finished game")
server.stop_server()