Skip to content
This repository was archived by the owner on Mar 1, 2018. It is now read-only.

Commit

Permalink
Add data sdk, bug fix, support xml map
Browse files Browse the repository at this point in the history
  • Loading branch information
jxpxxzj committed Oct 5, 2015
1 parent 9a1360c commit 37fff79
Show file tree
Hide file tree
Showing 42 changed files with 936 additions and 1,015 deletions.
262 changes: 262 additions & 0 deletions WarshipGirl.Data/Map.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
using System.IO;

namespace WarshipGirl.Data
{
[XmlRoot("Map")]
public class Map
{
[XmlIgnore]
public string FileName { get; set; }
public string MapIndex { get; set; }
public string LevelIndex { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Creator { get; set; }
[XmlArray("Node"), XmlArrayItem("Point")]
public List<Point> Node { get; set; }
[XmlArray("Fleets"), XmlArrayItem("Fleet")]
public List<Fleet> Fleets { get; set; }

[XmlIgnore]
public string MapName
{
get
{
return $"{MapIndex}-{LevelIndex}";
}
}
[XmlIgnore]
public string PreviewImagePath { get; protected set; }

public Point GetPoint(string PointName)
{
foreach (Point p in Node)
if (p.Name == PointName)
return p;
return null;
}
private void CheckWays(Point pBegin)
{
if (pBegin.CanSkip)
{
if (pBegin.Routes.Count != 0)
foreach (Route r in pBegin.Routes)
{
var pTravel = GetPoint(r.Target);
CheckWays(pTravel);
}
else
Ways++;
}
if (pBegin.Routes.Count != 0)
foreach (Route r in pBegin.Routes)
{
var pTravel = GetPoint(r.Target);
CheckWays(pTravel);
}
else
Ways++;
}
[XmlIgnore]
public int Points
{
get
{
return Node.Count;
}
}
[XmlIgnore]
public int AnchorPoint
{
get
{
int s = 0;
foreach (Point p in Node)
if (p.Enemies.Count==0 && p.Items.Count==0 && p.Type != PointType.Start)
s++;
return s;
}
}
[XmlIgnore]
public int ResourcesPoint
{
get
{
int s = 0;
foreach (Point p in Node)
if (p.Enemies.Count == 0 && p.Items.Count != 0)
s++;
return s;
}
}
[XmlIgnore]
public int CanSkipPoint
{
get
{
int s = 0;
foreach (Point p in Node)
if (p.CanSkip)
s++;
return s;
}
}
[XmlIgnore]
public int Routes
{
get
{
int s = 0;
foreach (Point p in Node)
s += p.Routes.Count;
return s;
}
}

[XmlIgnore]
public int Ways { get; protected set; }

public Map(string XmlPath,string ImagePath)
{
FileName = XmlPath;
PreviewImagePath = ImagePath;
var doc = new XmlDocument();
doc.Load(XmlPath);

//Basic
var root = doc.SelectSingleNode("Map");

LevelIndex = root.Attributes["LevelIndex"].InnerText;
MapIndex = root.Attributes["MapIndex"].InnerText;
Title = root.Attributes["Title"].InnerText;
Description = root.SelectSingleNode("Description").InnerText;
Creator = root.Attributes["Creator"].InnerText;

//Points
var nodes = root.SelectSingleNode("Node");
Node = new List<Point>();
foreach (XmlNode x in nodes.ChildNodes)
{
//Basic
var p = new Point();
p.Type = x.Attributes["Type"] != null ? (PointType)Enum.Parse(typeof(PointType), x.Attributes["Type"].InnerText) : PointType.Normal;
p.X = x.Attributes["X"] != null ? int.Parse(x.Attributes["X"].InnerText) : 0;
p.Y = x.Attributes["Y"] != null ? int.Parse(x.Attributes["Y"].InnerText) : 0;
p.CanSkip = x.Attributes["CanSkip"] != null ? bool.Parse(x.Attributes["CanSkip"].InnerText) : false;
p.Name = x.Attributes["Name"] != null ? x.Attributes["Name"].InnerText : "Start";

//Routes
var rx = x.SelectSingleNode("Routes");
p.Routes = new List<Route>();
if (rx != null)
foreach (XmlNode routex in rx.ChildNodes)
{
var s = new Route();
s.Target = routex.Attributes["Target"].InnerText;
s.Possibility = routex.Attributes["Possibility"] != null ? int.Parse(routex.Attributes["Possibility"].InnerText) : 0;
p.Routes.Add(s);
}

//Enemies
var ex = x.SelectSingleNode("Enemies");
p.Enemies = new List<Fleet>();
if (ex != null)
foreach (XmlNode enemx in ex.ChildNodes)
{
var e = new Fleet();
e.ID = int.Parse(enemx.Attributes["ID"].InnerText);
p.Enemies.Add(e);
}

//Items
var ix = x.SelectSingleNode("Items");
p.Items = new List<Item>();
if (ix != null)
foreach (XmlNode itemx in ix.ChildNodes)
{
var i = new Item();
i.Type = (ResourceType)Enum.Parse(typeof(ResourceType), itemx.Attributes["Type"].InnerText);
i.Value = int.Parse(itemx.Attributes["Value"].InnerText);
p.Items.Add(i);
}

Node.Add(p);
}

//Fleets
Fleets = new List<Fleet>();
var fn = root.SelectSingleNode("Fleets");
if(fn!=null)
foreach (XmlNode x in fn.ChildNodes)
{
var f = new Fleet();
f.ID = int.Parse(x.Attributes["ID"].InnerText);
f.Ships = new List<Ship>();
foreach (XmlNode sx in x)
{
var s = new Ship();
s.ID = int.Parse(sx.Attributes["ID"].InnerText);
f.Ships.Add(s);
}
Fleets.Add(f);
}
CheckWays(Node[0]);
}
}
public enum PointType
{
Start, Normal, Boss,
}
public class Point
{
[XmlAttribute("Type")]
public PointType Type { get; set; }
[XmlAttribute("X")]
public int X { get; set; }
[XmlAttribute("Y")]
public int Y { get; set; }
[XmlAttribute("CanSkip")]
public bool CanSkip { get; set; }
[XmlAttribute("Name")]
public string Name { get; set; }
[XmlArray("Routes"), XmlArrayItem("Route")]
public List<Route> Routes { get; set; }
[XmlArray("Fleets"), XmlArrayItem("Fleet")]
public List<Fleet> Enemies { get; set; }
[XmlArray("Items"), XmlArrayItem("Item")]
public List<Item> Items { get; set; }
}
public class Route
{
[XmlAttribute("Target")]
public string Target { get; set; }
[XmlAttribute("Possibility")]
public int Possibility { get; set; }
}
public class Item
{
[XmlAttribute("Type")]
public ResourceType Type { get; set; }
[XmlAttribute("Value")]
public int Value { get; set; }
}
public class Fleet
{
[XmlAttribute("ID")]
public int ID { get; set; }
[XmlArrayItem("Ship")]
public List<Ship> Ships { get; set; }
}
public class Ship
{
[XmlAttribute("ID")]
public int ID { get; set; }
}
}
36 changes: 36 additions & 0 deletions WarshipGirl.Data/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("WarshipGirl.Data")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WarshipGirl.Data")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

//将 ComVisible 设置为 false 将使此程序集中的类型
//对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]

// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("634fd3da-4104-4673-9016-ba89ae3b20a1")]

// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
74 changes: 74 additions & 0 deletions WarshipGirl.Data/ResourceType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WarshipGirl.Data
{
public enum ResourceType
{
/// <summary>
/// 钻石
/// </summary>
Gold = 1,
/// <summary>
/// 油
/// </summary>
Oil = 2,
/// <summary>
/// 钢
/// </summary>
Ammo = 3,
/// <summary>
/// 弹
/// </summary>
Steel = 4,
BuildMaterial = 5,
Exp = 6,
ShipEnemy = 7,
ShipExp = 8,
/// <summary>
/// 铝
/// </summary>
Aluminium = 9,
/// <summary>
/// 驱逐?
/// </summary>
SmallShip = 111,
/// <summary>
/// 轻巡?
/// </summary>
MediumShip = 112,
/// <summary>
/// 战列?
/// </summary>
BigShip = 113,
/// <summary>
/// 潜艇
/// </summary>
Submarine = 114,
Equipment = 121,
MainQuest = 131,
NormalQuest = 132,
WeekQuest = 133,
/// <summary>
/// 快速建造
/// </summary>
FastBuild = 141,
/// <summary>
/// 快速修理
/// </summary>
FastRepair = 541,
BuildShipItem = 241,
BuildEquipItem = 741,
/// <summary>
/// 誓约之戒
/// </summary>
LoveRing = 88841,
/// <summary>
/// 损管
/// </summary>
DamageManager = 66641
}
}
Loading

0 comments on commit 37fff79

Please sign in to comment.