public override void HandlePackage()
        {
            UpdatePositionsPackage positionsPackage = (UpdatePositionsPackage)Package;

            foreach (var unit in positionsPackage.Units)
            {
                var unitComponent = Game.Units.FirstOrDefault(u => u.Unit.Id == unit.Id);
                if (unitComponent != null)
                {
                    unitComponent.Unit = unit;
                }
            }
        }
        public void SetUp()
        {
            _factory     = new ServerPackageFactory();
            _pongPackage = new PongPackage {
                Value = 10
            };

            _acceptLoginPackage = new AcceptLoginPackage {
                ClientId = 10
            };
            _setRoomPackage = new SetRoomPackage
            {
                Room = new Room
                {
                    Id     = 1,
                    Width  = 10,
                    Height = 10,
                    Units  = new[]
                    {
                        new Unit
                        {
                            Id       = 1,
                            Position = new Position(),
                            State    = States.Move
                        }
                    }
                }
            };

            _updatePositionsPackage = new UpdatePositionsPackage
            {
                Units = new Unit[5]
            };
            for (int i = 0; i < _updatePositionsPackage.Units.Length; i++)
            {
                var unit = new Unit
                {
                    Id             = i + 1,
                    Position       = new Position(1 * i, 5 * i),
                    State          = States.Move,
                    TargetPosition = new Position(1 * i, 5 * i)
                };

                _updatePositionsPackage.Units[i] = unit;
            }
        }
Exemplo n.º 3
0
        public void SetUp()
        {
            _expected = new UpdatePositionsPackage
            {
                Units = new Unit[5]
            };
            for (int i = 0; i < _expected.Units.Length; i++)
            {
                var unit = new Unit
                {
                    Id             = i + 1,
                    Position       = new Position(1 * i, 5 * i),
                    State          = States.Move,
                    TargetPosition = new Position(1 * i, 5 * i)
                };

                _expected.Units[i] = unit;
            }
        }
Exemplo n.º 4
0
        public void UpdatePositionsPackageDeserializationTest()
        {
            var buffer = _expected.ToByteArray();

            UpdatePositionsPackage actual      = new UpdatePositionsPackage();
            ServerPackageType      packageType = ServerPackageType.None;

            using (var stream = new MemoryStream(buffer))
            {
                using (var reader = new BinaryReader(stream))
                {
                    var len = reader.ReadInt32();
                    packageType = (ServerPackageType)reader.ReadByte();
                    actual.FromByteArray(reader.ReadBytes(len - 1));
                }
            }

            Assert.AreEqual(_expected.Type, packageType);
            Assert.AreEqual(_expected.Units.Length, actual.Units.Length);
        }