class Random {
public:
Random(int low, int high); //constructor
int get(void) const;
private:
int low;
int diff;
static void seed(void);
static int seedcount;
};
int Random::seedcount=0;
void Random::seed(void)
{
if(seedcount) return; //we only want to seed once
seedcount=1;
srand((int)time(0)); //seeds the random number generator
}
Random::Random(int l, int h) : low(l), diff(abs(h-l)+1)
{
seed();
}
int Random::get(void) const
{
return int((float)rand()/RAND_MAX*diff+low);
}
class weapon
{
private:
string type;
int hit_chance;
int stamina_required;
public:
weapon();
weapon(string,int,int);
void display();
int display_stamina();
bool did_you_hit();
};
bool weapon::did_you_hit()
{
Random r1(1,100);
if(r1.get()<=hit_chance){return true;}
else{return false;}
}
weapon::weapon(string t,int x, int y):type(t), hit_chance(x), stamina_required(y){}// initilization list
int main()
{
string weapon_type1,weapon_type2,name1,name2,f;
int hc1,hc2,sr1,sr2,stamina1,stamina2;
cout << "What is the first knights name?" << endl;
cin>> name1;
cout << "What is " << name1 << " stamina?" << endl;
cin>>stamina1;
cout << "What is "<<name1<<" weapon?" << endl;
cin>> weapon_type1;
cout << "What is the weapon's hit chance?" << endl;
cin>> hc1;
cout << "What is the weapon's stamina required to use?" << endl;
cin >> sr1;
cout << "What is the second knights name?" << endl;
cin>> name2;
cout << "What is " << name2 << " stamina?" << endl;
cin>>stamina2;
cout << "What is "<<name2<<" weapon?" << endl;
cin>> weapon_type2;
cout << "What is the weapon's hit chance?" << endl;
cin>> hc2;
cout << "What is the weapon's stamina required to use?" << endl;
cin >> sr2;
weapon w1(weapon_type1,hc1,sr1);
weapon w2(weapon_type2,hc2,sr2);
knight k1(name1, stamina1, true);
knight k2(name2, stamina2, true);
cout<<"Press any key to begin the Joust"<<endl;
cin>>f;
do
{
if(w1.did_you_hit()==true){cout<<"knight 2 is off the horse"<<endl;}
if(w2.did_you_hit()==true){cout<<"knight 1 is off the horse"<<endl;}
if(k1.stamina_remaining()<=0){cout<<"knight 1 is exhausted"<<endl;}
if(k2.stamina_remaining()<=0){cout<<"knight 2 is exhausted"<<endl;}
cout<<"=============================="<<endl;
knight cool;
cool.display();
}
while(k1.stamina_remaining()>0 && k2.stamina_remaining()>0 && w1.did_you_hit()==false && w2.did_you_hit()==false);
return 0;
}