Added other classes.
This commit is contained in:
parent
f4c9d71aa8
commit
d30e5989af
40
Enemy.cpp
40
Enemy.cpp
@ -1,5 +1,45 @@
|
||||
#include "Enemy.h"
|
||||
|
||||
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
21
Enemy.h
@ -1,11 +1,30 @@
|
||||
#ifndef ENEMY_H
|
||||
#define ENEMY_H
|
||||
|
||||
#include "Weapon.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class Enemy
|
||||
{
|
||||
public:
|
||||
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
|
||||
|
31
Location.cpp
Normal file
31
Location.cpp
Normal 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
27
Location.h
Normal 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
|
4
Makefile
4
Makefile
@ -1,2 +1,2 @@
|
||||
a.out: main.cpp
|
||||
clang++ main.cpp Player.cpp Enemy.cpp -g -O0
|
||||
a.out: main.cpp Player.cpp Enemy.cpp Location.cpp Weapon.cpp
|
||||
clang++ main.cpp Player.cpp Enemy.cpp Location.cpp Weapon.cpp -g -O0
|
||||
|
45
Weapon.cpp
Normal file
45
Weapon.cpp
Normal 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
30
Weapon.h
Normal 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
|
6
main.cpp
6
main.cpp
@ -7,9 +7,7 @@
|
||||
// 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";
|
||||
"Story goes here.\n\n";
|
||||
void OutputCharacters(const std::string &str, int delay_ms = 50000)
|
||||
{
|
||||
for(const char &c : str)
|
||||
@ -112,7 +110,7 @@ void AfterBattle(Player &player, Enemy &enemy)
|
||||
|
||||
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);
|
||||
// end-game stuff w/ king
|
||||
// determine he was happy with your results (i.e. if you won)
|
||||
|
Loading…
Reference in New Issue
Block a user