Example #1
0
        public Map LoadMap(int mapId)
        {
            map = new Map();
            map.Width = 0;

            string filePath = String.Concat("..\\..\\..\\Worlds\\map", mapId, ".txt");
            string[] unparsedLines = File.ReadAllLines(filePath);
            List<Tile> previousLine = null;
            bool firstUnparsedLine = true;

            foreach (string unparsedLine in unparsedLines)
            {
                List<Tile> currentLine = parseLine(unparsedLine);

                if (currentLine.Count > map.Width)
                {
                    map.Width = currentLine.Count;
                }
                height = height + 1;

                // Set Origin
                if (firstUnparsedLine)
                {
                    map.Origin = currentLine[0];
                    firstUnparsedLine = false;
                }

                if (previousLine != null)
                {
                    linkParsedLines(previousLine, currentLine);
                }

                previousLine = currentLine;
            }

            map.Height = height;

            return map;
        }
Example #2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();

            parser = new Parser(this);

            // Loading map
            map = parser.LoadMap(1);
            graphics.PreferredBackBufferHeight = map.Height * TILE_SIZE;
            graphics.PreferredBackBufferWidth = map.Width * TILE_SIZE;
            graphics.ApplyChanges();
        }