57 lines
2.2 KiB
C#
57 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Xml;
|
|
using CzokoŚmieciarka.MonoGameView.DataModels.GeneralModels.Models;
|
|
using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces;
|
|
using CzokoŚmieciarka.MonoGameView.DataModels.Models;
|
|
using MonoGameView.DataModels.Models;
|
|
|
|
namespace MonoGameView.DataModels
|
|
{
|
|
public class MapLoader
|
|
{
|
|
public void Load(out int size, out IDrawables[,] grid, string filename)
|
|
{
|
|
XmlDocument xml = new XmlDocument();
|
|
xml.Load(filename);
|
|
XmlNode node = xml.GetElementsByTagName("Map").Item(0);
|
|
XmlNode sizeNode = node.SelectSingleNode("/Map/Size");
|
|
size = Convert.ToInt32(sizeNode.InnerText);
|
|
grid = new IDrawables[size,size];
|
|
for (int x = 0; x < size; x++)
|
|
{
|
|
for (int y = 0; y < size; y++)
|
|
{
|
|
grid[x, y] = new Grass(new Coords(x,y));
|
|
}
|
|
}
|
|
foreach(XmlNode objectNode in node.SelectNodes("/Map/Objects/Object"))
|
|
{
|
|
XmlNode positionNode;
|
|
int x;
|
|
int y;
|
|
switch (objectNode.SelectSingleNode("Type").InnerText)
|
|
{
|
|
case "Road":
|
|
positionNode = objectNode.SelectSingleNode("Position");
|
|
x = Convert.ToInt32(positionNode.SelectSingleNode("X").InnerText);
|
|
y = Convert.ToInt32(positionNode.SelectSingleNode("Y").InnerText);
|
|
Road1 road = new Road1(new Coords(x,y));
|
|
grid[x, y] = road;
|
|
break;
|
|
case "House":
|
|
positionNode = objectNode.SelectSingleNode("Position");
|
|
x = Convert.ToInt32(positionNode.SelectSingleNode("X").InnerText);
|
|
y = Convert.ToInt32(positionNode.SelectSingleNode("Y").InnerText);
|
|
House house = new House(new Coords(x,y));
|
|
grid[x, y] = house;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|