Verteiltesystheme/Code/Main.py

52 lines
1.1 KiB
Python
Raw Normal View History

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 ip
- own port
Optional: A neighbour:
- ip
- port
- direction
"""
args = sys.argv
print(args)
if len(args) >= 3:
own_ip = args[1]
own_port = int(args[2])
else:
print("using default ip 0.0.0.0")
print("using default port 8080")
own_ip = "0.0.0.0"
own_port = 8080
neighbours = Neighbours(own_process=Member(own_ip, own_port))
game_state = GameState(neighbours)
server = Server(neighbours, game_state)
n_direction = Direction.LEFT
if len(args) > 5:
n_direction = args[5]
if len(args) >= 5:
n_ip = args[3]
n_port = int(args[4])
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()