Esempio n. 1
0
        void loadMap(string mapFilePath)
        {
            string[] lines = File.ReadAllLines(mapFilePath);

            string[] widthAndHeight = lines[0].Split(' ');
            width = int.Parse(widthAndHeight[0]);
            height = int.Parse(widthAndHeight[1]);
            int numberOfResources = int.Parse(widthAndHeight[2]);
            int numberOfStartingPoints = int.Parse(widthAndHeight[3]);

            tiles = new MapTile[height, width];

            for (int i = 0; i < height; i++)
            {
                string[] rowOfTiles = lines[i + 1].Split(' ');

                for (int s = 0; s < width; s++)
                {
                    int typeCode = int.Parse(rowOfTiles[s].Substring(0, 1));
                    int pathingCode = int.Parse(rowOfTiles[s].Substring(1, 1));
                    tiles[i, s] = new MapTile(s, i, tileSize, tileSize, typeCode, pathingCode);
                    //if (pathingCode == 1)
                    //    Walls.Add(tiles[i - 1, s]);
                }
            }

            for (int i = height + 1; i < height + 1 + numberOfResources; i++)
            {
                string[] resourceParams = lines[i].Split(' ');

                if (resourceParams[0] == "0")
                {
                    BaseObject resource = new BaseObject(new Rectangle(int.Parse(resourceParams[1]) * TileSize, int.Parse(resourceParams[2]) * TileSize, 3 * TileSize, 3 * TileSize));
                    Resources.Add(resource );
                }
            }

            for (int i = height + 1 + numberOfResources; i < height + 1 + numberOfResources + numberOfStartingPoints; i++)
            {
                string[] resourceParams = lines[i].Split(' ');

                BaseObject startingPoint = new BaseObject(new Rectangle(int.Parse(resourceParams[0]) * TileSize, int.Parse(resourceParams[1]) * TileSize, 5 * TileSize, 5 * TileSize));
                StartingPoints.Add(startingPoint);
            }

            //Util.SortByX(Walls);
        }
Esempio n. 2
0
        void createMap(int width, int height)
        {
            this.width = width;
            this.height = height;

            tiles = new MapTile[height, width];

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    tiles[y, x] = new MapTile(x, y, tileSize, tileSize, 0, 0);
                }
            }

            for (int x = 0; x < width; x++)
            {
                tiles[0, x].Type = 1;
                tiles[0, x].Walkable = false;

                tiles[height - 1, x].Type = 1;
                tiles[height - 1, x].Walkable = false;
            }

            for (int y = 0; y < height; y++)
            {
                tiles[y, 0].Type = 1;
                tiles[y, 0].Walkable = false;

                tiles[y, width - 1].Type = 1;
                tiles[y, width - 1].Walkable = false;
            }
        }