示例#1
0
        public void GetTileDataTest()
        {
            string mapFileName = "testMap";
            string mapTitle = "Test";
            uint mapWidth = 1;
            uint mapHeight = 1;

            Map target = new Map(mapTitle, mapFileName, mapWidth, mapHeight);

            Tile testTile = new Tile();
            testTile.IsPassable = true;

            Tile[] expected = { testTile };
            Tile[] actual = target.GetTileData();

            for (int i = 0; i < actual.Length; i++)
            {
                if (expected.Length != actual.Length)
                    Assert.Fail("Expected size does not equal actual size");
                Assert.AreEqual(expected[i].Effect, actual[i].Effect);
                Assert.AreEqual(expected[i].EventID, actual[i].EventID);
                Assert.AreEqual(expected[i].Height, actual[i].Height);
                Assert.AreEqual(expected[i].ID, actual[i].ID);
                Assert.AreEqual(expected[i].IsPassable, actual[i].IsPassable);
                Assert.AreEqual(expected[i].ObjectID, actual[i].ObjectID);
                Assert.AreEqual(expected[i].Type, actual[i].Type);
            }
        }
示例#2
0
        public void CreateMapTest()
        {
            string mapFileName = "testMap";
            string mapTitle = "Test";
            uint mapWidth = 2;
            uint mapHeight = 2;

            Map target = new Map(mapTitle, mapFileName, mapWidth, mapHeight);

            Assert.AreEqual("testMap", target.FileName);
        }
        /// <summary>
        /// Gets the current map being played
        /// </summary>
        private void GetCurrentMap()
        {
            Options options = ServiceManager.Game.Options;
            if (String.IsNullOrEmpty(currentMap))
            {
                throw new Exception("No map is currently being played.");
            }

            try
            {
                FileInfo f = new FileInfo(String.Format(
                    "{0}{1}{2}", options.MapsFolder, Path.DirectorySeparatorChar, currentMap));
                if (f.Exists)
                {
                    currentMapInstance = new Map(f.FullName);

                    string mapHash = currentMapInstance.SHA1Hash;
                    string currentHash = Hash.CalculateSHA1OfFile(f.FullName);

                    bool valid = ServiceManager.Echelon.GetProxy().HashIsValid(
                        currentMap, currentHash);
                    if (!valid)
                    {
                        f.Delete();
                        f = null;

                        DownloadMap(currentMap);
                    }
                }
                else
                {
                    DownloadMap(currentMap);
                }
            }
            catch (Exception ex)
            {
                ServiceManager.Game.Console.DebugPrint("[WARNING] Cannot open map: {0}", ex.Message);
                if (currentMapInstance == null)
                {
                    try
                    {
                        DownloadMap(currentMap);
                    }
                    catch { }
                }
            }
        }
        /// <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;
        }
        /// <summary>
        /// Unloads content.
        /// </summary>
        public override void UnloadContent()
        {
            if (thread.IsAlive)
            {
                try
                {
                    thread.Interrupt();
                }
                catch (Exception e)
                {
                    ServiceManager.Game.Console.DebugPrint(
                        "[ERROR] At LoadingScreenState#UnloadContent(): {0}",
                        e.Message);
                }
            }

            if (futureGame != null)
            {
                ServiceManager.Game.BackgroundMovie.Pause();
                ServiceManager.MP3Player.Stop();
                ServiceManager.MP3Player.PlayPlaylist();
                futureGame.OnGameFinished += new GamePlayState.GameFinishHandler(OnGameFinished);
            }

            currentMap = null;
            currentMapInstance = null;
            thread = null;
            server = null;
            form = null;
            futureGame = null;
            clientCallback = null;
            buffer = null;
        }
示例#6
0
        public void GetTileTest()
        {
            string mapFileName = "testMap";
            string mapTitle = "Test";
            uint mapWidth = 1;
            uint mapHeight = 1;

            Map target = new Map(mapTitle, mapFileName, mapWidth, mapHeight);

            uint x = 0;
            uint y = 0;
            Tile expected = new Tile();
            expected.IsPassable = true;

            Tile actual;
            actual = target.GetTile(x, y);
            Assert.AreEqual(expected, actual);
        }
示例#7
0
        public void SetTileTest()
        {
            string mapFileName = "testMap";
            string mapTitle = "Test";
            uint mapWidth = 2;
            uint mapHeight = 2;

            Map target = new Map(mapTitle, mapFileName, mapWidth, mapHeight);
            uint x = 1;
            uint y = 1;

            Tile tile = new Tile();
            target.SetTile(x, y, tile);

            Assert.IsFalse(target.GetTile(x, y).IsPassable);
        }
示例#8
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));
        }
示例#9
0
        // False meaning, do not load/draw the background.
        public GamePlayState(GameCallback _callback, Map _map, EventBuffer _buffer)
            : base(false)
        {
            map = _map;
            //form = new InGameMenu(ServiceManager.Game.Manager);
            ServiceManager.Game.FormManager.RemoveWindow(
                ServiceManager.Game.FormManager.currentWindow);

            callback = _callback;
            buffer = _buffer;
            prevFrameScrollWheelValue = 0f;
        }
示例#10
0
        /// <summary>
        /// Unload any content (textures, fonts, etc) used by this state. Called when the state is removed.
        /// </summary>
        public override void UnloadContent()
        {
            /*try
            {
                ServiceManager.Game.GraphicsDevice.Reset();
                ServiceManager.Game.GraphicsDevice.VertexDeclaration = null;
                ServiceManager.Game.GraphicsDevice.Vertices[0].SetSource(null, 0, 0);
            }
            catch (Exception ex)
            {
                // If the graphics device was disposed already, it throws an exception.
                Console.Error.WriteLine(ex);
            }*/

            if (mouseCursor != null)
            {
                mouseCursor.DisableCustomCursor();
                mouseCursor = null;
            }
            EnvironmentEffects = null;
            Bases = null;
            buffbar = null;
            cd = null;
            hud = null;
            renderer = null;
            fps = null;
            map = null;
            visibleTiles = null;
            Scores = null;
            Players = null;
            Projectiles = null;
            Chat = null;
            buffer = null;
            miniMap.Dispose();
            miniMap = null;

            if (OnGameFinished != null)
            {
                EventArgs args = new EventArgs();
                OnGameFinished.Invoke(this, args);
            }
        }