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;
            }
        }
        public void SetRoomPackageDeserializationTest()
        {
            var buffer = _expected.ToByteArray();

            SetRoomPackage    actual      = new SetRoomPackage();
            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.Room.Id, actual.Room.Id);
            Assert.AreEqual(_expected.Room.Units.Length, actual.Room.Units.Length);
        }
 public void SetUp()
 {
     _expected = new SetRoomPackage
     {
         Room = new Room
         {
             Id     = 1,
             Width  = 10,
             Height = 10,
             Units  = new[]
             {
                 new Unit
                 {
                     Id       = 1,
                     Position = new Position(),
                     State    = States.Move
                 }
             }
         }
     };
 }
Beispiel #4
0
        public override void HandlePackage()
        {
            SetRoomPackage roomPackage = (SetRoomPackage)Package;

            Game.Init(roomPackage.Room.Width, roomPackage.Room.Height, roomPackage.Room.Units);
        }