示例#1
0
文件: Map.cs 项目: Wolfie13/RTSAI
	void load (string filename)
	{
		// Read the file
		System.IO.StreamReader file = 
			new System.IO.StreamReader (filename);

		//load mapsize from file
		//type octile
		file.ReadLine ();
		//height
		this.sizeY = Int32.Parse (file.ReadLine ().Split (' ') [1]);
		//width
		this.sizeX = Int32.Parse (file.ReadLine ().Split (' ') [1]);
		//"map"
		file.ReadLine ();

		//init maptiles array
		this.mapTiles = new char[sizeX, sizeY];


		//initialize entity array
		this.entities = new MapObject[sizeX, sizeY];


		//fill maptiles from file
		string line;
		int lineCount = 0;
		while ((line = file.ReadLine()) != null) {
			for (int i = 0; i < line.Length; i++) {
				mapTiles [i, lineCount] = line [i];
				if (Trees.Contains (mapTiles [i, lineCount])) {
					entities [i, lineCount] = new ResourceTile ();
					((ResourceTile)entities [i, lineCount]).setTile (ResourceType.Timber, new IVec2 (i, lineCount));
				} else if (Terrain.Contains (mapTiles [i, lineCount])) {
					if (UnityEngine.Random.Range (0.0f, 1.0f) < ResourceChance) {
						ResourceType t = ((UnityEngine.Random.Range (1, 100) % 2) == 0) ? ResourceType.Ore : ResourceType.Coal;
						ResourceTile rt = new ResourceTile ();
						entities [i, lineCount] = rt;
						rt.setTile (t, new IVec2 (i, lineCount));
					}
				} else {
					entities [i, lineCount] = new MapObject ();
				}
			}

			lineCount++;
		}

		//close file
		file.Close ();

	}
示例#2
0
文件: Map.cs 项目: Wolfie13/RTSAI
	//used only for testing 
	public void setResourcetile (ResourceType type, int ResourceAmount, IVec2 MapPos)
	{
		ResourceTile t = new ResourceTile ();
		t.setTile (type, MapPos, ResourceAmount);
	}