Skip to content
Snippets Groups Projects
Commit 3f871b72 authored by Max Cherris's avatar Max Cherris
Browse files

Add function prototypes for combat, updating position and movement

parent 9df4dc5f
No related branches found
No related tags found
No related merge requests found
#include "unit.hpp" #include "unit.hpp"
Unit::Unit(int x, int y): x(x), y(y) {}; Unit::Unit(std::string name, int health, int speed, int attack, std::pair<int, int> range, MovementType movement, WeaponType weapon)
: name(std::move(name)), health(health), speed(speed), attack(attack), range(range), movement(movement), weapon(weapon) {}
//TODO: IF necessary, implement scaling attack by remaining health
void Unit::init_combat(Unit defender)
{
//Attacker gets first move, inflicts its damage upon the the defender
defender.setHealth(defender.getHealth() - this.getAttack());
//if defender survives, it gets to inflict its damage upon the attacker
if(defender.getHealth() > 0) {
this.setHealth(this.getHealth() - defender.getAttack());
} else { //if ded, defender gets deleted
defender.~Unit();
}
}
void Unit::update_position(int posX, int posY)
{
this.setX(posX);
this.setY(posY);
}
...@@ -90,6 +90,27 @@ private: ...@@ -90,6 +90,27 @@ private:
{{MovementType::SHIPENGINE, TerrainType::STREET}, 999}, {{MovementType::SHIPENGINE, TerrainType::STREET}, 999},
{{MovementType::SHIPENGINE, TerrainType::WATER}, 1} {{MovementType::SHIPENGINE, TerrainType::WATER}, 1}
}; };
/*
The attacker will move towards the defender and thus initiate combat
@params Takes a reference to the defender
Will Update the health for both units
Attacker deals damage to the defender first
*/
void init_combat(Unit defender);
/*
@params Takes the desired position of the unit and updates its values
*/
void update_position(int posX, int posY);
/*
This function needs to be able to determine the possible movement-paths the unit can take
MUST take into consideration that different units behave differently on certain terrain
MUST show all movements possible
*/
void calculate_movement();
}; };
#endif // UNIT_HPP #endif // UNIT_HPP
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment