public CurrentValue(double value, CurrentUnits units)
 {
     _value = value;
     _units = units;
 }
        public static CurrentValue StrToCurrentValue(string value, out string message)
        {
            message = string.Empty;

            var ss = _doubleRege.Split(value).Where(t =>
            {
                var s = t.Trim();
                return(!(s == "," || s == "" || s == ","));
            });
            string num  = "";
            string unit = "";

            foreach (var s in ss)
            {
                if (_doubleRege.IsMatch(s))
                {
                    num = s;
                    continue;
                }
                if (_unitRegex.IsMatch(s))
                {
                    unit = s;
                    continue;
                }
            }

            string vl = string.IsNullOrEmpty(unit) ? string.Empty : value.Replace(unit, string.Empty);

            CurrentUnits units = CurrentUnits.A;

            if (unit.ToLower() == "a")
            {
                units = CurrentUnits.A;
            }
            else if (unit.ToLower() == "ka")
            {
                units = CurrentUnits.kA;
            }
            else if (unit.ToLower() == "ma")
            {
                units = CurrentUnits.mA;
            }
            else if (unit.ToLower() == "μa")
            {
                units = CurrentUnits.μA;
            }
            else if (unit.ToLower() == "ua")
            {
                units = CurrentUnits.μA;
            }
            else
            {
                if (double.TryParse(vl, out double d))
                {
                    message = $"{unit}不是电流的有效单位,请尝试输入<{vl}A/kA/mA/μA>格式";
                    return(null);
                }
                else
                {
                    message = $"{unit}不是电流的有效值,请尝试输入{num}A/kA/mA/μA>格式";
                    return(null);
                }
            }

            if (vl.EndsWith("."))
            {
                message = $"{vl}值不合法,请尝试输入<{num}{unit}>格式";
                return(null);
            }

            if (double.TryParse(vl, out double dd))
            {
                return(new CurrentValue(dd, units));
            }

            message = $"{vl}值不合法,请尝试输入<{num}{unit}>格式";

            return(null);
        }
Beispiel #3
0
        void InitialConditions()
        {
            Color[] _unit    = new Color[w * h];
            Color[] _data    = new Color[w * h];
            Color[] _extra   = new Color[w * h];
            Color[] _target  = new Color[w * h];
            Color[] _random  = new Color[w * h];
            Color[] _tiles   = new Color[w * h];
            Color[] _corpses = new Color[w * h];

            CurrentData.GetData(_data);

            var rnd = new System.Random();

            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    _random[i * h + j]  = new Color(rnd.IntRange(0, 256), rnd.IntRange(0, 256), rnd.IntRange(0, 256), rnd.IntRange(0, 256));
                    _corpses[i * h + j] = new Color(0, 0, 0, 0);
                    _tiles[i * h + j]   = new Color(2, rnd.Next(0, 11), 30, 0);

                    // Random units
                    //if (rnd.NextDouble() > 0.85f)
                    //{
                    //    int dir = rnd.Next(1, 5);

                    //    int action = (int)(255f * SimShader.UnitAction.Attacking);

                    //    int g = 0;
                    //    int b = 0;

                    //    int player = rnd.Next(1, 2);
                    //    int team = player;
                    //    int type = rnd.Next(1, 2);

                    //    _unit[i * h + j] = new Color(type, player, team, 0);
                    //    _data[i * h + j] = new Color(dir, g, b, action);
                    //    _extra[i * h + j] = new Color(0, 0, 0, 0);
                    //    _target[i * h + j] = new Color(rnd.Next(0, 4), rnd.Next(0, 256), rnd.Next(0, 4), rnd.Next(0, 256));
                    //}
                    //else
                    //{
                    //    _unit[i * h + j] = new Color(0, 0, 0, 0);
                    //    _data[i * h + j] = new Color(0, 0, 0, 0);
                    //    _extra[i * h + j] = new Color(0, 0, 0, 0);
                    //    _target[i * h + j] = new Color(0, 0, 0, 0);
                    //}
                }
            }

            // Gold mine gride
            //for (int i = 0; i < w; i += 50)
            //for (int j = 0; j < h; j += 50)
            //{
            //    Create.MakeBuilding(vec(i,j), SimShader.UnitType.GoldMine, Player.None, Team.None, i, j, w, h, _unit, _data, _target);
            //}

            CurrentUnits.SetData(_unit);
            PreviousUnits.SetData(_unit);

            CurrentData.SetData(_data);
            PreviousData.SetData(_data);

            Extra.SetData(_extra);

            TargetData.SetData(_target);

            RandomField.SetData(_random);

            Tiles.SetData(_tiles);
            Corpses.SetData(_corpses);
        }