From 12d06b305d222745f1f20cf2ae98cd5ad32ddb7c Mon Sep 17 00:00:00 2001 From: Bartek Date: Tue, 5 Mar 2019 10:20:34 +0000 Subject: [PATCH] Fixed annoying file name/function inconsistencies, sorry about that. --- CMakeLists.txt | 2 +- include/{ability.hpp => Ability.hpp} | 4 +- include/{effect.hpp => Effect.hpp} | 0 include/Game.hpp | 14 +------ include/{hero.hpp => Hero.hpp} | 8 ++-- include/{mainMenu.hpp => MainMenu.hpp} | 0 include/Player.hpp | 11 +++-- main.cpp | 6 +-- src/{ability.cpp => Ability.cpp} | 16 ++++---- src/CMakeLists.txt | 6 +-- src/{effect.cpp => Effect.cpp} | 10 ++--- src/Game.cpp | 8 ++-- src/{hero.cpp => Hero.cpp} | 22 +++++----- src/{mainMenu.cpp => MainMenu.cpp} | 20 ++++----- src/{main_test.cpp => MainTest.cpp} | 0 src/Player.cpp | 9 ++++- src/Sample_ncurses.cpp | 56 -------------------------- src/{ultimate.cpp => Ultimate.cpp} | 0 src/heroSelection.cpp | 12 +++--- 19 files changed, 73 insertions(+), 131 deletions(-) rename include/{ability.hpp => Ability.hpp} (93%) rename include/{effect.hpp => Effect.hpp} (100%) rename include/{hero.hpp => Hero.hpp} (88%) rename include/{mainMenu.hpp => MainMenu.hpp} (100%) rename src/{ability.cpp => Ability.cpp} (95%) rename src/{effect.cpp => Effect.cpp} (90%) rename src/{hero.cpp => Hero.cpp} (91%) rename src/{mainMenu.cpp => MainMenu.cpp} (97%) rename src/{main_test.cpp => MainTest.cpp} (100%) delete mode 100644 src/Sample_ncurses.cpp rename src/{ultimate.cpp => Ultimate.cpp} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 80cf681..350177d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,5 +27,5 @@ target_link_libraries(main menu game window ${CURSES_LIBRARIES}) find_library(sqlite3 NAMES sqlite3 PATHS ${/usr/lib/x86_64-linux-gnu}) add_compile_options(-lsqlite3) -add_executable(hero ${CMAKE_SOURCE_DIR}/src/hero.cpp) +add_executable(hero ${CMAKE_SOURCE_DIR}/src/Hero.cpp) target_link_libraries(hero ability effect sqlite3) diff --git a/include/ability.hpp b/include/Ability.hpp similarity index 93% rename from include/ability.hpp rename to include/Ability.hpp index fb74b17..77be6da 100644 --- a/include/ability.hpp +++ b/include/Ability.hpp @@ -7,11 +7,11 @@ #include #include #include "libsqlite.hpp" -#include "effect.hpp" +#include "Effect.hpp" #include using namespace std; -class Ability +class Ability { private: string Ability_Name, Ability_Description; diff --git a/include/effect.hpp b/include/Effect.hpp similarity index 100% rename from include/effect.hpp rename to include/Effect.hpp diff --git a/include/Game.hpp b/include/Game.hpp index 87adb98..d4c898e 100644 --- a/include/Game.hpp +++ b/include/Game.hpp @@ -2,17 +2,7 @@ #define GAME_HPP #include -/* -class Game -{ -public: - static int gv_line_count; - WINDOW *game_view, *statuses, *abilities; -public: - Game(bool cbreak_present); -}; -*/ -void mainGame(); +void MainGame(); -#endif \ No newline at end of file +#endif diff --git a/include/hero.hpp b/include/Hero.hpp similarity index 88% rename from include/hero.hpp rename to include/Hero.hpp index ce13e07..ea9a346 100644 --- a/include/hero.hpp +++ b/include/Hero.hpp @@ -7,15 +7,15 @@ #include #include #include "libsqlite.hpp" -#include "ability.hpp" +#include "Ability.hpp" #include #include using namespace std; -class Hero +class Hero { private: - string Hero_Name, Hero_Description; + string Hero_Name, Hero_Description; int HP, SP, MP, SPD, DEF; vector ability_ids; vector abilities; @@ -35,4 +35,4 @@ public: friend ostream& operator<<( ostream&, const Hero&); }; -#endif \ No newline at end of file +#endif diff --git a/include/mainMenu.hpp b/include/MainMenu.hpp similarity index 100% rename from include/mainMenu.hpp rename to include/MainMenu.hpp diff --git a/include/Player.hpp b/include/Player.hpp index 6645fd8..8a38c15 100644 --- a/include/Player.hpp +++ b/include/Player.hpp @@ -1,16 +1,19 @@ #ifndef PLAYER_HPP #define PLAYER_HPP -#include -#include "hero.hpp" +#include +#include +#include "Hero.hpp" using namespace std; class Player { private: - vector heroes; + string name; + array heroes; public: - Player(vector selection); + Player(array selection); + Hero GetHero(int ID); } #endif diff --git a/main.cpp b/main.cpp index e371ca4..10da153 100644 --- a/main.cpp +++ b/main.cpp @@ -3,7 +3,7 @@ #include #include #include "include/Game.hpp" -#include "include/mainMenu.hpp" +#include "include/MainMenu.hpp" using namespace std; @@ -16,6 +16,6 @@ int main(int argc, char **argv) } vector args(argv, argv + argc); bool cbreak_present = find(args.begin(), args.end(), "cbreak") != args.end(); - mainMenu(); + MainMenu(); return 0; -} \ No newline at end of file +} diff --git a/src/ability.cpp b/src/Ability.cpp similarity index 95% rename from src/ability.cpp rename to src/Ability.cpp index 018532f..4f5da35 100644 --- a/src/ability.cpp +++ b/src/Ability.cpp @@ -1,5 +1,5 @@ -#include "../include/ability.hpp" -#include "../include/effect.hpp" +#include "../include/Ability.hpp" +#include "../include/Effect.hpp" #include Ability::Ability(int _id) @@ -12,7 +12,7 @@ Ability::Ability(int _id) cur->set_sql("SELECT * FROM Abilities WHERE Ability_ID = ?;"); cur->prepare(); cur->bind(1, _id); - + while(cur->step()) { Ability_Name = cur->get_text(1); @@ -24,23 +24,23 @@ Ability::Ability(int _id) Mana_Cost = cur->get_int(7); Stamina_Cost = cur->get_int(8); } - + cur->reset(); cur->set_sql("SELECT Effect_ID FROM Ability_Effects WHERE Ability_ID = ?;"); cur->prepare(); cur->bind(1, _id); - + while(cur->step()) { effect_ids.emplace_back(cur->get_int(0)); } - + } catch(sqlite::exception e) { cerr << e.what() << endl; } - + for(int i=0; i Effect::Effect(int _id) @@ -11,7 +11,7 @@ Effect::Effect(int _id) cur->set_sql("SELECT * FROM Effects WHERE Effect_ID = ?;"); cur->prepare(); cur->bind(1, _id); - + while(cur->step()) { Effect_Name = cur->get_text(1); @@ -24,12 +24,12 @@ Effect::Effect(int _id) { cerr << e.what() << endl; } - + }; ostream& operator<<( ostream& os, const Effect& effect ) { - os << effect.Effect_Name << "affects the " << effect.Target_Stat << " of the targeted hero for " + os << effect.Effect_Name << "affects the " << effect.Target_Stat << " of the targeted hero for " << effect.Duration << " turns and have an impact of " << effect.Impact << "." << endl; return os; -} \ No newline at end of file +} diff --git a/src/Game.cpp b/src/Game.cpp index 9474624..86492c5 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -6,7 +6,7 @@ using namespace std; -void mainGame() +void MainGame() { /* Setting up windows using GameWindow class */ initscr(); @@ -33,7 +33,7 @@ void mainGame() {"Ultimate", "Your ultimate move!"}, {"Transform", "Become different!"} }; - + bool game_over = false; int current_player = 1; int choice = -1; @@ -41,7 +41,7 @@ void mainGame() text_box.Clear(); text_box.Print(to_print); getch(); - + while(!game_over) { //text_box.Clear(); @@ -75,4 +75,4 @@ void mainGame() text_box.Clear(false); menu_desc.Clear(false); endwin(); -} \ No newline at end of file +} diff --git a/src/hero.cpp b/src/Hero.cpp similarity index 91% rename from src/hero.cpp rename to src/Hero.cpp index e86ee3a..6c9fe6c 100644 --- a/src/hero.cpp +++ b/src/Hero.cpp @@ -1,5 +1,5 @@ -#include "../include/hero.hpp" -#include "../include/ability.hpp" +#include "../include/Hero.hpp" +#include "../include/Ability.hpp" #include using namespace std; @@ -14,7 +14,7 @@ Hero::Hero(int _id) cur->set_sql("SELECT * FROM Heroes WHERE Hero_ID = ?;"); cur->prepare(); cur->bind(1, _id); - + while(cur->step()) { Hero_Name = cur->get_text(1); @@ -25,12 +25,12 @@ Hero::Hero(int _id) SPD = cur->get_int(6); DEF = cur->get_int(7); } - + cur->reset(); cur->set_sql("SELECT Ability_ID FROM Hero_Abilities WHERE Hero_ID = ?;"); cur->prepare(); cur->bind(1, _id); - + while(cur->step()) { ability_ids.emplace_back(cur->get_int(0)); @@ -40,7 +40,7 @@ Hero::Hero(int _id) { cerr << e.what() << endl; } - + for(int i=0; i(Hero_details) << endl; }**/ - + } int Hero::GetHP() {return HP;} @@ -61,12 +61,12 @@ int Hero::GetSPD() {return SPD;} int Hero::GetDEF() {return DEF;} void Hero::DealDMG(int dmg) {HP = dmg * ((100-DEF)/100);} -void Hero::TakeSP(int amount) +void Hero::TakeSP(int amount) { SP -= amount; if(SP < 0) SP = 0; } -void Hero::TakeMP(int amount) +void Hero::TakeMP(int amount) { MP -= amount; if(MP < 0) MP = 0; @@ -76,7 +76,7 @@ void Hero::SetDEF(int defence) {DEF = defence;} ostream& operator<<( ostream& os, const Hero& hero ) { - os << "Details of " << hero.Hero_Name << ":\n" + os << "Details of " << hero.Hero_Name << ":\n" << "HP: " << hero.HP << "\n" << "SP: " << hero.SP << "\n" << "MP: " << hero.MP << "\n" @@ -100,7 +100,7 @@ ostream& operator<<( ostream& os, const Ability& ability ) ostream& operator<<( ostream& os, const Effect& effect ) { - os << effect.Effect_Name << "affects the " << effect.Target_Stat << " of the targeted hero for " + os << effect.Effect_Name << "affects the " << effect.Target_Stat << " of the targeted hero for " << effect.Duration << " turns and have an impact of " << effect.Impact << "." << endl; return os; } diff --git a/src/mainMenu.cpp b/src/MainMenu.cpp similarity index 97% rename from src/mainMenu.cpp rename to src/MainMenu.cpp index ab62c2d..4fde7ba 100644 --- a/src/mainMenu.cpp +++ b/src/MainMenu.cpp @@ -1,4 +1,4 @@ -#include "../include/mainMenu.hpp" +#include "../include/MainMenu.hpp" #include "../include/Game.hpp" #include #include @@ -7,18 +7,18 @@ #include "../include/GameWindow.hpp" using namespace std; -void mainMenu() +void MainMenu() { setlocale(LC_ALL, ""); initscr(); cbreak(); noecho(); curs_set(0); - + vector choices ={"Start Battle","Help","Exit"}; bool gameOver=false; while(gameOver!=true) - { + { GameWindow titleWin(9, 52, 0, COLS/2 - 26); GameWindow menuWin(5,52,10,COLS/2 - 26); const char *c="______ _ _ ___ \n | ___ (_) | | / _ \\ \n | |_/ /___ _____| | / /_\\ \\_ __ ___ _ __ __ _ \n | __/| \\ \\/ / _ \\ | | _ | '__/ _ \\ '_ \\ / _` | \n | | | |> < __/ | | | | | | | __/ | | | (_| | \n \\_| |_/_/\\_\\___|_| \\_| |_/_| \\___|_| |_|\\__,_|"; @@ -41,16 +41,16 @@ void mainMenu() { titleWin.Clear(false); menuWin.Clear(false); - bool helpOver=false; + bool helpOver=false; while(helpOver!=true) { - + GameWindow helpWin(9,120,0,COLS/2-60); GameWindow helpDescr(5,120,9,COLS/2-60); int helpChoice; helpChoice=helpWin.Menu(help,helpDescr); - if (helpChoice==6) {helpWin.Clear(false);helpDescr.Clear(false);helpOver=true;} - else if (helpChoice==1) + if (helpChoice==6) {helpWin.Clear(false);helpDescr.Clear(false);helpOver=true;} + else if (helpChoice==1) { helpWin.Clear(false); helpDescr.Clear(false); @@ -120,7 +120,7 @@ void mainMenu() dmgDescr.Clear(false); damageOver=true; } - + } } else if(helpChoice==3) @@ -180,7 +180,7 @@ void mainMenu() } else if (choice==0) { - mainGame(); + mainGame(); } } endwin(); diff --git a/src/main_test.cpp b/src/MainTest.cpp similarity index 100% rename from src/main_test.cpp rename to src/MainTest.cpp diff --git a/src/Player.cpp b/src/Player.cpp index ed57f36..586d119 100644 --- a/src/Player.cpp +++ b/src/Player.cpp @@ -1,6 +1,11 @@ #include "../include/Player.hpp" -Player::Player(vector selection) +Player::Player(array selection) { - heroes = selection; + for(int &i : selection) + { + heroes.push_back(Hero(i)); + } } + +Hero Hero::GetHero(int ID) { return heroes[ID]; } diff --git a/src/Sample_ncurses.cpp b/src/Sample_ncurses.cpp deleted file mode 100644 index 709fa6d..0000000 --- a/src/Sample_ncurses.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include - -WINDOW *create_newwin(int height, int width, int starty, int startx) -{ - WINDOW *local_win = newwin(height, width, starty, startx); - box(local_win, 0, 0); - wrefresh(local_win); - - return (local_win); -} - -int main(int argc, char **argv) -{ - WINDOW *my_win; - - int ch; - int x = 2; - int y = 2; - - initscr(); - cbreak(); - keypad(stdscr, TRUE); - noecho(); - - printw("Press q to exit"); - refresh(); - my_win = create_newwin(40, 80, y, x); - wmove(my_win, y, x); - wrefresh(my_win); - - while((ch = getch()) != 'q') - { - switch (ch) - { - case KEY_LEFT: - x--; - break; - case KEY_RIGHT: - x++; - break; - case KEY_UP: - y--; - break; - case KEY_DOWN: - y++; - break; - } - - wmove(my_win, y, x); - wrefresh(my_win); - } - - endwin(); - return 0; -} \ No newline at end of file diff --git a/src/ultimate.cpp b/src/Ultimate.cpp similarity index 100% rename from src/ultimate.cpp rename to src/Ultimate.cpp diff --git a/src/heroSelection.cpp b/src/heroSelection.cpp index 83e1fff..b1cfca0 100644 --- a/src/heroSelection.cpp +++ b/src/heroSelection.cpp @@ -1,4 +1,4 @@ -#include "../include/mainMenu.hpp" +#include "../include/MainMenu.hpp" #include "../include/Game.hpp" #include #include @@ -10,13 +10,13 @@ using namespace std; int main() { initscr(); - GameWindow selectionWin(0,0,0,0); + GameWindow selectionWin(0,0,0,0); GameWindow heroDescr(0,0,0,0); getch(); int selectedHeroes [5] = { }; int heroChoice; int i; - + vector> heroNames = { {"Warrior","Fearless warrior and weapon expert. A good choice for players who like a good combination of damage and speed.\n Abilities :\n 1)Shield Bash(attacks the enemy hero with a shield and has a chance to stun the other hero for 1 turn )\n 2)Spear Charge(sprints towards the enemy to stab him with the spear, ignores armor and has slight chance to cause bleed for 3 turns"}, @@ -26,10 +26,10 @@ int main() {"Cleric","This pious cleric is able to cast holy miracles in order to aid those around him.\n Abilities:\n 1)Divine Blessing(buffs a chosen hero in the party increasing dmg,speed and defence for 2 turns)\n 2)Grand heal(Heals a chosen hero in the party for 25% of his hp however it takes a long time to cast)"}, {"Hunter","This man is a famous hunter of beasts and man alike. He will strike down every enemy from afar with his deadly arrows.\n Abilities:\n 1)Poison Arrow(shoots a poisonous arrow that has a chance to poison the enemy for 3 turns)\n 2)Aerial strike(shoots an arrow at every hero at once however there's a 30% chance of missing)"}, {"Paladin","Holy man whose sole duty is to purge to wicked from the world with the aid of his holy hammer.\n Abilities:\n 1)Minor Heal(Is able to heal himself for 10% of his hp)\n 2)Hammer Bash(Attack an enemy hero with a high chance to stun him for 1 turn)"}, - {"Beastman","This deprived man was abandonded in the wilderness. In order to survive he had to adapt to his surroundings and abandon his humanity and any notion of civilization prior to his exile.\n Abilities:\n 1)Bite(charge at an enemy hero to bite his throat. The attack has a medium chance to deal bleed damage for 3 turns)\n 2)Howl(Shout at an enemy hero to intimidate him. The targeted heroes losses all buffs aplied on him and, his speed and defence are decreased for 1 turn)"}, + {"Beastman","This deprived man was abandonded in the wilderness. In order to survive he had to adapt to his surroundings and abandon his humanity and any notion of civilization prior to his exile.\n Abilities:\n 1)Bite(charge at an enemy hero to bite his throat. The attack has a medium chance to deal bleed damage for 3 turns)\n 2)Howl(Shout at an enemy hero to intimidate him. The targeted heroes losses all buffs aplied on him and, his speed and defence are decreased for 1 turn)"}, {"Alchemist","The alchemist is able to craft potions capable of aiding the allies or damage the enemy.\n Abilities:\n 1)Fire Bomb(once thrown it deals damage and has a chance to set the enemy on fire)\n 2)Mana and Healing Potion(restores a little hp and mp)"}, }; - + for ( i=0; i<=5; ++i) { heroChoice=selectionWin.Menu(hero,heroDescr); @@ -40,4 +40,4 @@ int main() selectedHeroes[i] = heroChoice; } return selectedHeroes; -} \ No newline at end of file +}