Beispiel #1
0
        public static void Main(string[] args)
        {
            /*
             * 现在是客户端-命令-控制器
             * 现在是控制器和客户端分开了,控制器不需要知道是什么客户端是TV还是radio
             * 只要命令里有去实现客户端的就行,而且你可以实现非常多不同的命令,同时还支持撤回等操作
             */

            Person     person     = new Person();
            JumpPerson jumpPerson = new JumpPerson();

            Commander commander = new Commander();

            commander.AddCommand(new MoveCommnad(person, 1, 1));
            commander.AddCommand(new JumoCommand(jumpPerson, 1));
            commander.AddCommand(new MoveCommnad(person, 2, 1));
            commander.AddCommand(new JumoCommand(jumpPerson, 3));
            commander.AddCommand(new MoveCommnad(person, 2, 2));
            commander.AddCommand(new JumoCommand(jumpPerson, 5));
            commander.AddCommand(new JumoCommand(jumpPerson, 6));
            Console.WriteLine("----------撤销");
            commander.UnDo();
            commander.UnDo();
            commander.UnDo();
            commander.UnDo();
            commander.UnDo();
            commander.UnDo();
            commander.UnDo();
            Console.WriteLine("----------恢复");
            commander.Do();
            commander.Do();
            commander.Do();
            commander.Do();
            commander.Do();
            commander.Do();
        }
Beispiel #2
0
 public JumoCommand(JumpPerson jumpPerson, int z)
 {
     _jumpPerson = jumpPerson;
     _curZ       = z;
     _oriZ       = jumpPerson.Z;
 }