• 泛型与无聊


    type
      TActionComponent = class(TObject)
      public
         procedure Execute;virtual;
      end;
    
      TStuckPig = class(TActionComponent)
      public
         procedure Execute;override;
      end;
    
      TRole = class(TObject)
      public
        Name:String[255];
        ActionList:TList<TActionComponent>;
      end;
    
      TWorld = class(TObject)
      public
         ObjectList:TDictionary<string,TList<TRole>>;
      end;
    
      TForm2 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form2: TForm2;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm2.Button1Click(Sender: TObject);
    var
      World:TWorld;
      Roles:TList<TRole>;
      Role:TRole;
      ActionComponent:TActionComponent;
    begin
      World:=TWorld.Create;
    
      //角色:屠夫
      Role:=TRole.Create;
      Role.Name:='屠夫';
      //杀猪动作或者叫技能可能更准确
      ActionComponent:=TStuckPig.Create;
      Role.ActionList.Add(ActionComponent);
      Roles:=TList<TRole>.Create;
      Roles.Add(Role);
    
      //角色:将军
      Role:=TRole.Create;
      Role.Name:='骠骑大将军';
      Roles.Add(Role);
      //角色:书法家
      Role:=TRole.Create;
      Role.Name:='书法家';
      Roles.Add(Role);
      //角色:酒鬼
      Role:=TRole.Create;
      Role.Name:='酒鬼';
      Roles.Add(Role);
      //赋与张飞各角色
      World.ObjectList.Add('张飞',Roles);
    
    end;
  • 相关阅读:
    Ngui使用随心记
    Ngui分辨率适配
    最大堆(优先队列)
    循环队列 & 栈的共用空间
    C#顺序表 & 单向链表(无头)
    IntelliJ Idea 常用快捷键列表
    写增删改查遇到的小问题总结
    用JS解决html页面间获取context-path问题
    html 页面如何获得url中的参数
    @RequestBody和@RequestParam区别
  • 原文地址:https://www.cnblogs.com/ZhouXiHong/p/4229349.html
Copyright © 2020-2023  润新知