public void Interpret(PlayContext context)
        {
            if (context.Text.Length == 0)
            {
                return;
            }
            else
            {
                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);

                Excute(playKey, playValue);
            }
        }
Пример #2
0
        public static void Test1()
        {
            PlayContext context = new PlayContext();

            // 音乐 上海滩
            Console.WriteLine("上海滩:");
            context.Text = "T 500 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 ";
            Expression expression = null;

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

                    case "T":
                        expression = new Speed();
                        break;

                    case "C":
                    case "D":
                    case "E":
                    case "F":
                    case "G":
                    case "A":
                    case "B":
                    case "P":
                        expression = new Note();
                        break;
                    }
                    expression.Interpret(context);
                }
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }
        }