-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEnemyFactory.cpp
More file actions
94 lines (87 loc) · 2.61 KB
/
EnemyFactory.cpp
File metadata and controls
94 lines (87 loc) · 2.61 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "EnemyFactory.h"
#include "StandardEnemy.h"
#include "FloatingEnemy.h"
#include "ShootingEnemy.h"
#include <iostream>
#include <ctime>
#include <cstdlib>
static const int SURVIVAL_GAME_TYPE = 10;
EnemyFactory::EnemyFactory(int gameType):gameType(gameType)
{
std::srand(time(0));
}
Enemy *EnemyFactory::Generate(int health, int xPos, int yPos)
{
switch (gameType)
{
case 0:
return InitializeBasic(health, xPos, yPos);
case 1:
return InitializeMedium(health, xPos, yPos);
case 2:
return InitializeHard(health, xPos, yPos);
case SURVIVAL_GAME_TYPE:
return InitializeSurvival(health, xPos, yPos);
default:
std::cerr << "Invalid game type set. Creating basic enemies only\n";
return InitializeBasic(health, xPos, yPos);
}
}
Enemy *EnemyFactory::InitializeBasic(int health, int xPos, int yPos)
{
int type = rand() % 10;
if (type >= 0 && type < 7)
return new StandardEnemy(health,xPos,yPos);
else if (type >= 3 && type < 10)
return new FloatingEnemy(health,xPos,yPos);
else
{
std::cerr << "EnemyFactory::InitializeBasic has invalid value\n";
return 0;
}
}
Enemy *EnemyFactory::InitializeMedium(int health, int xPos, int yPos)
{
int type = rand() % 10;
if (type >= 0 && type < 5)
return new StandardEnemy(health,xPos,yPos);
else if (type >= 5 && type < 8)
return new FloatingEnemy(health,xPos,yPos);
else if (type >= 8 && type < 10)
return new ShootingEnemy(health,xPos,yPos);
else
{
std::cerr << "EnemyFactory::InitializeMedium has invalid value\n";
return 0;
}
}
Enemy *EnemyFactory::InitializeHard(int health, int xPos, int yPos)
{
int type = rand() % 10;
if (type >= 0 && type < 3)
return new StandardEnemy(health,xPos,yPos);
else if (type >= 3 && type < 5)
return new FloatingEnemy(health,xPos,yPos);
else if (type >= 5 && type < 10)
return new ShootingEnemy(health,xPos,yPos);
else
{
std::cerr << "EnemyFactory::InitializeHard has invalid value\n";
return 0;
}
}
Enemy *EnemyFactory::InitializeSurvival(int health, int xPos, int yPos)
{
int type = rand() % 10;
if (type >= 0 && type < 5)
return new StandardEnemy(health,xPos,yPos);
else if (type >= 5 && type < 6)
return new FloatingEnemy(health,xPos,yPos);
else if (type >= 6 && type < 10)
return new ShootingEnemy(health,xPos,yPos);
else
{
std::cerr << "EnemyFactory::InitializeMedium has invalid value\n";
return 0;
}
}