forked from WeihanLi/DesignPatterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
62 lines (52 loc) · 1.78 KB
/
Program.cs
File metadata and controls
62 lines (52 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
namespace InterpreterPattern
{
public class Program
{
public static void Main(string[] args)
{
#region Prototype
var context = new Context();
ICollection<AbstractExpression> expressions = new List<AbstractExpression>();
expressions.Add(new TerminalExpression());
expressions.Add(new TerminalExpression());
expressions.Add(new NoneTerminalExpresssion());
foreach (var expression in expressions)
{
expression.Interpret(context);
}
#endregion Prototype
var playContext = new PlayContext
{
PlayText = "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 O 3 E 0.5 D 3 "
};
MusicalExpression musicalExpression = null;
while (!string.IsNullOrEmpty(playContext.PlayText))
{
var str = playContext.PlayText.Substring(0, 1);
switch (str)
{
case "O":
musicalExpression = new MusicalScale();
break;
case "T":
musicalExpression = new MusicalSpeed();
break;
case "A":
case "B":
case "C":
case "D":
case "E":
case "F":
case "G":
case "P":
musicalExpression = new MusicalNote();
break;
}
musicalExpression?.Interpret(playContext);
}
Console.ReadLine();
}
}
}