Skip to content

Commit b18bd44

Browse files
committed
Merge branch 'master' of github.com:dynamicy/DesignPatternStudy
2 parents 9a30b06 + 6e6a276 commit b18bd44

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace CommandPattern
6+
{
7+
class CommandPatternDemo
8+
{
9+
static void Main(string[] args)
10+
{
11+
Invoker tInvoker = new Invoker();
12+
ReceiveRole tRole = new ReceiveRole();
13+
MoveForwardCommand tMoveForwardCommand = new MoveForwardCommand(tRole);
14+
TurnLeftCommand tTurnLeftCommand = new TurnLeftCommand(tRole);
15+
TurnRightCommand tTurnRightCommand = new TurnRightCommand(tRole);
16+
AttackCommand tAttackCommand = new AttackCommand(tRole);
17+
18+
// set command list
19+
tInvoker.SetCommand(tTurnLeftCommand);
20+
tInvoker.SetCommand(tMoveForwardCommand);
21+
tInvoker.SetCommand(tMoveForwardCommand);
22+
tInvoker.SetCommand(tTurnRightCommand);
23+
tInvoker.SetCommand(tMoveForwardCommand);
24+
tInvoker.SetCommand(tAttackCommand);
25+
26+
// Notify the role to execute command
27+
tInvoker.NotifyExecute();
28+
29+
Console.ReadKey();
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)