[JsonObject("MapDataModel")]
public class MapData
{
[JsonProperty("list")]
public List[] list { get; set; }
}
[JsonObject("List")]
public class List
{
[JsonProperty("name")]
public string name { get; set; }
[JsonProperty("point")]
public Point[] point { get; set; }
}
[JsonObject("Point")]
public class Point
{
[JsonProperty("x")]
public int x { get; set; }
[JsonProperty("y")]
public int y { get; set; }
}
class FileAccess
{
private const string _filename = "hokkaido.json";
public static MapData Load()
{
string str = string.Empty;
using (var stream = new StreamReader(_filename, true))
{
str = stream.ReadToEnd();
}
return JsonConvert.DeserializeObject<MapData>(str);
}
}
これをAltseedで画面に表示させます。
class HokkaidoWar
{
MapData mapData = null;
public HokkaidoWar()
{
mapData = FileAccess.Load();
}
public void Run()
{
asd.Engine.Initialize("北海道大戦", 1800, 1000, new asd.EngineOption());
// 下地
var background = new asd.GeometryObject2D();
asd.Engine.AddObject2D(background);
var bgRect = new asd.RectangleShape();
bgRect.DrawingArea = new asd.RectF(0, 0, 1800, 1000);
background.Shape = bgRect;
var r = new Random();
foreach (var map in mapData.list)
{
var color = new asd.Color((byte)r.Next(0, 255), (byte)r.Next(0, 255), (byte)r.Next(0, 255));
foreach (var point in map.point)
{
var geometryObj = new asd.GeometryObject2D();
geometryObj.Color = color;
asd.Engine.AddObject2D(geometryObj);
var rect = new asd.RectangleShape();
rect.DrawingArea = new asd.RectF(24 * point.x + 50, 24 * point.y + 50, 24, 24);
geometryObj.Shape = rect;
}
}
while (asd.Engine.DoEvents())
{
asd.Engine.Update();
}
asd.Engine.Terminate();
}
}
Sub output()
Dim TownArea As Object
Dim Rows As Integer
Set TownArea = Worksheets("Sheet1").Range("AU1", Range("AU1").End(xlDown).End(xlToRight))
Rows = TownArea.Rows.Count
Dim Area As Object
Dim RightLength As Integer
Dim DownLength As Integer
Set Area = Worksheets("Sheet1").Range("B2:AS36")
RightLength = Area.Columns.Count
DownLength = Area.Rows.Count
Dim WS2 As Object
Set WS2 = Worksheets("Sheet2")
Dim WriteLine As Integer
WriteLine = 1
WS2.Cells(WriteLine, 1).Value = "{""list"":["
WriteLine = WriteLine + 1
For R = 1 To Rows
Dim number As Integer
Dim name As String
number = TownArea.Cells(R, 1).Value
name = TownArea.Cells(R, 2).Value
WS2.Cells(WriteLine, 2).Value = "{""name"" :"""
WS2.Cells(WriteLine, 3).Value = name
WS2.Cells(WriteLine, 4).Value = """, ""point"" :["
For RL = 1 To RightLength
For DL = 1 To DownLength
If Area.Cells(RL, DL).Value = number Then
WS2.Cells(WriteLine, 5).Value = "{""x"" :"
WS2.Cells(WriteLine, 6).Value = RL - 1
WS2.Cells(WriteLine, 7).Value = ", ""y"" :"
WS2.Cells(WriteLine, 8).Value = DL - 1
WS2.Cells(WriteLine, 9).Value = "}"
WS2.Cells(WriteLine, 10).Value = ","
WriteLine = WriteLine + 1
End If
Next
Next
WS2.Cells(WriteLine - 1, 10).Value = "]},"
Next
WS2.Cells(WriteLine - 1, 10).Value = "]}"
WS2.Cells(WriteLine, 1).Value = "]}"
End Sub