I was trying to make a game with C++ and noticed that there is Process Killed
in the 4th line of the output. I am just curious about what is it.
My Code
#include <iostream>
#include <string>
#include <ctime>
#include <unistd.h>
using namespace std;
class Health {
public:
int Nhealth = 1000;
int Mhealth = 1000;
};
class AttackMagicPower : public Health { // You can ignore this function
public:
int MagicAttackCommand;
void AttackMagicPowerPlan() {
cin >> MagicAttackCommand;
if (MagicAttackCommand = 1) {
Mhealth = Mhealth - 200;
}
}
};
class Enemy {
public:
void coutx() {
srand(time(0) + time(0));
string a[3];
a[0] = "Monster! - PUNCH";
a[1] = "Monster! - KICK";
a[2] = "Monster! - COMBO";
int randomcout = (rand() % 3);
cout << a[randomcout] << endl;
cout << "#########################" << endl;
}
};
class Character {
public:
int startSTOPmatch;
void coutxy() {
string coutt;
cout << "Enter Your Command" << endl;
cin >> coutt;
if (coutt == "KICK" || coutt == "PUNCH" || coutt == "COMBO") {
cout << "#########################" << endl;
cout << "Ninja! - " << coutt << endl;
startSTOPmatch = 1;
}
else {
cout << "Your Command Was Wrong...You Lost The Match" << endl;
cout << "You May Retry!" << endl;
startSTOPmatch = 0;
}
}
};
class mainx : public Health, public Character {
public:
mainx() {
int random = (rand() % 10);
Enemy e;
cout << "Ladies and Gentlemen! Welcome to the fight of a Ninja and a Monstor\n";
sleep(1.0);
cout << "Hope You Will Enjoy!\n";
sleep(0.5);
cout << "__________________________________________________________";
cout << "_____________\n\n" << endl;
cout << "You and the monster can perform the following actions - \nKICK, ";
cout << "PUNCH, COMBO" << endl;
sleep(2.0);
cout << "_____________________________" << endl;
cout << "Monster Health - 1000" << endl;
cout << "Ninja Health - 1000" << endl;
cout << "_____________________________" << endl;
cout << " " << endl;
sleep(1.0);
do {
srand(time(0));
int randomHealthLowNormal = (rand() % 101);
srand(time(0) + random);
int xandomHealthLowNormal = (rand() % 101);
Mhealth = Mhealth - randomHealthLowNormal;
Nhealth = Nhealth - xandomHealthLowNormal;
coutxy();
if (startSTOPmatch = 1) {
e.coutx();
sleep(1.0);
cout << "_____________________________" << endl;
cout << "Monster Health - " << Mhealth << endl;
cout << "Ninja Health - " << Nhealth << endl;
cout << "_____________________________" << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
sleep(3.0);
} else {
cout << " " << endl;
}
} while (Mhealth > 0 || Nhealth > 0);
if (Nhealth < 0 || Nhealth == 0 || startSTOPmatch == 0) {
cout << "Monster Won The Match!" << endl;
}
else if (Mhealth < 0 || Mhealth == 0) {
cout << "Ninja Won The Match!" << endl;
}
}
};
int main() {
mainx m;
return 0;
}
My Output
+ g++ -w -Wall -std=c++14 -O2 -o main.out main.cpp -lm
Process Killed.
+ ./main.out
>>>Ladies and Gentlemen! Welcome to the fight of a Ninja and a Monster
>>>Hope You Will Enjoy!
_______________________________________________________________________
>>>
You and the monster can perform the following actions -
KICK, PUNCH, COMBO
>>>_____________________________
Monster Health - 1000
Ninja Health - 1000
_____________________________
>>>Enter Your Command
>>>