How do I make their str, def, sstr and so forth random as if they were rolling dice and the set numbers are the max they can roll and 0 is the lleast?
Code:#include <iostream> #include <cstdlib> #include <string> #include <time.h> using namespace std; class Character { public: Character(); ~Character(); int VIT; int max_VIT; int SPI; int max_SPI; int STR; int max_STR; int DEF; int max_DEF; int SSTR; int max_SSTR; int SDEF; int max_SDEF; int ACC; int max_ACC; int EVA; int max_EVA; int AGI; int max_AGI; int TURN; int POT; int max_POT; int HPOT; int max_HPOT; int FPOT; int max_FPOT; int ETH; int max_ETH; int HETH; int max_HETH; int FETH; int max_FETH; int ELI; int max_ELI; int HELI; int max_HELI; int FELI; int max_FELI; void Command(); void Attack(); void Skill(); void Magic(); void Summon(); void Item(); char command[15]; char skill[15]; char magic[15]; char summon[15]; char item[15]; }; Character::Character() {} Character::~Character() {} class Swordsman { public: Swordsman(); ~Swordsman(); int VIT; int max_VIT; int SPI; int max_SPI; int STR; int max_STR; int DEF; int max_DEF; int SSTR; int max_SSTR; int SDEF; int max_SDEF; int ACC; int max_ACC; int EVA; int max_EVA; int AGI; int max_AGI; int TURN; void Attack(); }; Swordsman::Swordsman() {} Swordsman::~Swordsman() {} Character Player; Swordsman Enemy; int X; int Y; void Character::Command() { string command; cout<<"\n"; cout<<"Your Turn\n"; cin>>command; cin.ignore(); if(command=="Attack"||command=="attack"){Character::Attack();} else if(command=="Skill"||command=="skill"){Character::Skill();} else if(command=="Magic"||command=="magic"){Character::Magic();} else if(command=="Summon"||command=="summon"){Character::Summon();} else if(command=="Item"||command=="item"){Character::Item();} else{cout<<"(I don't think I should do that.)\n";Character::Command();} } void Character::Attack() { if(Player.ACC>=Enemy.EVA) {X=Player.STR-Enemy.DEF; if(X>0){Enemy.VIT=Enemy.VIT-X;cout<<X<<" Damage\n";} else{cout<<"0 Damage\n";}} else{cout<<"Miss\n";} } void Character::Skill() { string skill; cout<<"..."; cin>>skill; cin.ignore(); if(skill=="Break-Weapon"||skill=="Break-weapon"||skill=="break-weapon") {Player.SPI-5; if(Player.ACC>=Enemy.EVA) {Enemy.STR=Enemy.STR/2;cout<<"Enemy Strength Halved\n";} else{cout<<"Miss\n";}} else if(skill=="Break-Armor"||skill=="Break-armor"||skill=="break-armor") {Player.SPI-5; if(Player.ACC>=Enemy.EVA) {Enemy.DEF=Enemy.DEF/2;cout<<"Enemy Defence Halved\n";} else{cout<<"Miss\n";}} else{cout<<"(I don't think I should do that.)\n";Character::Command();} } void Character::Magic() { string magic; cout<<"..."; cin>>magic; cin.ignore(); if(magic=="Fire"||magic=="fire") {Player.SPI-5; if(Player.ACC>=Enemy.EVA){X=Player.SSTR-Enemy.SDEF; if(X>0){Enemy.VIT=Enemy.VIT-X;cout<<X<<" Damage\n";} else{cout<<"0 Damage\n";}} else{cout<<"Miss\n";}} else{cout<<"(I don't think I should do that.)\n";Character::Command();} } void Character::Summon() { string summon; cout<<"..."; cin>>summon; cin.ignore(); if(summon=="Ifrit"||summon=="ifrit") {Player.SPI-20; if(Player.ACC*2>=Enemy.EVA){X=Player.SSTR*4-Enemy.SDEF; if(X>0){Enemy.VIT=Enemy.VIT-X;cout<<X<<" Damage\n";} else{cout<<"0 Damage\n";}} else{cout<<"Miss\n";}} else{cout<<"(I don't think I should do that.)\n";Character::Command();} } void Character::Item() { string item; cout<<"..."; cin>>item; cin.ignore(); if(item=="Potion"||item=="potion") {Player.POT-1;X=Player.VIT/3;Player.VIT=Player.VIT+X; if(Player.VIT>Player.max_VIT) {Player.VIT=Player.max_VIT;cout<<X<<" Vitality Restored\n";} else{cout<<X<<" Vitality Restored\n";}} else{cout<<"(I don't think I should do that.)\n";Character::Command();} } void Swordsman::Attack() { cout<<"\n"; cout<<"Enemy's Turn\n"; if(Enemy.ACC>=Player.EVA) {X=Enemy.STR-Player.DEF; if(X>0){Player.VIT=Player.VIT-X;cout<<X<<" Damage\n";} else{cout<<"0 Damage\n";}} else{cout<<"Miss\n";} } int main() { Player.VIT=100; Player.max_VIT=100; Player.SPI=50; Player.max_SPI=50; Player.STR=rand()%20; Player.max_STR=20; Player.DEF=rand()%15; Player.max_DEF=15; Player.SSTR=rand()%15; Player.max_SSTR=15; Player.SDEF=rand()%15; Player.max_SDEF=15; Player.ACC=rand()%10; Player.max_ACC=10; Player.EVA=rand()%10; Player.max_EVA=10; Player.AGI=rand()%5; Player.max_AGI=5; Player.TURN=0; Player.POT=5; Player.max_POT=100; Player.HPOT=5; Player.max_HPOT=100; Player.FPOT=5; Player.max_FPOT=100; Player.ETH=5; Player.max_ETH=100; Player.HETH=5; Player.max_HETH=100; Player.FETH=5; Player.max_FETH=100; Player.ELI=5; Player.max_ELI=100; Player.HELI=5; Player.max_HELI=100; Player.FELI=5; Player.max_FELI=100; Enemy.VIT=100; Enemy.max_VIT=100; Enemy.SPI=50; Enemy.max_SPI=50; Enemy.STR=rand()%15; Enemy.max_STR=15; Enemy.DEF=rand()%15; Enemy.max_DEF=15; Enemy.SSTR=rand()%15; Enemy.max_SSTR=15; Enemy.SDEF=rand()%15; Enemy.max_SDEF=15; Enemy.ACC=rand()%10; Enemy.max_ACC=10; Enemy.EVA=rand()%10; Enemy.max_EVA=10; Enemy.AGI=rand()%5; Enemy.max_AGI=5; Enemy.TURN=0; cout<<"As your walking down the road a passing swordsman approaches you.\n"; cout<<"He challenges you to a fight and you accept.\n"; if(Player.AGI>=Enemy.AGI){Player.TURN=Player.TURN+1;} else{Enemy.TURN=Enemy.TURN+1;} do { if(Player.TURN>Enemy.TURN){Player.Command();Enemy.TURN=Enemy.TURN+2;} else if(Player.TURN<Enemy.TURN){Enemy.Attack();Player.TURN=Player.TURN+2;} else{ if(Player.AGI>=Enemy.AGI){Player.TURN=Player.TURN+1;} else{Enemy.TURN=Enemy.TURN+1;}} } while(Player.VIT>0||Enemy.VIT>0); if(Player.VIT<=0){cout<<"You Died\n";cout<<"Game Over\n";} else{cout<<"Victory\n";} cin.get(); }