DesignPattern/20.ObserverPattern/2.Code/AllyCenter.h

39 lines
709 B
C
Raw Permalink Normal View History

2019-11-06 13:36:28 +00:00
#ifndef __ALLYCENTER_H__
#define __ALLYCENTER_H__
#include "common.h"
#include <vector>
#include <string>
2019-11-06 13:36:28 +00:00
2021-10-28 15:15:51 +00:00
// 前向声明
2019-11-06 13:36:28 +00:00
class Observer;
class Player;
2021-10-28 15:15:51 +00:00
// 抽象目标:联盟中心
2019-11-06 13:36:28 +00:00
class AllyCenter
{
public:
AllyCenter();
2021-10-28 15:15:51 +00:00
virtual ~AllyCenter() {}
// 声明通知方法
2019-11-06 13:36:28 +00:00
virtual void notify(INFO_TYPE infoType, std::string name) = 0;
2021-10-28 15:15:51 +00:00
// 加入玩家
void join(Observer *player);
// 移除玩家
void remove(Observer *player);
2019-11-06 13:36:28 +00:00
protected:
2021-10-28 15:15:51 +00:00
// 玩家列表
std::vector<Observer *> playerList;
2019-11-06 13:36:28 +00:00
};
2021-10-28 15:15:51 +00:00
// 具体目标
class AllyCenterController : public AllyCenter
2019-11-06 13:36:28 +00:00
{
public:
AllyCenterController();
2021-10-28 15:15:51 +00:00
// 实现通知方法
2019-11-06 13:36:28 +00:00
void notify(INFO_TYPE infoType, std::string name);
};
#endif //__ALLYCENTER_H__