したがって、私の方法は理論的には機能するはずですが、期待した結果が得られません。
新しい TextReader クラスを作成し、テキスト ファイルから文字 (int) を読み取り、それをリストに追加する関数があります。
テキストファイル データは次のようになります (48 x 30)。
111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111 111111111111100000000001111111111000000111111111 111111110000000000000000000000000000000011111111 100000000000000000000000000000000000000001111111 000000000000001111111111111111111111000001111111 100000001111111111111111111112211221000001111111 100000111111122112211221122111111111000001111111 111111111221111111111111111112211110000011111111 111112211111111111111111111111111100000111221111 122111111111111122111100000000000000001111111111 111111111111111111100000000000000000011111111111 111111111111111111000000000000000001112211111111 111111111111221110000001111110000111111111111111 111111111111111100000111112211111122111111111111 111111112211110000001122111111221111111111111111111122111111000000011111111111111111112211221111 111111110000000011111111112211111111111111111111 111111000000001111221111111111221122111100000011 111111000000011111111111000001111111110000000001 111111100000112211111100000000000000000000000001 111111110000111111100000000000000000000000000011 111111111000011100000000000000000000000011111111 111111111100000000000000111111111110001111111111 111111111110000000000011111111111111111111111111 111111111111100000111111111111111111111111111111 111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111111111000000011111111111000001111111110000000001 111111100000112211111100000000000000000000000001 111111110000111111100000000000000000000000000011 111111111000011100000000000000000000000011111111 111111111100000000000000111111111110001111111111 111111111110000000000011111111111111111111111111 111111111111100000111111111111111111111111111111 111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111111111000000011111111111000001111111110000000001 111111100000112211111100000000000000000000000001 111111110000111111100000000000000000000000000011 111111111000011100000000000000000000000011111111 111111111100000000000000111111111110001111111111 111111111110000000000011111111111111111111111111 111111111111100000111111111111111111111111111111 111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111111111111111100000111111111111111111111111111111 111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111111111111111100000111111111111111111111111111111 111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111
私の方法は次のとおりです。
private void LoadReferenceMap(string FileName)
{
FileName = Path.Combine(Environment.CurrentDirectory, FileName);
List<int> ArrayMapValues = new List<int>();
if (File.Exists(FileName))
{
// Create a new stream to write to the file
using (TextReader reader = File.OpenText(FileName))
{
for (int i = 0; i < 48; i++)
{
for (int j = 0; j < 30; j++)
{
int x = reader.Read();
if (x == -1)
break;
ArrayMapValues.Add(x);
}
}
}
level.SetFieldMap(ArrayMapValues);
}
}
戻り値:
最初の行の終わりに到達するとわかるように、Read() は 13 を返し、次の行に移動する前に 10 を返しますか?