Exemplo n.º 1
0
        private Unit CreateUnit(JToken unitSetting, Army army, Field field)
        {
            string unitName    = unitSetting["Name"].ToString();
            int    branchID    = (int)unitSetting["Branch"];
            int    mobilePower = (int)unitSetting["MobilePower"];
            int    headcount   = (int)unitSetting["Headcount"];

            if (this.branches.ContainsKey(branchID) == false)
            {
                throw new Exception($"Unitsの設定に未対応の兵科ID:{branchID}が含まれています。");
            }

            if (mobilePower <= 0)
            {
                throw new Exception("Unitsの設定にmobilePowerが0以下のUnitが含まれています。");
            }

            if (headcount <= 0)
            {
                throw new Exception("Unitsの設定にheadcountが0以下のUnitが含まれています。");
            }

            Unit unit = new Unit(army, unitName, this.branches[branchID], mobilePower, headcount);

            var location = unitSetting["Location"];
            int x        = (int)location[0];
            int y        = (int)location[1];

            field.SetUnit(unit, x, y);

            return(unit);
        }