-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFactories.cpp
35 lines (33 loc) · 1.07 KB
/
Factories.cpp
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
#include "Factories.h"
#include "NarutoS.h"
std::unique_ptr<Character> CharacterFactory::createCharacter(CharacterType type, bool forEnemy) {
switch (type) {
case CharacterType::Gaara:
if (forEnemy) {
return std::make_unique<Gaara>((int)1); // 调用带参数的构造函数
}
else {
return std::make_unique<Gaara>(); // 调用默认构造函数
}
case CharacterType::NarutoS:
if (forEnemy) {
return std::make_unique<NarutoS>((int)1); // 调用带参数的构造函数
}
else {
return std::make_unique<NarutoS>(); // 调用默认构造函数
}
default:
throw std::invalid_argument("Unknown character type");
}
}
std::unique_ptr<Map> MapFactory::createMap(MapType type)
{
switch (type) {
case MapType::MR:
return std::make_unique<MR>(); // 调用默认构造函数
case MapType::VE:
return std::make_unique<VE>(); // 调用默认构造函数
default:
throw std::invalid_argument("Unknown character type");
}
}