/
Planet.cpp
83 lines (76 loc) · 1.59 KB
/
Planet.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
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
#include "Planet.h"
#include "Animal.h"
#include "Human.h"
#include "God.h"
#include <time.h>
#include <iostream>
Planet::Planet(std::string name){ this->name = name; }
void Planet::erasePopulation(){ population.clear(); }
Planet::~Planet()
{
int size = population.size();
std::cout << population.size();
for (unsigned int i = 0; i < size; i++)
{
delete population.back();
population.pop_back();
}
}
void Planet::addPopulation(EntityType type, int number)
{
for (int i = 0; i < number; i++)
{
switch (type)
{
case entity:
population.push_back(new Entity()); break;
case animal:
population.push_back(new Animal()); break;
case human:
population.push_back(new Human()); break;
case god:
population.push_back(new God()); break;
}
}
}
void Planet::movePopulation()
{
for (unsigned int j = 0; j < population.size(); j++)
{
population[j]->Move();
}
std::cout << "Population moving...";
}
void Planet::findPosition()
{
Point2D a;
for ( int j = 0; j <getPopulation(); j++)
{
for (int k = j + 1; k < getPopulation(); k++)
{
if (a.getDistance(population[j]->getPosition(), population[k]->getPosition()) < 5)
{
int random = rand() % 2 + 1;
switch (random)
{
case 1:
population[j]->Attack(*population[j]);
break;
case 2:
addPopulation(entity, 1);
}
}
else if (a.getDistance(population[j]->getPosition(), population[k]->getPosition()) == 0)
{
movePopulation();
}
}
}
}
void Planet::Update(){
for (unsigned int i = 1; i < population.size(); i++)
{
population[i]->DoAction();
}
std::cout << "DOingAction";
}