-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgameclass.cpp
More file actions
47 lines (46 loc) · 974 Bytes
/
Copy pathgameclass.cpp
File metadata and controls
47 lines (46 loc) · 974 Bytes
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
// Create a class game with member function to simulate a simple game with player actions and scoring:
#include <iostream>
#include<string>
using namespace std;
class Game
{
private:
int score;
string playerName;
public:
Game(string name)
{
playerName = name;
score = 0;
}
void attack()
{
cout << playerName << " perform attack! " << endl;
score = score + 10;
}
void defend()
{
cout << playerName << " perform defends! " << endl;
score = score + 5;
}
void heal()
{
cout << playerName << " perform heal! " << endl;
score = score + 7;
}
void showScore()
{
cout << playerName << " current score: "<<score << endl;
}
};
int main()
{
Game p1("Sanskrati");
//simulate actions:
p1.attack();
p1.defend();
p1.heal();
//show final score;
p1.showScore();
return 0;
}