diff --git a/game/Makefile b/game/Makefile new file mode 100644 index 0000000..5aeb1cc --- /dev/null +++ b/game/Makefile @@ -0,0 +1,22 @@ +all: build run clean clear + +newrelease: release runrelease clear +play: runrelease clear + +build: + g++ main.cpp utilities.cpp player.cpp ennemy.cpp spells.cpp interfaces.cpp combat.cpp -o main + +release: + g++ main.cpp utilities.cpp player.cpp ennemy.cpp spells.cpp interfaces.cpp combat.cpp -o release + +runrelease: + ./release + +run: + ./main + +clean: + rm main + +clear: + clear \ No newline at end of file diff --git a/game/combat.cpp b/game/combat.cpp new file mode 100644 index 0000000..2b0be8a --- /dev/null +++ b/game/combat.cpp @@ -0,0 +1,110 @@ +#include +#include +#include "structs.h" +#include "utilities.h" +#include "player.h" +#include "ennemy.h" +#include "spells.h" +#include "interfaces.h" +#include "combat.h" + +void init_combat(Player& player_arg, std::vector ennemies_arg) { + std::vector ennemies; + ennemies.push_back(ennemies_arg[1]); + ennemies.push_back(ennemies_arg[2]); + + combat(player_arg, ennemies); +} + +void combat(Player& player_arg, std::vector& ennemies_arg) { + int arg; + bool combat_loop = 1; + while (combat_loop) { + inc_speed(player_arg, -1); + if (player_arg.speed == 0) { + player_turn(player_arg, ennemies_arg, combat_loop, arg); + check_deads(player_arg, ennemies_arg, combat_loop); + init_speed(player_arg); + } + for (Ennemy& ennemy: ennemies_arg) { + inc_speed(ennemy, -1); + if (ennemy.speed == 0) { + ennemy_turn(player_arg, ennemy); + check_deads(player_arg, ennemies_arg, combat_loop); + init_speed(ennemy); + } + } + } +} +void check_deads(Player& player_arg, std::vector& ennemies_arg, bool& combat_loop) { + if (player_arg.health == 0) { + combat_loop = 0; + } + int i = 0; + for(Ennemy& ennemy: ennemies_arg) { + if (ennemy.health == 0) { + ennemies_arg.erase(ennemies_arg.begin() + i); + } + i++; + } +} + +void player_turn(Player& player_arg, std::vector& ennemies_arg, bool& combat_loop_arg, int& arg) { + display_combat_menu(player_arg, ennemies_arg); + std::cin >> arg; + select_combat_action(arg, player_arg, combat_loop_arg, ennemies_arg); +} + +void select_combat_action(int arg, Player& player_arg, bool& combat_loop_arg, std::vector& ennemies_arg) { + switch (arg){ + case 1: + print_spell_book(player_arg.spell_book); + break; + case 2: + attack(player_arg, ennemies_arg); + break; + case 3: + if(player_escape(player_arg, ennemies_arg)) { + std::cout << "Escape succesfully" << std::endl; + combat_loop_arg = 0; + } else { + std::cout << "Escape not succesfully" << std::endl; + } + break; + default: + combat_loop_arg = 0; + break; + } +} + +Spell choose_spell(const Ennemy& ennemy_arg) { + std::vector spells(ennemy_arg.spells.size()); + int i = random_choice(spells); + return ennemy_arg.spells[i]; +} + +void ennemy_turn(Player& player_arg, Ennemy& ennemy_arg) { + display_ennemi_turn(ennemy_arg); + Spell spell = choose_spell(ennemy_arg); + ennemy_use_spell(spell, player_arg, ennemy_arg); +} + +void attack(Player& player_arg, std::vector& ennemies_arg){ + if(player_arg.job == 0) { + casting_spell(player_arg, ennemies_arg); + } +} + +bool player_escape(const Player& player_arg, std::vector& ennemies_arg) { + float min = 1; + for(Ennemy& ennemy: ennemies_arg) { + if(ennemy.menace < min) { + min = ennemy.menace; + } + } + return random_success(player_arg.escape * min); +} + +bool escape(const Ennemy& ennemy_arg) { + return random_success(ennemy_arg.escape); +} \ No newline at end of file diff --git a/game/combat.h b/game/combat.h new file mode 100644 index 0000000..c21457d --- /dev/null +++ b/game/combat.h @@ -0,0 +1,15 @@ + +void init_combat(Player& player_arg, std::vector ennemies_arg); +void combat(Player& player_arg, std::vector& ennemies_arg); + +void check_deads(Player& player_arg, std::vector& ennemies_arg, bool& combat_loop); + +void player_turn(Player& player_arg, std::vector& ennemies_arg, bool& combat_loop_arg, int& arg); +void select_combat_action(int arg, Player& player_arg, bool& combat_loop_arg, std::vector& ennemies_arg); + +Spell choose_spell(const Ennemy& ennemy_arg); +void ennemy_turn(Player& player_arg, Ennemy& ennemy_arg); + +void attack(Player& player_arg, std::vector& ennemies_arg); +bool player_escape(const Player& player_arg, std::vector& ennemies_arg); +bool escape(const Ennemy& ennemy_arg); \ No newline at end of file diff --git a/game/ennemy.cpp b/game/ennemy.cpp new file mode 100644 index 0000000..3638459 --- /dev/null +++ b/game/ennemy.cpp @@ -0,0 +1,82 @@ +#include +#include +#include +#include "structs.h" +#include "ennemy.h" +#include "spells.h" + +void init_ennemy(Ennemy& ennemy_arg, + std::string name_arg, + int xp_arg, + int max_health_arg, + int max_shield_arg, + int max_speed_arg, + int max_tame_arg, + float escape_arg, + float menace_arg, + std::vector spells_arg +) { + ennemy_arg.name = name_arg; + ennemy_arg.xp = xp_arg; + ennemy_arg.max_health = max_health_arg; + ennemy_arg.max_shield = max_shield_arg; + ennemy_arg.max_speed = max_speed_arg; + ennemy_arg.max_tame = max_tame_arg; + init_stats(ennemy_arg); + ennemy_arg.escape = escape_arg; + ennemy_arg.menace = menace_arg; + ennemy_arg.spells = spells_arg; +} + +void init_speed(Ennemy& ennemy_arg) { + ennemy_arg.speed = ennemy_arg.max_speed; +} +void init_stats(Ennemy& ennemy_arg) { + ennemy_arg.health = ennemy_arg.max_health; + ennemy_arg.shield = ennemy_arg.max_shield; + ennemy_arg.speed = ennemy_arg.max_speed; + ennemy_arg.tame = ennemy_arg.max_tame; +} + +void create_ennemies(std::vector& ennemies_arg) { + std::vector all_spells; + init_spells(all_spells); + + Ennemy emplialin; + init_ennemy(emplialin, "Emplialin", 60, 40, 50, 20, 50, 0.8, 0.6, std::vector{all_spells[0], all_spells[2], all_spells[4]}); + ennemies_arg.push_back(emplialin); + + Ennemy arzkalin; + init_ennemy(arzkalin, "Arzkalin", 60, 70, 60, 10, 100, 1.0, 0.5, std::vector{all_spells[1], all_spells[3], all_spells[4]}); + ennemies_arg.push_back(arzkalin); + + Ennemy coindithai; + init_ennemy(coindithai, "Coindithaï", 32, 30, 15, 20, 10, 0.9, 0.8, std::vector{all_spells[5]}); + ennemies_arg.push_back(coindithai); +} + +void inc_health(Ennemy& ennemy_arg, int value_arg){ + ennemy_arg.health += value_arg; +} +void inc_shield(Ennemy& ennemy_arg, int value_arg){ + ennemy_arg.shield += value_arg; +} +void inc_speed(Ennemy& ennemy_arg, int value_arg){ + ennemy_arg.speed += value_arg; +} + +void print_ennemy(const Ennemy& ennemy_arg) { + std::cout << ennemy_arg.name << std::endl; + std::cout << "Xp: " << ennemy_arg.xp << std::endl; + std::cout << "Health: " << ennemy_arg.health << "/"<< ennemy_arg.max_health << std::endl; + std::cout << "Shield: " << ennemy_arg.shield << "/"<< ennemy_arg.max_shield << std::endl; + std::cout << "Speed: " << ennemy_arg.speed << "/"<< ennemy_arg.max_speed << std::endl; + std::cout << "Speed: " << ennemy_arg.tame << "/"<< ennemy_arg.max_tame << std::endl; + std::cout << "Escape: " << ennemy_arg.escape * 100 << "%"<< std::endl; + std::cout << "Menace: " << ennemy_arg.menace * 100 << "%"<< std::endl; + std::cout << "Spells: "; + for (Spell spell: ennemy_arg.spells) { + std::cout << spell.name << ", "; + } + std::cout << std::endl << std::endl; +} \ No newline at end of file diff --git a/game/ennemy.h b/game/ennemy.h new file mode 100644 index 0000000..15c5c35 --- /dev/null +++ b/game/ennemy.h @@ -0,0 +1,25 @@ + +void init_ennemy(Ennemy& ennemy_arg, + std::string name_arg, + int xp_arg, + int health_arg, + int shield_arg, + int speed_arg, + int tame_arg, + int max_health_arg, + int max_shield_arg, + int max_speed_arg, + int max_tame_arg, + float escape_arg, + float menace_arg, + std::vector spells_arg +); +void init_speed(Ennemy& ennemy_arg); +void init_stats(Ennemy& ennemy_arg); +void create_ennemies(std::vector& ennemies_arg); + +void inc_health(Ennemy& ennemy_arg, int value_arg); +void inc_shield(Ennemy& ennemy_arg, int value_arg); +void inc_speed(Ennemy& ennemy_arg, int value_arg); + +void print_ennemy(const Ennemy& ennemy_arg); \ No newline at end of file diff --git a/game/interfaces.cpp b/game/interfaces.cpp new file mode 100644 index 0000000..9470556 --- /dev/null +++ b/game/interfaces.cpp @@ -0,0 +1,37 @@ +#include +#include +#include "structs.h" +#include "player.h" +#include "ennemy.h" +#include "interfaces.h" + +void display_menu() { + std::cout << "1. Search ennemies" << std::endl; + std::cout << "2. Quit" << std::endl; + std::cout << std::endl; +} + +void display_combat_menu(const Player& player_arg, const std::vector& ennemies_arg) { + std::cout << std::endl; + print_player(player_arg); + for (Ennemy ennemy: ennemies_arg) { + print_ennemy(ennemy); + } + std::cout << "1. Spell book" << std::endl; + std::cout << "2. Cast spell" << std::endl; + std::cout << "3. Escape" << std::endl; + std::cout << std::endl; +} + +void display_ennemi_turn(const Ennemy& ennemy_arg) { + std::cout << ennemy_arg.name << "'s turn" << std::endl; +} + +void display_ennemies(const std::vector& ennemies_arg) { + int i = 0; + for(Ennemy ennemy: ennemies_arg) { + std::cout << i << ", " << ennemy.name << std::endl; + i++; + } + std::cout << std::endl; +} \ No newline at end of file diff --git a/game/interfaces.h b/game/interfaces.h new file mode 100644 index 0000000..2a432ef --- /dev/null +++ b/game/interfaces.h @@ -0,0 +1,5 @@ + +void display_menu(); +void display_combat_menu(const Player& player_arg, const std::vector& ennemies_arg); +void display_ennemi_turn(const Ennemy& ennemy_arg); +void display_ennemies(const std::vector& ennemies_arg); \ No newline at end of file diff --git a/game/main.cpp b/game/main.cpp new file mode 100644 index 0000000..1fa1eb0 --- /dev/null +++ b/game/main.cpp @@ -0,0 +1,40 @@ +#include +#include +#include "structs.h" +#include "player.h" +#include "ennemy.h" +#include "spells.h" +#include "interfaces.h" +#include "combat.h" + +void select_menu(int arg, Player& player_arg, std::vector& ennemies_arg, bool& game_loop_arg); + +void select_menu(int arg, Player& player_arg, std::vector& ennemies_arg, bool& game_loop_arg) { + switch (arg){ + case 1: + init_combat(player_arg, ennemies_arg); + break; + case 2: + game_loop_arg = 0; + break; + default: + game_loop_arg = 0; + break; + } +} + +int main() { + Player mage; + init_default_mage(mage); + std::vector ennemies; + create_ennemies(ennemies); + + int arg; + bool game_loop = 1; + while (game_loop) { + display_menu(); + std::cin >> arg; + select_menu(arg, mage, ennemies, game_loop); + } + return 0; +} \ No newline at end of file diff --git a/game/player.cpp b/game/player.cpp new file mode 100644 index 0000000..084350d --- /dev/null +++ b/game/player.cpp @@ -0,0 +1,78 @@ +#include +#include +#include +#include "structs.h" +#include "utilities.h" +#include "player.h" +#include "spells.h" + +const int MAGE = 0; +const int ALCHIMIST = 1; +const int WARRIOR = 2; +const int ENGINEER = 3; +const int ARCHER = 4; +const int TAMER = 5; + + +void init_default_mage(Player& player_arg) { + player_arg.name = "Liam le dieu"; + player_arg.job = MAGE; + player_arg.xp = 0; + player_arg.max_health = 50; + player_arg.max_shield = 20; + player_arg.max_speed = 10; + player_arg.max_mana = 50; + player_arg.max_energy = 0; + init_stats(player_arg); + init_spells(player_arg.spell_book); + player_arg.escape = 1.0; + player_arg.menace = 0.7; +} + +void init_speed(Player& player_arg) { + player_arg.speed = player_arg.max_speed; +} + +void init_stats(Player& player_arg) { + player_arg.health = player_arg.max_health; + player_arg.shield = player_arg.max_shield; + player_arg.speed = player_arg.max_speed; + player_arg.mana = player_arg.max_mana; + player_arg.energy = player_arg.max_energy; +} + +void inc_health(Player& player_arg, int value_arg){ + player_arg.health += value_arg; +} +void inc_shield(Player& player_arg, int value_arg){ + player_arg.shield += value_arg; +} +void inc_speed(Player& player_arg, int value_arg){ + player_arg.speed += value_arg; +} +void inc_mana(Player& player_arg, int value_arg){ + player_arg.mana += value_arg; +} +void inc_energy(Player& player_arg, int value_arg){ + player_arg.energy += value_arg; +} + +void level_up(Player& player_arg, int xp_arg){ + player_arg.xp += xp_arg; +} + +void print_player(const Player& player_arg) { + std::vector jobs = {"Mage", "Alchimist", "Warrior", "Engineer", "Archer", "Tamer"}; + + std::cout << player_arg.name << std::endl; + std::cout << jobs[player_arg.job] << std::endl; + std::cout << "Xp: " << player_arg.xp << std::endl; + std::cout << "Health: " << player_arg.health << "/"<< player_arg.max_health << std::endl; + std::cout << "Shield: " << player_arg.shield << "/"<< player_arg.max_shield << std::endl; + std::cout << "Mana: " << player_arg.mana << "/"<< player_arg.max_mana << std::endl; + std::cout << "Energy: " << player_arg.energy << "/"<< player_arg.max_energy << std::endl; + std::cout << "Speed: " << player_arg.speed << "/"<< player_arg.max_speed << std::endl; + std::cout << "Escape: " << player_arg.escape * 100 << "%"<< std::endl; + std::cout << "Menace: " << player_arg.menace * 100 << "%"<< std::endl; + std::cout << std::endl; +} \ No newline at end of file diff --git a/game/player.h b/game/player.h new file mode 100644 index 0000000..fb48a35 --- /dev/null +++ b/game/player.h @@ -0,0 +1,15 @@ + +void init_default_mage(Player& player_arg); + +void init_speed(Player& player_arg); +void init_stats(Player& player_arg); + +void inc_health(Player& player_arg, int value_arg); +void inc_shield(Player& player_arg, int value_arg); +void inc_speed(Player& player_arg, int value_arg); +void inc_mana(Player& player_arg, int value_arg); +void inc_energy(Player& player_arg, int value_arg); + +void level_up(Player& player_arg, int xp_arg); + +void print_player(const Player& player_arg); \ No newline at end of file diff --git a/game/release b/game/release new file mode 100755 index 0000000..6b143c3 Binary files /dev/null and b/game/release differ diff --git a/game/spells.cpp b/game/spells.cpp new file mode 100644 index 0000000..2cf3afa --- /dev/null +++ b/game/spells.cpp @@ -0,0 +1,269 @@ +#include +#include +#include +#include "utilities.h" +#include "structs.h" +#include "player.h" +#include "ennemy.h" +#include "interfaces.h" +#include "spells.h" + + +// Elements +const int FIRE = 0; +const int AIR = 1; +const int WATER = 2; +const int EARTH = 3; +const int EATHER = 4; +const std::vector elements = {"Fire", "Air", "Water", "Earth", "Eather"}; + +// Combinaisons +const int UP = 0; +const int RIGHT = 1; +const int DOWN = 2; +const int LEFT = 3; +const int END_SPELL = 5; +const std::vector arrows = {"↑", "→", "↓", "←"}; + +void init_spell(Spell& spell_arg, const std::string& name_arg, int damage_arg, int cost_arg, float precision_arg, bool zone_arg, std::vector elements_arg, std::vector combinaison_arg) { + spell_arg.name = name_arg; + spell_arg.damage = damage_arg; + spell_arg.cost_mana = cost_arg; + spell_arg.cost_health = 0; + spell_arg.precision = precision_arg; + spell_arg.zone = zone_arg; + spell_arg.elements = elements_arg; + spell_arg.combinaison = combinaison_arg; +} + +void init_spells(std::vector& spell_book_arg) { + Spell fire_ball; + init_spell( + fire_ball, + "Fire Ball", + 10, + 5, + 0.8, + 1, + std::vector{FIRE}, + std::vector{UP, RIGHT, UP} + ); + spell_book_arg.push_back(fire_ball); + + Spell tsunami; + init_spell( + tsunami, + "Tsunami", + 15, + 8, + 1, + 1, + std::vector{WATER}, + std::vector{UP, DOWN, RIGHT} + ); + spell_book_arg.push_back(tsunami); + + Spell tailwind_css; + init_spell( + tailwind_css, + "Tailwind CSS", + 8, + 4, + 0.8, + 0, + std::vector{AIR}, + std::vector{UP, UP, UP} + ); + spell_book_arg.push_back(tailwind_css); + + Spell rolling_rock; + init_spell( + rolling_rock, + "Rolling Rock", + 15, + 13, + 0.7, + 0, + std::vector{EARTH}, + std::vector{DOWN, UP, LEFT} + ); + spell_book_arg.push_back(rolling_rock); + + Spell lightning; + init_spell( + lightning, + "Lightning", + 20, + 10, + 0.8, + 0, + std::vector{AIR, FIRE}, + std::vector{DOWN, UP, LEFT, UP} + ); + spell_book_arg.push_back(lightning); + + Spell bubble; + init_spell( + bubble, + "Bubble", + 5, + 2, + 1, + 0, + std::vector{AIR, WATER}, + std::vector{UP, UP, UP, UP} + ); + spell_book_arg.push_back(bubble); +} + +//Return -1 if no spells, 0 if a spell is totally completed and the only possible, else the number of spells possible +int possible_spell(const std::vector& spell_book_arg, const std::vector& spell_arg) { + int spells_count = 0; + for (const Spell& spell: spell_book_arg) { + if (spell.combinaison.size() >= spell_arg.size()) { + std::vector actual_spell(spell.combinaison.begin(), spell.combinaison.begin() + spell_arg.size()); + if (actual_spell == spell_arg) { + spells_count++; + } + } + } + return spells_count; +} + +Spell find_spell_by_combinaison(const std::vector& spell_book_arg, const std::vector& spell_arg) { + for (const Spell& spell: spell_book_arg) { + if (spell.combinaison == spell_arg) { + return spell; + } + } + return spell_book_arg[0]; +} + +//Return true if the player still can cast a spell +bool cast_spell(Player& player_arg, std::vector& spell_arg, int spell_segment_arg, std::vector& ennemies_arg) { + + std::vector spell_book = player_arg.spell_book; + + if (spell_segment_arg == END_SPELL) { + Spell casted_spell = find_spell_by_combinaison(spell_book, spell_arg); + if (spell_arg.size() == casted_spell.combinaison.size()) { + use_spell(casted_spell, player_arg, ennemies_arg); + } + return 0; + } else { + spell_arg.push_back(spell_segment_arg); + int count_spell = possible_spell(spell_book, spell_arg); + if (count_spell <= 1) { + if (count_spell == 1) { + Spell casted_spell = find_spell_by_combinaison(spell_book, spell_arg); + if (spell_arg.size() == casted_spell.combinaison.size()) { + use_spell(casted_spell, player_arg, ennemies_arg); + } else { + return 1; + } + } else if (count_spell == 0) { + std::cout << "Spell doesn't exist" << std::endl; + } + spell_arg = {}; + return 0; + } + } + return 1; +} + +void casting_spell(Player& player_arg, std::vector& ennemies_arg) { + std::vector spell; + int spell_segment; + do { + std::cin >> spell_segment; + } while (cast_spell(player_arg, spell, spell_segment, ennemies_arg)); + +} + +void use_spell(const Spell& spell_arg, Player& player_arg, std::vector& ennemies_arg) { + if (player_arg.mana - spell_arg.cost_mana >= 0) { + inc_health(player_arg, -spell_arg.cost_health); + inc_mana(player_arg, -spell_arg.cost_mana); + if(spell_arg.zone) { + for(Ennemy& ennemy: ennemies_arg) { + spell_damage(ennemy, spell_arg); + } + } else { + Ennemy& ennemy = choose_target(ennemies_arg); + spell_damage(ennemy, spell_arg); + } + std::cout << player_arg.name<< " casts " << spell_arg.name << std::endl; + } else { + std::cout << "Not enough mana" << std::endl; + } +} + +void spell_damage(Ennemy& ennemy_arg, const Spell& spell_arg) { + if(ennemy_arg.shield >= spell_arg.damage) { + inc_shield(ennemy_arg, -spell_arg.damage); + } else if(ennemy_arg.shield > 0) { + inc_health(ennemy_arg, ennemy_arg.shield - spell_arg.damage); + inc_shield(ennemy_arg, -ennemy_arg.shield); + } else if(ennemy_arg.health >= spell_arg.damage) { + inc_health(ennemy_arg, -spell_arg.damage); + } else { + inc_health(ennemy_arg, -ennemy_arg.health); + } +} + +Ennemy& choose_target(std::vector& ennemies_arg) { + display_ennemies(ennemies_arg); + int arg; + std::cin >> arg; + return ennemies_arg[arg]; +} + +void ennemy_use_spell(const Spell& spell_arg, Player& player_arg, Ennemy& ennemy_arg) { + inc_health(ennemy_arg, -spell_arg.cost_health); + + if(random_success(spell_arg.precision)) { + if(player_arg.shield >= spell_arg.damage) { + inc_shield(player_arg, -spell_arg.damage); + } else if(player_arg.shield > 0) { + inc_health(player_arg, player_arg.shield - spell_arg.damage); + inc_shield(player_arg, -player_arg.shield); + } else if(player_arg.health >= spell_arg.damage) { + inc_health(player_arg, -spell_arg.damage); + } else { + inc_health(player_arg, -player_arg.health); + } + std::cout << ennemy_arg.name<< " casts " << spell_arg.name << std::endl; + } else { + std::cout << ennemy_arg.name<< " fails " << spell_arg.name << std::endl; + } +} + +void print_spell(const Spell& spell_arg) { + std::cout << spell_arg.name << std::endl; + std::cout << "Damage : " << spell_arg.damage << std::endl; + std::cout << "Mana cost : " << spell_arg.cost_mana << std::endl; + if(spell_arg.cost_health > 0) { + std::cout << "Health cost : " << spell_arg.cost_health << std::endl; + } + std::cout << "Precision : " << spell_arg.damage << std::endl; + std::cout << "Elements : "; + for (int element: spell_arg.elements) { + std::cout << elements[element] << " "; + } + std::cout << std::endl; + if (spell_arg.zone) { + std::cout << "Zone" << std::endl; + } + std::cout << "Combinaison : "; + + for (int arrow: spell_arg.combinaison) { + std::cout << arrows[arrow] << " "; + } + std::cout << std::endl << std::endl; +} + +void print_spell_book(const std::vector& spell_book_arg) { + for (Spell spell: spell_book_arg) { + print_spell(spell); + } +} \ No newline at end of file diff --git a/game/spells.h b/game/spells.h new file mode 100644 index 0000000..70f6e77 --- /dev/null +++ b/game/spells.h @@ -0,0 +1,23 @@ + +void init_spell(Spell& spell_arg, + const std::string& name_arg, + int damage_arg, + int cost_arg, + float precision_arg, + bool zone_arg, + std::vector elements_arg, + std::vector combinaison_arg +); +void init_spells(std::vector& spell_book_arg); + +int possible_spell(const std::vector& spell_book_arg, const std::vector& spell_arg); +Spell find_spell_by_combinaison(const std::vector& spell_book_arg, const std::vector& spell_arg); +bool cast_spell(Player& player_arg, std::vector& spell_arg, std::vector& ennemies_arg); +void casting_spell(Player& player_arg, std::vector& ennemies_arg); +void use_spell(const Spell& spell_arg, Player& player_arg, std::vector& ennemies_arg); +void spell_damage(Ennemy& ennemy_arg, const Spell& spell_arg); +Ennemy& choose_target(std::vector& ennemies_arg); +void ennemy_use_spell(const Spell& spell_arg, Player& player_arg, Ennemy& ennemy_arg); + +void print_spell(const Spell& spell_arg); +void print_spell_book(const std::vector& spell_book_arg); diff --git a/game/structs.h b/game/structs.h new file mode 100644 index 0000000..b45d2f8 --- /dev/null +++ b/game/structs.h @@ -0,0 +1,27 @@ + +struct Spell { + std::string name; + int damage; + int cost_health, cost_mana; + float precision; + bool zone; + std::vector elements, combinaison; +}; + +struct Ennemy { + std::string name; + int xp; + int health, shield, speed, tame; + int max_health, max_shield, max_speed, max_tame; + float escape, menace; //Menace comlpexifies the escape, the higher the value is, the less menace it is + std::vector spells; +}; + +struct Player { + std::string name; + int job, xp; + int health, shield, speed, mana, energy; + int max_health, max_shield, max_speed, max_mana, max_energy; + float escape, menace; + std::vector spell_book; +}; \ No newline at end of file diff --git a/game/utilities.cpp b/game/utilities.cpp new file mode 100644 index 0000000..5223fb7 --- /dev/null +++ b/game/utilities.cpp @@ -0,0 +1,17 @@ +#include +#include +#include "utilities.h" + +bool random_success(float probability) { + std::random_device rd; + std::mt19937 gen(rd()); + std::bernoulli_distribution dist(probability); + return dist(gen); +} + +int random_choice(std::vector list) { + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> dis(0, list.size() - 1); + return dis(gen); +} \ No newline at end of file diff --git a/game/utilities.h b/game/utilities.h new file mode 100644 index 0000000..427da96 --- /dev/null +++ b/game/utilities.h @@ -0,0 +1,3 @@ + +bool random_success(float probability); +int random_choice(std::vector list); \ No newline at end of file