From 6ca6516877a137dfdeee9dc685139df4759c39c8 Mon Sep 17 00:00:00 2001 From: "David Vereb (Home)" Date: Sun, 24 Jan 2021 14:40:11 -0500 Subject: [PATCH] Initial Commit --- .gitignore | 3 + Enemy.cpp | 5 ++ Enemy.h | 11 ++++ Makefile | 2 + Player.cpp | 7 +++ Player.h | 27 +++++++++ main.cpp | 160 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 215 insertions(+) create mode 100644 .gitignore create mode 100644 Enemy.cpp create mode 100644 Enemy.h create mode 100644 Makefile create mode 100644 Player.cpp create mode 100644 Player.h create mode 100644 main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6f3d0df --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*~ +a.out + diff --git a/Enemy.cpp b/Enemy.cpp new file mode 100644 index 0000000..6e179de --- /dev/null +++ b/Enemy.cpp @@ -0,0 +1,5 @@ +#include "Enemy.h" + +Enemy::Enemy() +{ +} diff --git a/Enemy.h b/Enemy.h new file mode 100644 index 0000000..7bce069 --- /dev/null +++ b/Enemy.h @@ -0,0 +1,11 @@ +#ifndef ENEMY_H +#define ENEMY_H + +class Enemy +{ +public: + Enemy(); + bool Alive() const { return false; } +}; + +#endif diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a3778f3 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +a.out: main.cpp + clang++ main.cpp Player.cpp Enemy.cpp -g -O0 diff --git a/Player.cpp b/Player.cpp new file mode 100644 index 0000000..9a54adb --- /dev/null +++ b/Player.cpp @@ -0,0 +1,7 @@ +#include "Player.h" + +Player::Player(std::string setName, + CharClass setCharClass) + : name(setName), charClass(setCharClass) +{ +} diff --git a/Player.h b/Player.h new file mode 100644 index 0000000..3416f39 --- /dev/null +++ b/Player.h @@ -0,0 +1,27 @@ +#ifndef PLAYER_H +#define PLAYER_H + +#include +//#include "Weapon.h" + +enum CharClass { + FIGHTER, + WIZARD, + ROGUE, +}; + +class Player { +public: + Player(std::string setName, + CharClass setCharClass); + + bool Alive() const { return hp > 0; } + +private: + std::string name; + CharClass charClass; + int hp; +// Weapon weapon; +}; + +#endif diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..464953b --- /dev/null +++ b/main.cpp @@ -0,0 +1,160 @@ +#include +#include + +#include "Player.h" +#include "Enemy.h" + +// Generic text outputs: +const std::string text_welcome = + "\nWelcome\n\n" + "It is a period of civil wars in the galaxy. A brave alliance of underground\n" + "freedom fighters has challenged the tyranny and oppression of the awesome\n" + "GALACTIC EMPIRE.\n\n"; +void OutputCharacters(const std::string &str, int delay_ms = 50000) +{ + for(const char &c : str) + { + std::cout << c << std::flush; + usleep(delay_ms); + } +} + +// Characters: +Player PromptForPlayer(); +char PromptTravel(); + +// MAIN CODE GIVEN TO STUDENTS: +Player Intro(); +char Travel(); +Enemy GenerateEnemy(char locaion, const Player &player); +void Battle(Player &player, Enemy &enemy); +void AfterBattle(Player &player, Enemy &enemy); +void EndGame(Player &player); + +int main() +{ + Player player = Intro(); + + while(true) // Game Loop! + { + char location = Travel(); + if(location == 'K') // back to the king == go to end of game + break; + + Enemy enemy = GenerateEnemy(location, player); // perhaps build enemy based on player stats? + Battle(player, enemy); + AfterBattle(player, enemy); + + if(!player.Alive()) + break; // go to endgame if you're dead! + } + + EndGame(player); +} + +Player PromptForPlayer() +{ + std::string name = ""; + std::cout << "Enter your player name:" << std::endl; + std::getline(std::cin, name); + + std::string charClass_str = ""; + do + { + std::cout << std::endl << "Enter your character class, (F)ighter, (W)izard, or (R)ogue:" << std::endl; + std::getline(std::cin, charClass_str); + } while(charClass_str != "F" && + charClass_str != "W" && + charClass_str != "R"); + + CharClass charClass; + if(charClass_str == "F") + charClass = CharClass::FIGHTER; + else if(charClass_str == "W") + charClass = CharClass::WIZARD; + else if(charClass_str == "R") + charClass = CharClass::ROGUE; + + return Player(name, charClass); +} + +char PromptTravel() +{ + while(true) + { + char travel = 'K'; + std::cout << "Travel: (C)ave, (D)esert, (F)oothills, or return to the (K)ing:" << std::endl; + std::cin >> travel; + + if(travel == 'K' || travel == 'C' || travel == 'D' || travel == 'F') + return travel; + } +} + +Player Intro() +{ + // intro text & setup + OutputCharacters(text_welcome); + + // build a new character from user input + return PromptForPlayer(); +} + +char Travel() +{ + // choose where to travel to + char location = PromptTravel(); + if(location != 'K') + { + // random chance at meeting the traveler + } + + return location; +} + +Enemy GenerateEnemy(char location, const Player &player) +{ + Enemy enemy; + return enemy; +} + +void Battle(Player &player, Enemy &enemy) +{ + while(true) // while(battling) + { + if(!player.Alive() || enemy.Alive()) + break; + + // TODO(dev): + // prompt for action + // perform action + + // NOTE(dev): Just quit out for now... + std::cout << "BATTLE HERE" << std::endl; + usleep(1000000); + break; + } +} + +void AfterBattle(Player &player, Enemy &enemy) +{ + OutputCharacters("Battle over (TODO(dev))\n"); + if(player.Alive()) // `&& !enemy.Alive()` if flee is an option + { + // get gold + // show stats + // prompt for weapon + // level up? + // I dunno... + } +} + +void EndGame(Player &player) +{ + const std::string end_of_story_text = "THE END"; + OutputCharacters(end_of_story_text); + // end-game stuff w/ king + // determine he was happy with your results (i.e. if you won) + // show total enemies killed & total gold found + // THE END +}