-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.cpp
194 lines (169 loc) · 5.75 KB
/
Player.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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include "Player.h"
#include "Node.h"
#include "Map.h"
#include <iostream>
using namespace std;
Player::Player() {
playerPosition = nullptr;
mercy = 3;
}
Node *Player::getPlayerPosition() const {
return playerPosition;
}
void Player::setPlayerPosition(Node* newPosition) {
playerPosition = newPosition;
}
int Player::getPlayerCoordinate() const {
return playerPosition->value;
}
void Player::moveForward(Map &map) {
Node* current = playerPosition;
if(current->next){
playerPosition = current->next;
cout << "--You have moved forward.--" << endl;
}
else{
cout << "No more road in front" << endl; // wont face this issue
}
checkStatus(map);
}
void Player::setForgetDie(){
playerPosition->monsterType = '-'; // to forget he been die cause by any monster
}
void Player::moveBackward(Map &map) {
Node* current = playerPosition;
if(current->back){
playerPosition = current->back;
cout << "--You have moved backward.--" << endl; // dialog
// when level 3 will recover the mercy
if (map.getlevel()==3){
Mercy();
}
}
else{
script.printBackHit(); // dialog
}
checkStatus(map);
}
void Player::jumpOverNode(Map &map) {
Node* current = playerPosition;
if (playerPosition && playerPosition->next) {
// Jump over the node
playerPosition = playerPosition->next->next;
cout << "--You have successfully jumped over a step.--" << endl;
}
else {
cout << "There is no step ahead to jump over." << endl;
}
if(current->next->monsterType == 'A'){
script.printJumpMons(); // dialog
}
else{
script.printJumpAir(); // dialog
}
checkStatus(map);
}
bool Player::isPlayerAlive() {
if (playerPosition != nullptr && playerPosition->monsterType == 'A') { // indicate meet monster
return false;
}
if (playerPosition == nullptr){
script.printFell(); // dialog
return false;
}
return true;
}
bool Player::finish(Map &map){
if (playerPosition == map.getTail()){ // if head point to nullptr, the program broken.
return true;
}
return false;
}
// Mercy Function
void Player::Mercy(){
Node *nodePtr = nullptr;
nodePtr = playerPosition;
if (nodePtr->next != nullptr && nodePtr->next->monsterType == 'A'){
cout << "Your mental bacomes weaker..." << endl;
mercy--;
if (mercy == 0){
cout << "Due to the depressed condition, you totally go crazy. " << endl;
cout << "You rush towards the doors in front of you, one by one without sensing whether there are anything ahead." << endl;
cout << "When you stop at one of the room, you discover that there is a monster standing in front of you." << endl;
cout << "You accept your destiny by letting the monster bitting every part of your body..." << endl;
playerPosition->monsterType = 'A';
}
}
else{
cout << "You have calmed down yourself." << endl;
mercy++;
if (mercy>=3){
mercy = 3;
cout << "You are fully calm down." << endl;
}
}
}
int Player::getMercy() const {
return mercy;
}
void Player::setMercy(int newMercy) {
mercy = newMercy;
}
void Player::checkStatus(Map &map){
Node *nodePtr = nullptr;
nodePtr = playerPosition;
// if jump over the exit and die
if (playerPosition != map.getHead() && !nodePtr){
script.printJumpAcrossExit(); // dialog
}
// if the next node is a monster
else if (nodePtr->next != nullptr && nodePtr->next->monsterType == 'A'){
script.printMons(); // dialog
// level 3 will have damage when monster next node
if(map.getlevel()==3){
Mercy();
}
}
// die if current node containing monster
else if (nodePtr->monsterType == 'A'){
script.printEat(); // dialog
}
// answer question if current node containing goblin
else if (nodePtr->monsterType == 'B'){
GoblinQuestion(map);
}
// if the next node is exit
else if (nodePtr->next == map.getTail()){
script.printAlmost(); // dialog
}
// if current node is exit
else if (nodePtr == map.getTail()){
script.printExitFound(); // dialog
}
// normal walking scene
else{
script.printWalk();
}
}
void Player::GoblinQuestion(Map &map){
Node *nodePtr = nullptr;
nodePtr = playerPosition;
cout << "But before you can reach another door, there is a strange creature appears in front of you." << endl;
cout << "Goblin Question: How many nodes have you passed?" << endl;
int answer;
cin >> answer;
if (answer == nodePtr->value) {
cout << "Goblin Witch : \"Correct answer! You can pass the road.\"" << endl;
cout << "The goblin witch disappears in front of you, leaving an evil laugh echo..." << endl;
cout << "You carefully open the door and move to the next location carefully." << endl;
moveForward(map);
} else {
cout << "Goblin Witch : \"WRONG ANSWER! YOU SHOULD NOT PAASS!!!\"" << endl;
cout << "Yield the goblin witch." << endl;
cout << "Then, it summons a monster in front of you." << endl;
cout << "Without any sounds of shouting for help, ";
nodePtr->monsterType = 'A'; // forward to checkStatus, mentioning player eaten by a monster, else can form one more status like
// attacked by a group of goblin or any other situasion.
// will also forward to isPlayerAlive(), to mention the game is over (Lose).
}
}