aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main/cpp/Bullet.cpp11
-rw-r--r--src/main/cpp/MeleeWeapon.cpp64
-rw-r--r--src/main/cpp/RangedWeapon.cpp29
-rw-r--r--src/main/cpp/Stick.cpp11
-rw-r--r--src/main/headers/Actor.hpp19
-rw-r--r--src/main/headers/Bullet.hpp7
-rw-r--r--src/main/headers/Item.hpp9
-rw-r--r--src/main/headers/MeleeWeapon.hpp2
-rw-r--r--src/main/headers/RangedWeapon.hpp2
-rw-r--r--src/main/headers/Stick.hpp7
-rw-r--r--src/main/headers/Weapon.hpp2
11 files changed, 145 insertions, 18 deletions
diff --git a/src/main/cpp/Bullet.cpp b/src/main/cpp/Bullet.cpp
new file mode 100644
index 0000000..c856213
--- /dev/null
+++ b/src/main/cpp/Bullet.cpp
@@ -0,0 +1,11 @@
+#include "Bullet.hpp"
+
+bool Bullet::decreaseAmount(int qnt)
+{
+ if (_amount >= qnt) {
+ _amount = _amount - qnt;
+ return true;
+ } else {
+ return false;
+ }
+}
diff --git a/src/main/cpp/MeleeWeapon.cpp b/src/main/cpp/MeleeWeapon.cpp
index 92c7632..8c7ffce 100644
--- a/src/main/cpp/MeleeWeapon.cpp
+++ b/src/main/cpp/MeleeWeapon.cpp
@@ -1,15 +1,71 @@
+#include "Weapon.hpp"
#include "MeleeWeapon.hpp"
#include "Actor.hpp"
#include <string>
-MeleeWeapon::MeleeWeapon(Type t, const std::string &name)
-: Weapon(name), type(t)
+MeleeWeapon::MeleeWeapon(Type t, const std::string &name, bool throwable)
+: Weapon(Item::Type::MELEEWEAPON, name), type(t), _throwable(throwable)
{
}
bool MeleeWeapon::use(Actor &user, Actor &actor)
{
- //TODO implement attack probability
- //actor.damage(_damage);
+ //TODO implements attack probability
+ //TODO balance advantages
+ MeleeWeapon* weapon = dynamic_cast <MeleeWeapon*> (user.weapon());
+ int bonus;
+
+ if (MeleeWeapon* enemyWeapon = dynamic_cast <MeleeWeapon*> (actor.weapon())) {
+ switch (weapon->type) {
+ case MeleeWeapon::Type::AXE:
+ switch (enemyWeapon->type) {
+ case MeleeWeapon::Type::AXE:
+ bonus = 0;
+ break;
+ case MeleeWeapon::Type::LANCE:
+ bonus = 10;
+ break;
+ case MeleeWeapon::Type::SWORD:
+ bonus = -10;
+ break;
+ }
+ break;
+ case MeleeWeapon::Type::LANCE:
+ switch (enemyWeapon->type) {
+ case MeleeWeapon::Type::AXE:
+ bonus = -10;
+ break;
+ case MeleeWeapon::Type::LANCE:
+ bonus = 0;
+ break;
+ case MeleeWeapon::Type::SWORD:
+ bonus = 10;
+ break;
+ }
+ break;
+ case MeleeWeapon::Type::SWORD:
+ switch (enemyWeapon->type) {
+ case MeleeWeapon::Type::AXE:
+ bonus = 10;
+ break;
+ case MeleeWeapon::Type::LANCE:
+ bonus = -10;
+ break;
+ case MeleeWeapon::Type::SWORD:
+ bonus = 0;
+ break;
+ }
+ break;
+ }
+ } else {
+ bonus = 0;
+ }
+
+ if (actor.levelAxe() <= _requiredLevel) {
+ actor.damage(_damage + user.attack() - actor.defence() + bonus);
+ return true;
+ } else {
+ return false;
+ }
}
diff --git a/src/main/cpp/RangedWeapon.cpp b/src/main/cpp/RangedWeapon.cpp
index eb33780..21feae4 100644
--- a/src/main/cpp/RangedWeapon.cpp
+++ b/src/main/cpp/RangedWeapon.cpp
@@ -1,12 +1,9 @@
#include "RangedWeapon.hpp"
#include "Actor.hpp"
-
-#include <string>
-#include <algorithm>
-#include <vector>
+#include "Bullet.hpp"
RangedWeapon::RangedWeapon(const std::string &name)
-: Weapon(name)
+: Weapon(Item::Type::RANGEDWEAPON, name)
{
}
@@ -19,7 +16,25 @@ bool RangedWeapon::use(Actor &user, Actor &actor)
}
}
-void RangedWeapon::reload(Actor &actor)
+bool RangedWeapon::reload(Actor &actor)
{
- //std::vector<Item> bullet = actor.bullet();
+ //TODO add bullet type
+ std::list<Item*> inventory = actor.inventory();
+ for (Item* item : inventory) {
+ if (item->type == Item::Type::BULLET) {
+ //TODO get the bullet
+ //Bullet* bullet = dynamic_cast <Bullet*> (item);
+ break;
+ }
+ }
+
+ /*
+ if (bullet->decreaseAmount(1)) {
+ _charged = true;
+ return true;
+ } else {
+ return false;
+ }
+ */
+
}
diff --git a/src/main/cpp/Stick.cpp b/src/main/cpp/Stick.cpp
new file mode 100644
index 0000000..bc67ccb
--- /dev/null
+++ b/src/main/cpp/Stick.cpp
@@ -0,0 +1,11 @@
+#include "Stick.hpp"
+
+Stick::Stick(const std::string &name, int maxUses) : Item(Item::Type::STICK, name), _maxUses(maxUses)
+{
+ _remainingUses = _maxUses;
+}
+
+bool Stick::use(Actor &user, Actor &actor)
+{
+
+}
diff --git a/src/main/headers/Actor.hpp b/src/main/headers/Actor.hpp
index 14c4fff..90535b1 100644
--- a/src/main/headers/Actor.hpp
+++ b/src/main/headers/Actor.hpp
@@ -38,6 +38,16 @@ public:
const std::list<Item*>& inventory() const { return _inventory; }
+ //TODO add weaponslot
+ Item* weapon() const { return _weapon; }
+
+ unsigned levelAxe() const { return _levelAxe; }
+ unsigned levelLance() const { return _levelLance; }
+ unsigned levelSword() const { return _levelSword; }
+ unsigned levelRanged() const { return _levelRanged; }
+ unsigned levelStick() const { return _levelStick; }
+ unsigned levelMedicine() const { return _levelMedicine; }
+
int x() { return _x; }
int y() { return _y; }
@@ -66,6 +76,15 @@ protected:
unsigned _inventorySize;
std::list<Item*> _inventory;
+ Item* _weapon;
+
+ unsigned _levelAxe;
+ unsigned _levelLance;
+ unsigned _levelSword;
+ unsigned _levelRanged;
+ unsigned _levelStick;
+ unsigned _levelMedicine;
+
Actor(std::string _name, unsigned _maxHp);
};
diff --git a/src/main/headers/Bullet.hpp b/src/main/headers/Bullet.hpp
index e38c3f2..6ab5dbe 100644
--- a/src/main/headers/Bullet.hpp
+++ b/src/main/headers/Bullet.hpp
@@ -3,10 +3,11 @@
#include "Item.hpp"
-class Bullet : public Item
+class Bullet : protected Item
{
public:
- bool use(RangedWeapon &weapon);
-}
+ virtual bool use(RangedWeapon &weapon);
+ virtual bool decreaseAmount(int qnt);
+};
#endif
diff --git a/src/main/headers/Item.hpp b/src/main/headers/Item.hpp
index caa1e6f..56f8733 100644
--- a/src/main/headers/Item.hpp
+++ b/src/main/headers/Item.hpp
@@ -11,11 +11,18 @@ class Actor;
class Item
{
public:
+ enum Type {
+ BULLET, MELEEWEAPON, RANGEDWEAPON, STICK, HEAL, FOOD
+ };
+
+ const Type type;
+
Item() = delete;
virtual ~Item() {}
virtual bool use(Actor &user, Actor &actor) = 0;
+ int amount() { return _amount; }
bool stackable() { return _maxAmount == 1; }
protected:
@@ -24,7 +31,7 @@ protected:
const std::string _name;
- Item(const std::string &name) : _name(name) {}
+ Item(Type t, const std::string &name) : _name(name), type(t) {}
};
#endif
diff --git a/src/main/headers/MeleeWeapon.hpp b/src/main/headers/MeleeWeapon.hpp
index b98d027..97a0930 100644
--- a/src/main/headers/MeleeWeapon.hpp
+++ b/src/main/headers/MeleeWeapon.hpp
@@ -16,7 +16,7 @@ public:
const Type type;
- MeleeWeapon(Type t, const std::string &name);
+ MeleeWeapon(Type t, const std::string &name, bool throwable);
bool use(Actor &user, Actor &actor);
protected:
diff --git a/src/main/headers/RangedWeapon.hpp b/src/main/headers/RangedWeapon.hpp
index 0cc3be1..e5b0b66 100644
--- a/src/main/headers/RangedWeapon.hpp
+++ b/src/main/headers/RangedWeapon.hpp
@@ -11,7 +11,7 @@ class RangedWeapon : public Weapon
public:
RangedWeapon(const std::string &name);
bool use(Actor &user, Actor &actor);
- void reload(Actor &actor);
+ bool reload(Actor &actor);
protected:
bool _charged;
diff --git a/src/main/headers/Stick.hpp b/src/main/headers/Stick.hpp
index 4ed2b45..724e36d 100644
--- a/src/main/headers/Stick.hpp
+++ b/src/main/headers/Stick.hpp
@@ -5,6 +5,13 @@
class Stick : public Item
{
+public:
+ Stick(const std::string &name);
+ bool use(Actor &user, Actor &actor);
+
+protected:
+ const int _maxUses;
+ int _remainingUses;
};
diff --git a/src/main/headers/Weapon.hpp b/src/main/headers/Weapon.hpp
index 4c134ea..40eb7a3 100644
--- a/src/main/headers/Weapon.hpp
+++ b/src/main/headers/Weapon.hpp
@@ -12,7 +12,7 @@ protected:
unsigned _damage;
unsigned _requiredLevel;
- Weapon(const std::string &name) : Item(name) {}
+ Weapon(Item::Type t, const std::string &name) : Item(t, name) {}
};
#endif