Uzupełnienie o randomowe smieci

This commit is contained in:
Bartosz Chyzy 2019-05-14 22:49:31 +02:00
parent 3167789721
commit 7d4bdd1dfa
3 changed files with 61 additions and 4 deletions

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<configuration> <configuration>
<appSettings> <appSettings>
<add key="imageFilePath" value="FOLDERPATH\input.bmp"/> <add key="imageFilePath" value="C:\Users\Bartek\Desktop\EEE\map1.bmp"/>
<add key="outputFilePath" value="FOLDERPATH\output.xml"/> <add key="outputFilePath" value="C:\Users\Bartek\Desktop\EEE\map1.xml"/>
</appSettings> </appSettings>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />

View File

@ -22,7 +22,7 @@ namespace MapEditor.Helpers
return FieldType.House; return FieldType.House;
if (color == Color.FromArgb(255,255,0)) if (color == Color.FromArgb(255,255,0))
return FieldType.House; return FieldType.Dump;
throw new NotImplementedException($"Conversion form {color.ToKnownColor()} has not been implemented."); throw new NotImplementedException($"Conversion form {color.ToKnownColor()} has not been implemented.");

View File

@ -44,6 +44,7 @@ namespace MapEditor
} }
private static bool GenerateXML(IEnumerable<FieldInfo> fieldInfos) private static bool GenerateXML(IEnumerable<FieldInfo> fieldInfos)
{ {
var random = new Random();
try try
{ {
using (var xmlWriter = XmlWriter.Create(Config.OutputFilePath)) using (var xmlWriter = XmlWriter.Create(Config.OutputFilePath))
@ -64,6 +65,62 @@ namespace MapEditor
xmlWriter.WriteElementString("Y",fieldInfo.Y.ToString()); xmlWriter.WriteElementString("Y",fieldInfo.Y.ToString());
xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement();
if (fieldInfo.FieldType == FieldType.House)
{
xmlWriter.WriteStartElement("TrashCans");
var hasAnyDumps = false;
if (random.Next(0, 10) > 4)
{
xmlWriter.WriteStartElement("Can");
xmlWriter.WriteElementString("GarbageType", "Paper");
xmlWriter.WriteElementString("Volume", random.Next(0, 100).ToString());
xmlWriter.WriteEndElement();
hasAnyDumps = true;
}
if (random.Next(0, 10) > 4)
{
xmlWriter.WriteStartElement("Can");
xmlWriter.WriteElementString("GarbageType", "Glass");
xmlWriter.WriteElementString("Volume", random.Next(0, 100).ToString());
xmlWriter.WriteEndElement();
hasAnyDumps = true;
}
if (random.Next(0, 10) > 4)
{
xmlWriter.WriteStartElement("Can");
xmlWriter.WriteElementString("GarbageType", "Organic");
xmlWriter.WriteElementString("Volume", random.Next(0, 100).ToString());
xmlWriter.WriteEndElement();
hasAnyDumps = true;
}
if (random.Next(0, 10) > 4)
{
xmlWriter.WriteStartElement("Can");
xmlWriter.WriteElementString("GarbageType", "PlasticMetal");
xmlWriter.WriteElementString("Volume", random.Next(0, 100).ToString());
xmlWriter.WriteEndElement();
hasAnyDumps = true;
}
if (!hasAnyDumps)
{
xmlWriter.WriteStartElement("Can");
xmlWriter.WriteElementString("GarbageType", "PlasticMetal");
xmlWriter.WriteElementString("Volume", random.Next(0, 40).ToString());
xmlWriter.WriteEndElement();
}
xmlWriter.WriteEndElement();
}
xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement();
} }
xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement();