Exemplo n.º 1
0
        public void Main()
        {
            // 初始化各個物件
            Invoker invoker = new Invoker();                               // 發命令物件

            ReceiverRobot robot = new ReceiverRobot();                     // 執行命令物件

            GoAheadCommand   cmd_go_ahead   = new GoAheadCommand(robot);   // 向前走指令
            TurnLeftCommand  cmd_turn_left  = new TurnLeftCommand(robot);  // 左轉指令
            TurnRightCommand cmd_turn_right = new TurnRightCommand(robot); // 右轉指令

            // 設定要執行的命令
            invoker.SetCommand(cmd_go_ahead);
            invoker.SetCommand(cmd_go_ahead);
            invoker.SetCommand(cmd_turn_left);
            invoker.SetCommand(cmd_go_ahead);
            invoker.SetCommand(cmd_turn_right);

            // 開始執行命令
            invoker.Run();
        }
Exemplo n.º 2
0
 public GoAheadCommand(ReceiverRobot robot)
     : base(robot)
 {
 }
Exemplo n.º 3
0
 // 設定實際執行命令的物件
 public CommandClass(ReceiverRobot robot)
 {
     this.robot = robot;
 }
Exemplo n.º 4
0
 public TurnRightCommand(ReceiverRobot robot)
     : base(robot)
 {
 }
Exemplo n.º 5
0
 public TurnLeftCommand(ReceiverRobot robot)
     : base(robot)
 {
 }