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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
#ifndef ARMOR_H_
#define ARMOR_H_
#include <iostream>
#include <string>
using namespace std;
enum armor { head, chest, arms, legs };
struct CraftArmor {
int AVOIDED[4];
int DURABILITY[4];
double WEIGHT;
int CAMO;
string NAME;
};
class Armor
{
private:
int defenseRating; // calculated after the other variables are
// entered.
double weight; // in kg
int camouflage; // % from 0 - 100
int armorPieces[4]; // how many % does the pieces protect
int armorDurability[4]; // hp of each individual part
// 100 is the best possible normal humans
// will use. (a robot suit would be more)
string name;
public:
Armor(const CraftArmor & armor)
{
for(int i = 0; i < 4; i++)
armorPieces[i] = armor.AVOIDED[i];
for(int i = 0; i < 4; i++)
armorDurability[i] = armor.DURABILITY[i];
weight = armor.WEIGHT;
camouflage = armor.CAMO;
name = armor.NAME;
}
Armor(int a[], int b[], double w=0, int camo=0, string nm = "not specified")
{
for(int i = 0; i < 4; i++)
armorPieces[i] = a[i];
for(int i = 0; i < 4; i++)
armorDurability[i] = b[i];
weight = w;
camouflage = camo;
name = nm;
}
Armor() // no armor
{
int a[4] = { 0 };
int b[4] = { 0 };
double w=0;
int camo=0;
for(int i = 0; i < 4; i++)
armorPieces[i] = a[i];
for(int i = 0; i < 4; i++)
armorDurability[i] = b[i];
weight = w;
camouflage = camo;
name = "no armor";
}
Armor(bool manual)
{
cout << "What is the name of the armor?\nname: ";
cin >> name;
cout << "How heavy is the armor? (kilograms)\nweight: ";
cin >> weight;
cout << "How good is the camouflage? 0% no camo, 100% invisible\ncamo: ";
cin >> camouflage;
string pieces[4] = { "head", "chest", "arms", "legs" };
cout << "What is the % of damage avoided each attack\n"
<< "and how good is the durability of the armor?\n";
for(int i = 0; i < 4; i++)
{
cout << "avoided, " << pieces[i] << ": ";
cin >> armorPieces[i];
cout << "durability, " << pieces[i] << ": ";
cin >> armorDurability[i];
}
}
void updateDefenseRating() // this is an average of the pieces
// of armor. Its only use will be get
// the overall defense.
{
defenseRating = 0;
if(noDefenseLeft())
defenseRating = 0;
else
{
for(int i = 0; i < 4; i++)
defenseRating += armorPieces[i];
for(int i = 0; i < 4; i++)
defenseRating += armorDurability[i];
defenseRating += camouflage;
defenseRating /= 9; // find the overall average!
}
}
void showDefenseRating()
{
updateDefenseRating();
cout << "Defense rating of the warrior: " << defenseRating
<< endl;
}
int returnDefenseRating() { return defenseRating; }
void updateArmor()
{
updateDefenseRating();
if(armorDurability[head] == 0 && armorDurability[chest] == 0
&& armorDurability[arms] == 0 && armorDurability[legs] == 0)
{ weight = 0; camouflage = 0; updateDefenseRating(); } // armor is destroyed
}
int armorDamaged(int attackDamage, int part)
{
int damageAvoided = 0;
if(armorDurability[part] > 0 && armorPieces[part] > 0)
{
damageAvoided += attackDamage * float(armorPieces[part])/100.0;
armorDurability[part] -= damageAvoided;
// the design could be better, the % of damage blocked doesn't decrease as
// the armor gets damaged. This is not that important to have now
// and can be added in the future.
}
if(0 <= attackDamage - damageAvoided) // returns the attack damage left after
// damage avoided is subtracted.
return attackDamage - damageAvoided;
else
return 0;
}
void Show()
{
updateArmor();
cout << "Name: " << name << endl;
cout << "Defense rating: " << defenseRating << endl;
cout << "Weight: " << weight << endl << endl;
if(!noDefenseLeft())
{
cout << "(percent of damage avoided, durability):\n"; // head, chest, arms, legs
cout << "Head: (" << armorPieces[head] << ", " << armorDurability[head] << ")\n";
cout << "Chest: (" << armorPieces[chest] << ", " << armorDurability[chest] << ")\n";
cout << "Arms: (" << armorPieces[arms] << ", " << armorDurability[arms] << ")\n";
cout << "Legs: (" << armorPieces[legs] << ", " << armorDurability[legs] << ")\n";
}
else
cout << "No armor\n";
}
bool noDefenseLeft()
{
return (armorDurability[head] == 0 && armorDurability[chest] == 0
&& armorDurability[arms] == 0 && armorDurability[legs] == 0);
}
};
#endif
|