-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.cpp
More file actions
80 lines (64 loc) · 1.89 KB
/
Controller.cpp
File metadata and controls
80 lines (64 loc) · 1.89 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
#include <iostream>
#include <vector>
#include <string>
class FighterJet {
public:
FighterJet(const std::string& name, int health, int speed)
: name(name), health(health), speed(speed) {}
void displayStatus() const {
std::cout << "Jet Name: " << name << "\n"
<< "Health: " << health << "\n"
<< "Speed: " << speed << " km/h\n";
}
void takeDamage(int damage) {
health -= damage;
if (health < 0) health = 0;
}
bool isDestroyed() const {
return health <= 0;
}
private:
std::string name;
int health;
int speed;
};
class GameController {
public:
GameController() {
// Initialize game settings
std::cout << "Welcome to Mighty Wings - 3D Fighter Jet Game!\n";
}
void addJet(const std::string& name, int health, int speed) {
jets.emplace_back(name, health, speed);
}
void displayJets() const {
for (const auto& jet : jets) {
jet.displayStatus();
std::cout << "-------------------\n";
}
}
void simulateDamage(int jetIndex, int damage) {
if (jetIndex < jets.size()) {
jets[jetIndex].takeDamage(damage);
std::cout << jets[jetIndex].getName() << " took " << damage << " damage!\n";
} else {
std::cout << "Invalid jet index!\n";
}
}
private:
std::vector<FighterJet> jets;
};
int main() {
GameController gameController;
// Adding fighter jets to the game
gameController.addJet("Falcon", 100, 900);
gameController.addJet("Eagle", 120, 850);
gameController.addJet("Hawk", 90, 950);
// Displaying the status of all jets
gameController.displayJets();
// Simulating damage to the first jet
gameController.simulateDamage(0, 30);
// Displaying the status again after damage
gameController.displayJets();
return 0;
}