From c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:08:27 +0200 Subject: add: graphs et rushs --- graphs/cpp/war/assassin.cc | 5 +++++ graphs/cpp/war/assassin.hh | 8 ++++++++ graphs/cpp/war/knight.cc | 5 +++++ graphs/cpp/war/knight.hh | 8 ++++++++ graphs/cpp/war/regiment.cc | 38 ++++++++++++++++++++++++++++++++++++++ graphs/cpp/war/regiment.hh | 17 +++++++++++++++++ graphs/cpp/war/soldier.cc | 24 ++++++++++++++++++++++++ graphs/cpp/war/soldier.hh | 16 ++++++++++++++++ 8 files changed, 121 insertions(+) create mode 100644 graphs/cpp/war/assassin.cc create mode 100644 graphs/cpp/war/assassin.hh create mode 100644 graphs/cpp/war/knight.cc create mode 100644 graphs/cpp/war/knight.hh create mode 100644 graphs/cpp/war/regiment.cc create mode 100644 graphs/cpp/war/regiment.hh create mode 100644 graphs/cpp/war/soldier.cc create mode 100644 graphs/cpp/war/soldier.hh (limited to 'graphs/cpp/war') diff --git a/graphs/cpp/war/assassin.cc b/graphs/cpp/war/assassin.cc new file mode 100644 index 0000000..090ec8b --- /dev/null +++ b/graphs/cpp/war/assassin.cc @@ -0,0 +1,5 @@ +#include "assassin.hh" + +Assassin::Assassin() + : Soldier(10, 9, "Out of the shadows!") +{} diff --git a/graphs/cpp/war/assassin.hh b/graphs/cpp/war/assassin.hh new file mode 100644 index 0000000..548fd8b --- /dev/null +++ b/graphs/cpp/war/assassin.hh @@ -0,0 +1,8 @@ +#pragma once +#include "soldier.hh" + +class Assassin : public Soldier +{ +public: + Assassin(); +}; \ No newline at end of file diff --git a/graphs/cpp/war/knight.cc b/graphs/cpp/war/knight.cc new file mode 100644 index 0000000..be52105 --- /dev/null +++ b/graphs/cpp/war/knight.cc @@ -0,0 +1,5 @@ +#include "knight.hh" + +Knight::Knight() + : Soldier(20, 5, "Be quick or be dead!") +{} diff --git a/graphs/cpp/war/knight.hh b/graphs/cpp/war/knight.hh new file mode 100644 index 0000000..d4f2b5f --- /dev/null +++ b/graphs/cpp/war/knight.hh @@ -0,0 +1,8 @@ +#pragma once +#include "soldier.hh" + +class Knight : public Soldier +{ +public: + Knight(); +}; \ No newline at end of file diff --git a/graphs/cpp/war/regiment.cc b/graphs/cpp/war/regiment.cc new file mode 100644 index 0000000..3534ced --- /dev/null +++ b/graphs/cpp/war/regiment.cc @@ -0,0 +1,38 @@ +#include "regiment.hh" + +#include + +void Regiment::join_by(Regiment& r) +{ + if (r.soldiers_.empty()) + return; + std::vector v{ r.soldiers_.rbegin(), r.soldiers_.rend() }; + while (!v.empty()) + { + this->soldiers_.push_back(v.back()); + v.pop_back(); + } + r.soldiers_.clear(); +} +size_t Regiment::count() const +{ + return soldiers_.size(); +} +void Regiment::add_soldier(Soldier* s) +{ + soldiers_.push_back(s); +} +void Regiment::print_state() const +{ + for (auto soldier : soldiers_) + { + soldier->print_state(); + } +} +void Regiment::scream() const +{ + for (auto soldier : soldiers_) + { + soldier->scream(); + } +} \ No newline at end of file diff --git a/graphs/cpp/war/regiment.hh b/graphs/cpp/war/regiment.hh new file mode 100644 index 0000000..ac54953 --- /dev/null +++ b/graphs/cpp/war/regiment.hh @@ -0,0 +1,17 @@ +#pragma once +#include + +#include "soldier.hh" + +class Regiment +{ +public: + void join_by(Regiment& r); + size_t count() const; + void add_soldier(Soldier* s); + void print_state() const; + void scream() const; + +private: + std::vector soldiers_; +}; \ No newline at end of file diff --git a/graphs/cpp/war/soldier.cc b/graphs/cpp/war/soldier.cc new file mode 100644 index 0000000..01dc57c --- /dev/null +++ b/graphs/cpp/war/soldier.cc @@ -0,0 +1,24 @@ +#include "soldier.hh" + +#include + +Soldier::Soldier(int hp, int dmg, std::string scream) + : health_points_{ hp } + , damage_{ dmg } + , scream_{ scream } +{} + +void Soldier::print_state() const +{ + std::cout << "I have " << health_points_ << " health points.\n"; +} + +void Soldier::scream() const +{ + std::cout << scream_ << "\n"; +} + +void Soldier::attack(Soldier& s) +{ + s.health_points_ -= this->damage_; +} diff --git a/graphs/cpp/war/soldier.hh b/graphs/cpp/war/soldier.hh new file mode 100644 index 0000000..1406022 --- /dev/null +++ b/graphs/cpp/war/soldier.hh @@ -0,0 +1,16 @@ +#pragma once +#include + +class Soldier +{ +public: + Soldier(int hp, int dmg, std::string scream); + void attack(Soldier& s); + void print_state() const; + virtual void scream() const; + +private: + int health_points_; + int damage_; + std::string scream_; +}; \ No newline at end of file -- cgit v1.2.3