예제 #1
0
        public void UnPackEnumPropertyCorrectly()
        {
            var networkMessagePackager = new NetworkMessagePackager();

            var testPacket = new EnumPacket()
            {
                TestEnum = TestEnum.Test
            };

            networkMessagePackager.AddDefinition <EnumPacket>();

            var value  = networkMessagePackager.Package(testPacket);
            var result = (EnumPacket)networkMessagePackager.Unpack(value);

            result.TestEnum.ShouldBe(testPacket.TestEnum);
        }
예제 #2
0
        public void UnPackCorrectly()
        {
            var networkMessagePackager = new NetworkMessagePackager();

            var testPacket = new TestPacket()
            {
                Number = 3,
                Name   = "Test"
            };

            networkMessagePackager.AddDefinition <TestPacket>();

            var value  = networkMessagePackager.Package(testPacket);
            var result = (TestPacket)networkMessagePackager.Unpack(value);

            result.Name.ShouldBe(testPacket.Name);
            result.Number.ShouldBe(testPacket.Number);
        }
예제 #3
0
        public void PackageCorrectlyBasedOnType()
        {
            var networkMessagePackager = new NetworkMessagePackager();

            var testPacket = new TestPacket()
            {
                Number = 3,
                Name   = "Test"
            };

            var definition = networkMessagePackager.AddDefinition <TestPacket>();

            var value = networkMessagePackager.Package(testPacket);

            var expectedString = $"{definition.PacketTypeId}:{testPacket.Number}:{testPacket.Name}";
            var outputString   = Encoding.UTF8.GetString(value);

            outputString.ShouldBe(expectedString);
        }
예제 #4
0
        private async Task <IGameWorld> GetWorldFromNetwork(IWorldMakerListener worldGeneratorListener)
        {
            await Task.Delay(1000);

            _tilesReceived = 0;

            AreaWidth  = 200;
            AreaHeight = 200;

            _tiles = new Tile[AreaWidth, AreaHeight];

            var outsideArea = new OutsideArea()
            {
                Tiles      = _tiles,
                AreaWidth  = AreaWidth,
                AreaHeight = AreaHeight,
            };

            var world = new GameWorld(outsideArea)
            {
                TileSize = 8
            };

            for (var i = 0; i < AreaWidth; i++)
            {
                for (var j = 0; j < AreaHeight; j++)
                {
                    _tiles[i, j] = new Tile(TileTypes.None, i, j)
                    {
                        GameWorld = world,
                        GameArea  = outsideArea
                    };
                }
            }

            Bitmap = new Bitmap(AreaWidth, AreaHeight);

            var mapRequest = new MapRequestPacket();
            var toSend     = _networkMessagePackager.Package(mapRequest);

            _networkManager.SendMessage(toSend);

            while (_tilesReceived < AreaWidth * AreaHeight)
            {
                var percent = ((float)_tilesReceived / (AreaWidth * AreaHeight)) * 100;
                worldGeneratorListener.OnWorldGenerationUpdate($"Receiving tiles... {percent}%");
            }

            worldGeneratorListener.OnWorldGenerationUpdate("Got tiles...");

            while (!ReceivedMap)
            {
                worldGeneratorListener.OnWorldGenerationUpdate("Waiting for players...");
            }

            foreach (var tile in _tiles)
            {
                Bitmap.SetPixel(tile.TileX, tile.TileY, tile.TileType == TileTypes.None ? Color.Black :
                                tile.TileType == TileTypes.Dirt ? Color.White : Color.Orange);
            }

            return(world);
        }