-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVirus.cpp
More file actions
155 lines (139 loc) · 2.46 KB
/
Copy pathVirus.cpp
File metadata and controls
155 lines (139 loc) · 2.46 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include "Virus.h"
Virus::Virus(string name, double virulence, double resistance, double energy, bool variant, int speed, int id, Point2D in_loc): GameObject(in_loc, id,'V')
{
this->name = name;
this->virulence = virulence;
this->resistance = resistance;
this->energy = energy;
this->variant = variant;
this->speed = speed;
is_moving = false;
is_in_student = false;
state = IN_ENVIRONMENT;
}
void Virus::infect(Student* student)
{
current_student = student;
state = IN_STUDENT;
is_in_student = true;
}
bool Virus::get_variant()
{
return false;
}
bool Virus::UpdateLocation(Point2D loc)
{
if (current_student != NULL && state == IN_STUDENT)
{
location = loc;
return true;
}
else if (fabs((loc - location).x) <= fabs(delta.x) && fabs((loc - location).y) <= fabs(delta.y))
{
location = loc;
is_moving = false;
return true;
}
else
{
location = location + delta;
is_moving = true;
return false;
}
}
void Virus::SetupLocation()
{
srand(time(NULL));
Point2D dest;
int x_val = rand() % 21;
int y_val = rand() % 21;
dest.x = x_val;
dest.y = y_val;
delta = (dest - location) * (speed / GetDistanceBetween(dest, location));
destination = dest;
}
bool Virus::Update()
{
if (state == IN_ENVIRONMENT)
{
if (!is_moving)
SetupLocation();
UpdateLocation(destination);
cout << name << " is moving in an environment" << endl;
return true;
}
else if (state == DEAD)
{
cout << name << " is dead." << endl;
return false;
}
else
{
energy -= 1;
if (IsAlive())
cout << name << " has infected student" << endl;
else
cout << name << " is dead and not in a student" << endl;
return true;
}
}
double Virus::get_virulence()
{
return virulence;
}
double Virus::get_resistance()
{
return resistance;
}
double Virus::get_energy()
{
return energy;
}
bool Virus::get_in_student()
{
return is_in_student;
}
void Virus::ShowStatus()
{
if (state == IN_ENVIRONMENT)
{
cout << name << " is in the environment" << endl;
}
else if (state == IN_STUDENT)
{
cout << name << " is in a student" << endl;
}
else if (state == DEAD)
{
cout << name << " is dead" << endl;
}
else
{
cout << "No state set" << endl;
}
}
bool Virus::IsAlive()
{
if (energy == 0)
{
state = DEAD;
is_in_student = false;
current_student = NULL;
return false;
}
else
{
return true;
}
}
bool Virus::ShouldBeVisible()
{
if (state == IN_ENVIRONMENT)
return true;
else
return false;
}
Virus::~Virus()
{
cout << "Virus Object destructed" << endl;
}