CPP-RPG/main.cpp

164 lines
3.3 KiB
C++

#include <iostream>
#include <unistd.h>
#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 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
}
// MY IMPLEMENTATION
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;
}
}