0
내 게임 클래스는리스트로 XML 파일에서 데이터를 가져 오기 위해이방법은 이것이다
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace testReadXmlGame
{
/// <summary>
/// This is the main type for your game.
/// </summary>
public class Game1 : Game
{
GraphicsDeviceManager graphics;
static List<List<string>> imageData = new List<List<string>>();
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
base.Draw(gameTime);
}
#region Public methods
#endregion
}
}
내 클래스의 주요 게임 클래스에 표시되지 않습니다.
using System;
using System.Collections.Generic;
using System.Xml;
namespace testReadXmlGame
{
public class XmlFileRead
{
#region Fields
private bool addToFile = false;
List<List<string>> imageData = new List<List<string>>();
#endregion
#region Public methods
public List<List<string>> XmlDataToList(string pathToXmlFile)
{
XmlReader xmlReader = XmlReader.Create(pathToXmlFile);
while (xmlReader.Read())
{
List<string> tempData = new List<string>(); // create a temp list to add data from each node
while (xmlReader.MoveToNextAttribute())
{
tempData.Add(xmlReader.Value);
addToFile = true;
}
if (addToFile)
{
imageData.Add(tempData);
addToFile = false;
}
}
// below code used to check the contents of the list returned
for (int i = 1; i <= imageData.Count - 1; i++)
{
for (int j = 0; j < imageData[i].Count; j++)
{
Console.WriteLine(imageData[i][j]);
}
}
Console.ReadKey();
return imageData;
}
#endregion
}
}
나는 업데이트 필드에
imageData = XmlReadFile.XmlDataToList(string nameOfXmlFile)
을 추가 할 수 있습니다.
내가하려고하는 것은 xml 파일의 위치를 전달하는 동안 Game 클래스에서 XmlFileRead 메서드를 호출 한 다음 xml 파일을 읽고 Main Game 클래스로 목록을 반환하는 것입니다.
내 문제는 메서드가 Main Game 클래스에도 표시되지 않는 것입니다. 누군가 문제를 해결하는 데 도움을 줄 수 있습니까? 오류를 지적하지 말고 C# 및 Monogame을 처음 접했을 때 해결책을 알려주십시오.
와 메인 클래스에서
XmlFileRead.XmlDataToList
를 호출 선언? 무엇을 쓰려고 했습니까? –XmlFileRead는 생성자를 의미하지 않는 한 클래스가 아닙니다. –
나는 질문을 편집하고 내가하고 싶은 것을 정확히 보여 주었다. – emorphus