-
Notifications
You must be signed in to change notification settings - Fork 0
/
weapon.cpp
34 lines (28 loc) · 843 Bytes
/
weapon.cpp
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
#include "weapon.h"
#include <stdexcept>
namespace da_game {
Weapon::Weapon(unsigned int attack, float ratio) {
this->strength = attack;
if (ratio >= 0 && ratio <= 1) {
this->ratio = ratio;
}
else {
// Shouldnt happen
this->ratio = 0;
throw std::out_of_range("index out of range");
}
}
std::string Weapon::type() const {
return "Weapon";
}
int Weapon::attack_strength() const {
return strength;
}
float Weapon::hit_ratio() const {
return ratio;
}
void Weapon::save(std::fstream & save) {
save << "OBJ" << id << ":" << type();
save << ":" << weight() << "kg," << volume() << "liter," << price() << "kr," << strength << "strength," << ratio << "ratio" << std::endl;
}
}