static void Main(string[] args) { Invoker invoker = new Invoker(); ReceiverRobot robot = new ReceiverRobot(); GoAheadCommand cmd_goAhead = new GoAheadCommand(robot); TurnLeftCommand cmd_turnLeft = new TurnLeftCommand(robot); TurnRightCommand cmd_turnRight = new TurnRightCommand(robot); invoker.SetCommand(cmd_goAhead); invoker.SetCommand(cmd_goAhead); invoker.SetCommand(cmd_turnLeft); invoker.SetCommand(cmd_turnRight); invoker.SetCommand(cmd_turnLeft); invoker.SetCommand(cmd_goAhead); invoker.SetCommand(cmd_turnLeft); invoker.Run(); Console.ReadLine(); }
public TurnLeftCommand(ReceiverRobot robot) : base(robot) { }
public TurnRightCommand(ReceiverRobot robot) : base(robot) { }
public GoAheadCommand(ReceiverRobot robot) : base(robot) { }
// 設定實際執行命令的物件 public Command(ReceiverRobot robot) { this.robot = robot; }