コード例 #1
0
ファイル: Form1.cs プロジェクト: narlon/TOMClassic
 private void LoadFromFile(String txt)
 {
     try
     {
         StreamReader sr = new StreamReader(txt);
         for (int i = 0; i < 30; i++)
         {
             string[] datas = sr.ReadLine().Split('\t');
             cd[i] = new CardDescript(int.Parse(datas[0]), int.Parse(datas[1]), int.Parse(datas[2]));
         }
         sr.Close();
         UpdateImages();
     }
     catch (Exception e)
     {
         MessageBox.Show("错误的文件格式"+e, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: jayrulez/TOMClassic
        private static CardDescript[] MakeLoad(string name, int level)
        {
            var          deck = new List <CardDescript>();
            StreamReader sr   = new StreamReader(name);

            for (int i = 0; i < 30; i++)
            {
                var line = sr.ReadLine();
                if (line == null)
                {
                    break;
                }
                if (line.Contains("//"))
                {
                    int index = line.IndexOf("//"); //去除注释
                    line = line.Substring(0, index);
                }

                string[] datas  = line.Split('=');
                int      cardId = 0;
                string   tip    = "";

                string tpStr  = datas[0].Trim();
                string valStr = datas[1].Trim();
                if (tpStr == "Id")
                {
                    cardId = int.Parse(valStr);
                }
                else if (tpStr == "Rand")
                {
                    tip = valStr;
                }
                else
                {
                    throw new ApplicationException("card type error " + tpStr + "@" + name);
                }

                var card = new CardDescript(cardId, tip);
                deck.Add(card);
            }
            sr.Close();

            return(deck.ToArray());
        }