forked from FengJungle/DesignPattern
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAllyCenter.cpp
More file actions
55 lines (49 loc) · 1.16 KB
/
AllyCenter.cpp
File metadata and controls
55 lines (49 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "AllyCenter.h"
#include "Observer.h"
/*********** AllyCenter ****************/
AllyCenter::AllyCenter(){
printf("大吉大利,今晚吃鸡!\n");
}
// 加入玩家
void AllyCenter::join(Observer* player){
if (playerList.size() == 4){
printf("玩家已满\n");
return;
}
printf("玩家 %s 加入\n", player->getName().c_str());
playerList.push_back(player);
if (playerList.size() == 4){
printf("组队成功,不要怂,一起上!\n");
}
}
// 移除玩家
void AllyCenter::remove(Observer* player){
printf("玩家 %s 退出\n", player->getName().c_str());
//playerList.remove(player);
}
/*********** AllyCenter ****************/
/********** AllyCenterController *******/
AllyCenterController::AllyCenterController(){
}
// 实现通知方法
void AllyCenterController::notify(INFO_TYPE infoType, std::string name){
switch (infoType){
case RESOURCE:
for each (Observer* obs in playerList){
if (obs->getName() != name){
((Player*)obs)->come();
}
}
break;
case HELP:
for each (Observer* obs in playerList){
if (obs->getName() != name){
((Player*)obs)->help();
}
}
break;
default:
printf("Nothing\n");
}
}
/********** AllyCenterController *******/