0
我想讀取文本文件以構建地圖。在XNA中逐行讀取文本文件以在XNA中創建地圖
例如,我有這樣的地圖:
[email protected]
[email protected]
[email protected]
000000000
000000000
000000000
000000000
我知道我應該使用這樣的:現在
StreamReader reader = new StreamReader([email protected]"/TestMap.MMAP");
string line = reader.ReadToEnd();
reader.Close();
,例如,我想讀第2行字符 「@」。我怎樣才能做到這一點?
請幫幫我。
解決:
謝謝(@LB和@ user861114),最後我的問題解決了:
string[,] item = new string[9, 7];
string[] line = File.ReadAllLines(Application.StartupPath + @"/TestMap.MMAP");
for (int j = 0; j < 7; j++)
{
for (int i = 0; i < 9; i++)
{
item[i, j] = line[j].Substring(i, 1);
Console.WriteLine(i + " " + j + "=" + item[i, j]);
}
}