Exemplo n.º 1
0
        private void setupOnConnected(GameInfoMessage msg)
        {
            gameState.empireId = msg.empireId;
            gameState.empires  = msg.empires;
            // TODO: set up rendering and stuff
            clearColor = new Color(225, 225, 225);
            findEntity("loading").destroy();
            // set up the board
            var boardEntity = createEntity("board");

            gameState.map = new MapRef(msg.mapSize);
            var board = boardEntity.addComponent(new GameBoard(gameState));

            board.pawnMove = (pawn, dest) => {
                client.sendMessageAsync(new MovePawnMessage {
                    pawn = pawn, dest = dest
                });
            };
            // setup navigator camera
            camera.setMaximumZoom(2f);
            camera.setMinimumZoom(0.1f);
            camera.setZoom(0);
            var navigator = camera.addComponent(new Navigator());

            camera.setUpdateOrder(int.MaxValue);
        }
Exemplo n.º 2
0
        public override void onStart()
        {
            base.onStart();

            if (serverInformation == null)
            {
                // we need to run a server
                var localServerPort = DEFAULT_GAME_PORT;
                server = new GameServer(new NetworkConnectionProvider(RemoteGameProtocol.instance,
                                                                      new Target(Target.AnyIP, localServerPort), GameServer.MAX_CONNECTIONS));
                server.initializeSimulation();
                // run the server on a server thread
                serverThread = new Thread(server.Start);
                serverThread.Start();
                serverInformation = new ServerInformation {
                    ip = Target.LoopbackIP, port = localServerPort
                };
            }

            // run a client and connect
            // TODO: locally generate and store RSA client key
            client = new RemoteGameClient(new NetworkClientConnection(RemoteGameProtocol.instance));
            var clientConnectTask = client.ConnectAsync(new Target(serverInformation.ip, serverInformation.port));

            clientConnectTask.ContinueWith(x => client.sendMessageAsync(new JoinMessage {
                ready = true
            }));
//            client.onGameInfo = setupOnConnected;
            client.subscribe <GameInfoMessage>(setupOnConnected);
            client.subscribe <EmpireFetchMessage>(empireFetch);
            client.subscribe <WorldUpdateMessage>(worldUpdate);

            gameState = new RemoteGameState();
        }