足球戰術->多點進攻之Abstract Factory篇
時間:2024-10-20 來源: 作者: 我要糾錯
<p style=line-height: 150%>接上回:<p style=line-height: 150%><A >http://www.csdn***/develop/read_article.asp?id=11111</A><p style=line-height: 150%>用前鋒,前衛甚至后衛來多點進攻,是最好的進攻方法,
在這里可以使用abstract factory模式,用一個abstract
factory來創建一個統一的進攻位置,然后派生出具體的
concrete factory(具體位置)來生產concrete product
(進球),所有的進攻由client class(教練)來指揮。
缺點是基本打發已經定死,沒有什么創造性
的進球方法,如肩部進球,胸部進球和“上
帝之手”等等:P
代碼如下:
T位置 = class(TObject)<p style=line-height: 150%> public<p style=line-height: 150%> constructor Create;<p style=line-height: 150%> destructor Destroy; override;<p style=line-height: 150%>
function 頭球(AOwner: TComponent): T頭球得分; virtual; abstract;<p style=line-height: 150%> function 近射(AOwner: TComponent): T近射得分; virtual; abstract;<p style=line-height: 150%> function 遠射(AOwner: TComponent): T遠射得分; virtual; abstract;<p style=line-height: 150%> end;<p style=line-height: 150%>T前鋒 = class(T位置)<p style=line-height: 150%> public<p style=line-height: 150%> { concrete constructors }<p style=line-height: 150%> function 前鋒頭球(AOwner: TComponent): T前鋒頭球得分; override;<p style=line-height: 150%> function 前鋒近射(AOwner: TComponent): T前鋒近射得分; override;<p style=line-height: 150%> function 前鋒遠射(AOwner: TComponent): T前鋒遠射得分; override;<p style=line-height: 150%> end;<p style=line-height: 150%>T后衛 = class(T位置)<p style=line-height: 150%> public<p style=line-height: 150%> { concrete constructors }<p style=line-height: 150%> function 后衛頭球(AOwner: TComponent): T后衛頭球得分; override;<p style=line-height: 150%> function 后衛近射(AOwner: TComponent): T后衛近射得分; override;<p style=line-height: 150%> function 后衛遠射(AOwner: TComponent): T后衛遠射得分; override;<p style=line-height: 150%> end;<p style=line-height: 150%>
標簽: