-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaybe needed code
More file actions
56 lines (45 loc) · 1.43 KB
/
maybe needed code
File metadata and controls
56 lines (45 loc) · 1.43 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
#include <iostream>
#include <vector>
#include <string>
using namespace std;
// Define the Skill class
class Skill {
public:
Skill(string name) : name(name) {}
string getName() const {
return name;
}
private:
string name;
};
// Define the Player class
class Player {
public:
// Constructor to initialize the player with skills
Player(const vector<Skill>& initialSkills) : skills(initialSkills) {}
// Function to check if the player has a specific skill
bool hasSkill(const string& skillName) const {
for (const Skill& skill : skills) {
if (skill.getName() == skillName) {
return true;
}
}
return false;
}
private:
vector<Skill> skills;
};
int main() {
// Define some sample skills
Skill fireball("Fireball");
Skill swordMastery("Sword Mastery");
Skill poisonResistance("Poison Resistance");
// Create a player with initial skills
vector<Skill> initialSkills = {fireball, swordMastery, poisonResistance};
Player player(initialSkills);
// Check if the player has certain skills
cout << "Does the player have Fireball? " << (player.hasSkill("Fireball") ? "Yes" : "No") << endl;
cout << "Does the player have Sword Mastery? " << (player.hasSkill("Sword Mastery") ? "Yes" : "No") << endl;
cout << "Does the player have Ice Magic? " << (player.hasSkill("Ice Magic") ? "Yes" : "No") << endl;
return 0;
}