forked from parraro/Assignment1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeaponFactory.cpp
47 lines (38 loc) · 943 Bytes
/
WeaponFactory.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
36
37
38
39
40
41
42
43
44
45
46
47
/*
* File: WeaponFactory.cpp
* Author: Javier <[email protected]>
*
*/
#include <string>
#include <stddef.h>
#include "WeaponFactory.h"
#include "CommonSword.h"
#include "CommonSpear.h"
#include "SimpleAxe.h"
#include "CrazyRandomSword.h"
#include "StrongHammer.h"
WeaponFactory* WeaponFactory::instance = NULL;
WeaponFactory * WeaponFactory::getInstance() {
if (!instance) {
instance = new WeaponFactory();
}
return instance;
}
Weapon * WeaponFactory::getWeapon(std::string name) {
if (name.compare("sword") == 0) {
return new CommonSword();
}
if (name.compare("spear") == 0) {
return new CommonSpear();
}
if (name.compare("axe") == 0) {
return new SimpleAxe();
}
if(name.compare("random") == 0) {
return new CrazyRandomSword();
}
if(name.compare("hammer") == 0) {
return new StrongHammer();
}
throw "Invalid weapon";
}