Added other classes.

This commit is contained in:
David Vereb 2021-01-25 21:40:08 -05:00
parent f4c9d71aa8
commit d30e5989af
8 changed files with 197 additions and 7 deletions

View File

@ -1,5 +1,45 @@
#include "Enemy.h" #include "Enemy.h"
Enemy::Enemy() Enemy::Enemy()
: name("Mr. No-name!"),
hitPoints(1),
gold(1),
weapon(Weapon())
{ {
} }
Enemy::Enemy(std::string setName,
int setHitPoints,
int setGold,
const Weapon &setWeapon)
: name(setName),
hitPoints(setHitPoints),
gold(setGold),
weapon(setWeapon)
{
}
bool Enemy::Alive() const
{
return (hitPoints > 0);
}
std::string Enemy::getName() const
{
return name;
}
int Enemy::getHitPoints() const
{
return hitPoints;
}
int Enemy::getGold() const
{
return gold;
}
Weapon Enemy::getWeapon() const
{
return weapon;
}

21
Enemy.h
View File

@ -1,11 +1,30 @@
#ifndef ENEMY_H #ifndef ENEMY_H
#define ENEMY_H #define ENEMY_H
#include "Weapon.h"
#include <string>
class Enemy class Enemy
{ {
public: public:
Enemy(); Enemy();
bool Alive() const { return false; } Enemy(std::string setName,
int setHitPoints,
int setGold,
const Weapon &setWeapon);
bool Alive() const;
std::string getName() const;
int getHitPoints() const;
int getGold() const;
Weapon getWeapon() const;
private:
std::string name;
int hitPoints;
int gold;
Weapon weapon;
}; };
#endif #endif

31
Location.cpp Normal file
View File

@ -0,0 +1,31 @@
#include "Location.h"
#include <time.h>
Location::Location()
: name("Nowhere"),
descriptions({"This is undefined, bruh.", "This doesn't exist, bruh."})
{
static bool initialized = false;
if(!initialized)
{
initialized = true;
srand(time(nullptr));
}
}
Location::Location(std::string setName,
std::vector<std::string> setDescriptions)
: name(setName),
descriptions(setDescriptions)
{
}
const std::string& Location::getName() const
{
return name;
}
const std::string& Location::getDescription() const
{
return descriptions[rand() % descriptions.size()];
}

27
Location.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef LOCATION_H
#define LOCATION_H
#include "Enemy.h"
#include <string>
#include <vector>
class Location
{
public:
Location();
Location(std::string setName,
std::vector<std::string> setDescriptions);
const std::string& getName() const;
const std::string& getDescription() const; // random
// const std::string& getEnemy() const;
private:
std::string name;
std::vector<std::string> descriptions;
// Enemy enemy;
//bool currentLocation;
};
#endif

View File

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

45
Weapon.cpp Normal file
View File

@ -0,0 +1,45 @@
#include "Weapon.h"
Weapon::Weapon()
: name("Stick"),
damageType("pokes"),
twoHanded(false),
damage(2)
{
}
Weapon::Weapon(std::string setName,
std::string setDamageType,
bool setTwoHanded,
int setDamage)
: name(setName),
damageType(setDamageType),
twoHanded(setTwoHanded),
damage(setDamage)
{
}
const std::string& Weapon::getName() const
{
return name;
}
const std::string& Weapon::getDamageType() const
{
return damageType;
}
bool Weapon::getTwoHanded() const
{
return twoHanded;
}
int Weapon::getLevel() const
{
return level;
}
void Weapon::levelUp()
{
damage += 3 + level++;
}
int Weapon::getDamage() const
{
return damage;
}

30
Weapon.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef WEAPON_H
#define WEAPON_H
#include <string>
class Weapon
{
public:
Weapon();
Weapon(std::string setName,
std::string setDamageType,
bool setTwoHanded,
int setDamage);
const std::string& getName() const;
const std::string& getDamageType() const;
bool getTwoHanded() const;
int getLevel() const;
void levelUp();
int getDamage() const;
private:
std::string name;
std::string damageType;
bool twoHanded;
int damage;
int level;
};
#endif

View File

@ -7,9 +7,7 @@
// Generic text outputs: // Generic text outputs:
const std::string text_welcome = const std::string text_welcome =
"\nWelcome\n\n" "\nWelcome\n\n"
"It is a period of civil wars in the galaxy. A brave alliance of underground\n" "Story goes here.\n\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) void OutputCharacters(const std::string &str, int delay_ms = 50000)
{ {
for(const char &c : str) for(const char &c : str)
@ -112,7 +110,7 @@ void AfterBattle(Player &player, Enemy &enemy)
void EndGame(Player &player) void EndGame(Player &player)
{ {
const std::string end_of_story_text = "THE END"; const std::string end_of_story_text = "THE END\n\n";
OutputCharacters(end_of_story_text); OutputCharacters(end_of_story_text);
// end-game stuff w/ king // end-game stuff w/ king
// determine he was happy with your results (i.e. if you won) // determine he was happy with your results (i.e. if you won)