Beispiel #1
0
        // グラフのパラメーターをファイルから読み込む
        void LoadGraphParameter(string fileName)
        {
            // ファイルを読み込む
            var tempGPS = new List <GraphParameter>();

            using (var sr = new System.IO.StreamReader(fileName)) {
                while (!sr.EndOfStream)
                {
                    // 1行を読み込む
                    string line = sr.ReadLine();
                    // マッチさせてから各数値を取り出す
                    string pattern = @"^(?<Name>[^,]+),(?<MaxHP>\d+),(?<Defense>\d+),(?<NowHP>[\d-]+),(?<NaiveFlg>[^,]+)";
                    var    match   = Regex.Match(line, pattern);
                    bool   oldFlg  = false;
                    if (!match.Success)
                    {
                        // 旧形式用
                        pattern = @"^(?<Name>[^,]+),(?<MaxHP>\d+),(?<Defense>\d+),(?<NowHP>[\d-]+)";
                        match   = Regex.Match(line, pattern);
                        if (!match.Success)
                        {
                            continue;
                        }
                        oldFlg = true;
                    }
                    // 取り出した数値をGraphParameterに変換し、tempGPSに代入する
                    {
                        try {
                            // 読み込む
                            string name     = match.Groups["Name"].Value;
                            int    maxHp    = int.Parse(match.Groups["MaxHP"].Value);
                            int    defense  = int.Parse(match.Groups["Defense"].Value);
                            int    nowHp    = int.Parse(match.Groups["NowHP"].Value);
                            bool   naiveFlg = (oldFlg ? (bool)NaiveCheckBox.IsChecked : match.Groups["NaiveFlg"].Value == "True" ? true : false);
                            // 正規化
                            if (name.Length == 0)
                            {
                                name = $"グラフ{tempGPS.Count + 1}";
                            }
                            if (nowHp < 0)
                            {
                                nowHp = maxHp;
                            }
                            maxHp   = Math.Max(Math.Min(maxHp, 200), 1);
                            defense = Math.Max(Math.Min(defense, 200), 0);
                            nowHp   = Math.Max(Math.Min(nowHp, 200), 1);
                            bool afterFlg = (bool)AfterLineCheckBox.IsChecked;
                            var  gp       = new GraphParameter(name, maxHp, defense, nowHp, naiveFlg, afterFlg);
                            tempGPS.Add(gp);
                        }
                        catch {
                            continue;
                        }
                    }
                }
            }
            if (tempGPS.Count == 0)
            {
                throw new Exception();
            }
            // 読み込んだ結果を反映する
            graphParameterStock = tempGPS;
            this.Draw();
        }
 public static List <Point> CalcPlotData(GraphParameter g)
 {
     return(CalcPlotData(g.MaxHp, g.Armor, g.NowHp, g.NaiveFlg, g.AfterFlg));
 }