Esempio n. 1
0
        static void Main(string[] args)
        {
            PlayContext context = new PlayContext();

            Console.WriteLine("上海滩:");
            context.Text = "O 2 E 0.5 G 0.5 A 3 E 0.5 G 0.5 D 3 E 0.5 G 0.5 A 0.5 O 3 C 1 O 2 A 0.5 G 1 C 0.5 E 0.5 D 3 ";
            Expression exp = null;

            while (context.Text.Length > 0)
            {
                string str = context.Text.Substring(0, 1);
                switch (str)
                {
                case "O": exp = new Scale(); break;

                case "C":
                case "D":
                case "E":
                case "F":
                case "G":
                case "A":
                case "B":
                case "P": exp = new Note(); break;
                }
                exp.Interpret(context);
            }
            Console.ReadKey();
        }
Esempio n. 2
0
 public void Interpret(PlayContext context)
 {
     if (context.Text.Length != 0)
     {
         //此方法用于将当前地演奏文本第一条命令获得命令字母和其参数值
         //例如“O3 E0.5 G0.5 A3”
         //则playKey为O,而playValue为3
         string playKey = context.Text.Substring(0, 1);
         context.Text = context.Text.Substring(2);
         double playValue = Convert.ToDouble(context.Text.Substring(0, context.Text.IndexOf(' ')));
         context.Text = context.Text.Substring(context.Text.IndexOf(' ') + 1);
         Execute(playKey, playValue);
     }
 }