Beispiel #1
0
        public void Queue_CanPullBatch_RemovingPulledObjects()
        {
            IGameUpdate o1 = new GameUpdate {
                IPAddress = "STRING", GameState = "1"
            };
            IGameUpdate o2 = new GameUpdate {
                IPAddress = "STRING", GameState = "2"
            };
            IGameUpdate o3 = new GameUpdate {
                IPAddress = "STRING", GameState = "3"
            };

            _queue.Push(o1);
            _queue.Push(o2);
            _queue.Push(o3);
            _queue.Size().ShouldBe(3);

            var result = _queue.PullBatch(2);

            result.Count().ShouldBe(2);
            _queue.Size().ShouldBe(1);
        }
Beispiel #2
0
        private void ProcessGameTick(object source, ElapsedEventArgs e)
        {
            Console.Out.WriteLine($"Attempting to update from a list containing {_queue.Size()} updates.");

            IEnumerable <IGameUpdate> gameUpdates  = _queue.PullBatch(_BATCHSIZE);
            IList <IGameCommand>      gameCommands = new List <IGameCommand>();

            foreach (var gameUpdate in gameUpdates)
            {
                gameCommands.Add(_decoder.Decode(gameUpdate));
            }

            _serverStateManager.Process();

            string gameState = "";

            foreach (var playerLoggedIn in _serverGameState.PlayersLoggedIn)
            {
                IGameCommand command = new GameCommand() // TODO move to an extension method or extend the service to do this
                {
                    Command = GameCommands.Login,
                    Data    = new Tuple <Guid, object>(playerLoggedIn.Key, playerLoggedIn.Value)
                };

                string encodedResult = _encoder.Encode(command);
                gameState += "_" + encodedResult;
            }

            foreach (var playerCoordinate in _serverGameState.PlayerCoordinates)
            {
                IGameCommand command = new GameCommand()
                {
                    Command = GameCommands.Position,
                    Data    = new Tuple <Guid, object>(playerCoordinate.Key, playerCoordinate.Value)
                };

                string encodedResult = _encoder.Encode(command);
                gameState += "_" + encodedResult;
            }

            _broadcaster.Broadcast(gameState);
        }