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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
#include<iostream>
#include<string>
#include"Random.h"
using namespace std;
class Weapon
{
private:
int hit_chance;
int stamina_required;
string weapon_type;
public:
void display (void);
Weapon(string type, int sr, int hc);
bool did_you_hit();
int get_stamina_required(void);
};
Weapon:: Weapon(string type, int sr, int hc)
:hit_chance(hc), stamina_required(sr), weapon_type(type)
{
}
void Weapon::display(void)
{
std::cout<< "hit chance: " << hit_chance << endl;
std::cout<< "stamina required: " << stamina_required << endl;
}
int Weapon::get_stamina_required(void)
{
return stamina_required;
}
bool Weapon:: did_you_hit()
{
Random r(1,100);
int prob=r.get();
if (hit_chance<=prob)
{
did_you_hit()==false;
}
else
did_you_hit()==true;
}
class Knight
{
private:
string name;
int stamina;
public:
Knight(string n, int stam, const Weapon);
Weapon weapon_in_hand;
bool attack();
bool on_horse();
};
Knight::Knight(string n, int stam, const Weapon)
:name(n), stamina(stam)
{
}
bool Knight::on_horse()
{
if (stamina<=0)
{
std::cout << name << " is exhausted." << endl;
return false;
}
else
return true;
}
bool Knight::attack(const Weapon &w)
{ stamina -= w.get_stamina_required();
did_you_hit;
}
{
if did_you_hit()
{
stamina -= get_stamina_required();
}
else
{
stamina -= stamina_required;
}
}
int main()
{
Knight k1;
cout << "What is the first knights name?" << endl;
cin >> k1.name;
cout << "What is" << k1.name << "stamina?" << endl;
cin >> k1.stamina;
cout << "What is knights weapon?" << endl;
cin >> k1.weapon;
cout << "What is the weapon's hit chance?" << endl;
cin >> w1.hit_chance;
cout << "What is the weapon's stamina required to use?" << endl;
cin >> w1.sr;
Knight k2;
cout << "What is the second knights name?" << endl;
cin >> k2.name;
cout << "What is" << name << "stamina?" << endl;
cin >> k2.stamina;
cout << "What is knights weapon?" << endl;
cin >> k2.weapon;
cout << "What is weapon's hit chance?" << endl;
cin >> w2.hc;
cout << "What is weapon's stamina required?" << endl;
cin >> w2.sr;
while(k1==on_horse)
{
k1.attack;
if(did_you_hit==false)
{
k2.attack;
}
else
}
}
|