public void ImageShare()
        {
            //if(!isProcessing)
            //StartCoroutine( ShareScreenshot() );

            if (!isProcessing)
            {
                StartCoroutine(ShareGame());
            }


            ShareGameEvent?.Invoke();
        }
Beispiel #2
0
        public void execute(GameEvent gameEvent)
        {
            GameNetwork network = gameEvent.game.gameNetwork;

            if (server)
            {
                ShareGameEvent shareEvent = new ShareGameEvent();
                shareEvent.model = gameEvent.model;
                network.BroadcastMessage(shareEvent);

                List <object> events = network.ReceiveEvents();

                foreach (object message in events)
                {
                    if (message is SendKeysEvent)
                    {
                        SendKeysEvent keyEvent = ((SendKeysEvent)message);

                        Dictionary <Keys, Keys> keyTransfer = new Dictionary <Keys, Keys>();
                        keyTransfer.Add(Keys.W, Keys.Up);
                        keyTransfer.Add(Keys.S, Keys.Down);
                        keyTransfer.Add(Keys.A, Keys.Left);
                        keyTransfer.Add(Keys.D, Keys.Right);
                        keyTransfer.Add(Keys.Q, Keys.ShiftKey);

                        foreach (var pair in keyTransfer)
                        {
                            gameEvent.game.changeInputState(pair.Value, keyEvent.keyTable.ContainsKey(pair.Key) && keyEvent.keyTable[pair.Key]);
                        }
                    }
                }
            }
            else
            {
                SendKeysEvent sendKeys = new SendKeysEvent();
                sendKeys.keyTable = gameEvent.game.keyTable;
                network.BroadcastMessage(sendKeys);

                List <object> events = network.ReceiveEvents();

                foreach (object message in events)
                {
                    if (message is ShareGameEvent)
                    {
                        gameEvent.game.model = ((ShareGameEvent)message).model;
                    }
                }
            }
        }
        private void OnEvent(int width, int height, OnAsynCreate callback)
        {
            object message = network.TakeFirst();

            if (message is ShareGameEvent)
            {
                ShareGameEvent shareMessage = (ShareGameEvent)message;

                CreateClientGame(shareMessage.model, width, height, callback);

                return;
            }

            network.HandleEvent(() =>
            {
                OnEvent(width, height, callback);
            });
        }
        private void CreateServerGame(int width, int height, OnAsynCreate callback)
        {
            currentTeam = (random.Next() % 2 == 0) ? Team.blue : Team.green;

            QuantumMapBuilder mapBuilder = new QuantumMapBuilder();

            model = mapBuilder.initializeMap(width, height);

            ShareGameEvent shareGame = new ShareGameEvent();

            shareGame.model = model;

            network.BroadcastMessage(shareGame);

            QuantumGame game = new QuantumGame();

            game.gameNetwork = network;
            game.AddController(new NetworkSync(true));
            game.start(model, width, height);

            callback(game);
        }