/// <summary>
        /// Download the map from Echelon.
        /// </summary>
        /// <param name="mapName">Filename of the map to be downloaded.</param>
        private void DownloadMap(string mapName)
        {
            Options options = ServiceManager.Game.Options;
            Message = String.Format("Downloading map {0}...", mapName);
            Value = 25;

            VTankObject.Map map = ServiceManager.Echelon.GetProxy().DownloadMap(mapName);

            Message = "Reading map...";

            Console.WriteLine("Finished downloading map {0}.", map.filename);
            try
                {
                    DirectoryInfo directory = new DirectoryInfo(options.MapsFolder);
                    if (!directory.Exists)
                    {
                        directory.Create();
                    }
                }
                catch (Exception)
                {
                    options.MapsFolder = String.Format(@"{0}\{1}\maps\",
                        Environment.GetEnvironmentVariable("APPDATA"), "VTank");
                    try
                    {
                        Directory.CreateDirectory(options.MapsFolder);
                    }
                    catch (Exception) { }
                }

            Map realMap = new Map(
                map.title, map.filename, (uint)map.width, (uint)map.height);

            List<int> buf = new List<int>();
            for (int i = 0; i < map.supportedGameModes.Length; i++)
            {
                buf.Add(map.supportedGameModes[i]);
            }

            realMap.SetGameModes(buf);

            VTankObject.Tile[] tiles = map.tileData;
            // Set the tile data.
            for (uint y = 0; y < (uint)map.height; y++)
            {
                for (uint x = 0; x < (uint)map.width; x++)
                {
                    int position = (int)(y) * map.width + (int)(x);
                    VTankObject.Tile tempTile = tiles[position];
                    Tile tile = new Tile(
                        (uint)tempTile.id, (ushort)tempTile.objectId, (ushort)tempTile.eventId,
                        tempTile.passable, (ushort)tempTile.height, (ushort)tempTile.type,
                        (ushort)tempTile.effect);
                    realMap.SetTile(x, y, tile);
                }
            }

            try
            {
                realMap.SaveMap(options.MapsFolder);
            }
            catch (Exception)
            {
                options.MapsFolder = String.Format(@"{0}\{1}\maps\",
                    Environment.GetEnvironmentVariable("APPDATA"), "VTank");

                try
                {
                    Directory.CreateDirectory(options.MapsFolder);
                    realMap.SaveMap(options.MapsFolder);
                }
                catch (Exception ex)
                {
                    ServiceManager.Game.Console.DebugPrint("[WARNING] Cannot save map: {0}", ex.Message);
                }
            }

            currentMapInstance = realMap;
        }
Exemplo n.º 2
0
        public void SetGameModesTest()
        {
            string mapFileName = "test";
            string mapTitle = "Test";
            uint mapWidth = 2;
            uint mapHeight = 2;

            Map target = new Map(mapTitle, mapFileName, mapWidth, mapHeight);
            List<int> gameModes = new List<int>();

            gameModes.Add(1);
            gameModes.Add(2);

            target.SetGameModes(gameModes);

            Assert.IsTrue(target.GameModeSupported(1));
            Assert.IsFalse(target.GameModeSupported(3));
        }