Beginners adventure rpg

I'm in the middle of creating a really basic rpg as a way to try to learn c++, and I want units to attack each other with a base damage with a random modifier applied with a different value on each attack, like a true rng modifier. So far I have units attacking each other in a predictable pattern but I'm wondering if there is anyway to apply the aforementioned modifier.

Any feedback would be much appreciated.


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
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;

class Enemy;
class Player{
	protected:
		int AttackPower;

	public:
		int health;

		void setAttackPower(int b){ AttackPower = b; }
		virtual void Attack(Enemy &enemy) = 0;
};

class Enemy{
	protected:
		int AttackPower;

	public:
		int health;

		void setAttackPower(int a){ AttackPower = a; }
		virtual	void Attack(Player &player) = 0;
};

class Warrior:public Player{
	public:
	Warrior(){ AttackPower = 80; health = 200; }

	void Attack(Enemy &enemy){
		std::cout << "Warrior charge deals " << AttackPower << " damage to the knight." << std::endl;

		enemy.health -= AttackPower; // equivalent to takeDamage();
		if(enemy.health <= 0){
		std::cout << "Enemy is dead, congratulations!" << std::endl;
		}
	}
};
class Ninja:public Enemy{
	public:
	Ninja(){ AttackPower = 60; health = 200; }

	void Attack(Player &player){
		std::cout << "Ninja strike deals  " << AttackPower << " damage to the warrior." << std::endl;

		player.health -= AttackPower;
		if (player.health <=0){
			std::cout << "You died." << std::endl;
		}
	}
};


int main(){
//Calling objects from above
	Warrior warrior1;
	Ninja ninja1;

do{
    cout << "The warrior has " <<  warrior1.health << " health.\n" ;
	cout << "The ninja has " << ninja1.health << " health.\n" ;
	
//Displaying health of all units


	warrior1.Attack(ninja1);
	ninja1.Attack(warrior1);
//Executing attacks of units and their targets

    cout << "\n \nThe warrior has " <<  warrior1.health << " health.\n" ;
	cout << "The ninja has " << ninja1.health << " health.\n" ;
	
//Displaying health after damage


	system("pause");
//Allows user to read health levels
}while (ninja1.health > 0 && warrior1.health > 0 /*&& musketeer1.health >0 && knight1.health>0*/);
//Stops program if any object drops below 0
}
Last edited on
This video has you covered.
https://www.youtube.com/watch?v=pc-fA05eKZI&index=38&list=PLSPw4ASQYyynKPY0I-QFHK0iJTjnvNUys

I also suggest you to watch that whole playlist, since it builds on top of what he explained in the videos before.

Last edited on
Topic archived. No new replies allowed.