Home  >  Article  >  php教程  >  星际争霸之php策略模式

星际争霸之php策略模式

WBOY
WBOYOriginal
2016-06-07 17:23:101188browse

星际开地图对战,等5秒钟进入地图后,每个玩家都会拥有一个基地,几个农民等,还会有初始的人口供给。但这些是根据种族的不同而不同。


待解决的问题:我们需要根据种族的不同,而对玩家进行不同的初始化,最好将这些不同的处理方式封装。


思路:定义初始化的接口,然后制作不同种族的初始化类。



策略模式(Strategy)示例:


为了使代码不至于过长,一部分类的定义不在此写出,如果要调试,请用字符串等方式替代new。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn