Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <random>
- #include <ctime>
- using namespace std;
- default_random_engine randomGenerator(time(NULL));
- uniform_real_distribution<float> attackChance(0.0f, 1.0f);
- bool canAttack() {
- float chance = attackChance(randomGenerator);
- if (chance <= 0.35f) return true;
- return false;
- }
- class Character {
- private:
- float _health;
- float _attackDamage;
- public:
- virtual void attack(Character& other) {
- other.getAttacked(*this);
- }
- virtual void getAttacked(Character& other) {
- this->_health -= other.getAttackDamage();
- }
- virtual float getAttackDamage() {
- return this->_attackDamage;
- }
- };
- class Player : public Character{
- private:
- float _health = 100.0f;
- float _attackDamage = 100.0f;
- string _name;
- void say(string act) {
- if (act == "hurt") cout << _name << "says \"Auch!!\"\n";
- else if (act == "attack") cout << _name << "says \"Argh!!!\"\n";
- else if (act == "dead") cout << _name << "says \"Ahhhhh! You have defeated.... me....\"\n";
- else if (act == "missed") cout << _name << "says \"Oh, I missed my attack!\"\n";
- else cout << _name << "says \"Argh!!!\"\n";
- }
- void dead() {
- say("dead");
- }
- public:
- float getHealth() {
- return _health;
- }
- void setHealth(float health) {
- _health = health;
- }
- string getName() {
- return _name;
- }
- void setName() {
- cout << "What is your name Sir?: ";
- cin >> _name;
- cout << "\n";
- }
- void setName(string name) {
- _name = name;
- }
- bool isDead() {
- if (_health <= 0.0f) {
- dead();
- return true;
- }
- return false;
- }
- };
- class Skeleton : public Character{
- private:
- float _health = 100.0f;
- float _attackDamage = 100.0f;
- string _name;
- void say(string act) {
- if (act == "hurt") cout << _name << "says \"Arghhh!!!\"\n";
- else if (act == "attack") cout << _name << "says \"Growl!\"\n";
- else if (act == "dead") cout << _name << "says \"Ourgh! Me.... died......\"\n";
- else if (act == "missed") cout << _name << "says \"Rrraghh....\"\n";
- else cout << _name << "says \"Growl!\"\n";
- }
- void dead() {
- say("dead");
- }
- public:
- float getHealth() {
- return _health;
- }
- string getName() {
- return _name;
- }
- void setHealth(float health) {
- _health = health;
- }
- void setName(string name) {
- _name = name;
- }
- bool isDead() {
- if (_health <= 0.0f) {
- dead();
- return true;
- }
- return false;
- }
- };
- int main(int argc, char* argv[]) {
- Player player;
- Skeleton skeleton;
- player.setName("Player");
- skeleton.setName("M");
- cout << player.getAttackDamage() << endl;
- cout << skeleton.getAttackDamage() << endl;
- for (int i = 0; i < 10; i++) {
- cout << i << endl;
- player.attack(skeleton);
- cout << skeleton.getHealth();
- if (skeleton.isDead())
- return 0;
- skeleton.attack(player);
- cout << player.getHealth() << endl << endl;
- if (player.isDead())
- return 0;
- }
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement