Initial Commit

This commit is contained in:
David Vereb 2021-01-24 14:40:11 -05:00
commit 6ca6516877
7 changed files with 215 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*~
a.out

5
Enemy.cpp Normal file
View File

@ -0,0 +1,5 @@
#include "Enemy.h"
Enemy::Enemy()
{
}

11
Enemy.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef ENEMY_H
#define ENEMY_H
class Enemy
{
public:
Enemy();
bool Alive() const { return false; }
};
#endif

2
Makefile Normal file
View File

@ -0,0 +1,2 @@
a.out: main.cpp
clang++ main.cpp Player.cpp Enemy.cpp -g -O0

7
Player.cpp Normal file
View File

@ -0,0 +1,7 @@
#include "Player.h"
Player::Player(std::string setName,
CharClass setCharClass)
: name(setName), charClass(setCharClass)
{
}

27
Player.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef PLAYER_H
#define PLAYER_H
#include <string>
//#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

160
main.cpp Normal file
View File

@ -0,0 +1,160 @@
#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 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
}