Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Cave-Crawler/Mob_Types.h.txt
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
219 lines (180 sloc)
4.1 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef MOB_TYPES_H | |
#define MOB_TYPES_H | |
#include <iostream> | |
#include <string> | |
#include <cstdlib> | |
#include <ctime> | |
class Enemy | |
{ | |
public: | |
static int counter; | |
int id; | |
std::string name; | |
bool species; | |
int rank; | |
Enemy(std::string _name,bool _species, int _rank) | |
{ | |
id = counter; | |
counter += 1; | |
name = _name; | |
species = _species; | |
rank = _rank; | |
} | |
void display() | |
{ | |
std::cout << "A level " << rank << " " << name << std::endl; | |
} | |
void attack() | |
{ | |
std::cout << "A level " << rank << " " << name << " tried to attack" << std::endl; | |
} | |
}; | |
int Enemy::counter = 0; | |
class Wolf : public Enemy | |
{ | |
private: | |
bool attacking; | |
int HP; | |
int AP; | |
public: | |
Wolf(std::string _name, int _rank, bool _attacking) | |
: Enemy(_name, true, _rank) | |
{ | |
HP = (_rank * 10) + 10; | |
AP = _rank + 5; | |
attacking = _attacking; | |
} | |
void attack() | |
{ | |
if (attacking) | |
std::cout << name << " attacks!" << std::endl; | |
else | |
std::cout << name << " is waiting to attack." << std::endl; | |
} | |
void drop() | |
{ | |
if (species) | |
std::cout << name << " had died and dropped ITEM: meat" << std::endl; | |
else | |
std::cout << name << " had died and dropped ITEM: bones" << std::endl; | |
} | |
void display() | |
{ | |
std::cout << "A"; | |
if (attacking) | |
std::cout << "n attacking level "; | |
else | |
std::cout << " waiting level "; | |
std::cout << rank << " " << name << " with " << HP << " HP and " << AP << " AP" << std::endl; | |
} | |
void battle(Wolf &other) | |
{ | |
if (attacking && other.attacking) | |
{ | |
int turn = 1; | |
srand(time(0)); | |
while ((HP > 0) && (other.HP > 0)) | |
{ | |
int x = (AP + (rand() % 4)); | |
int y = (other.AP + (rand() % 4)); | |
other.HP = other.HP - x; | |
HP = HP - y; | |
std::cout << "(TURN: " << turn << ")" << std::endl; | |
std::cout << name << " deals " << x << " damage to " << other.name << std::endl; | |
std::cout << other.name << " deals " << y << " damage to " << name << std::endl << " " << std::endl; | |
turn += 1; | |
} | |
if (HP > other.HP) | |
{ | |
std::cout << name << " is the winner!" << std::endl; | |
other.drop(); | |
} | |
else if (HP < other.HP) | |
{ | |
std::cout << other.name << " is the winner!" << std::endl; | |
drop(); | |
} | |
else | |
std::cout << "It's a draw!" << std::endl; | |
} | |
else | |
std::cout << "The wolves will not fight" << std::endl; | |
} | |
}; | |
class Tiger : public Enemy | |
{ | |
private: | |
bool attacking; | |
int HP; | |
int AP; | |
public: | |
Tiger(std::string _name, int _rank, bool _attacking) | |
: Enemy(_name, true, _rank) | |
{ | |
HP = (_rank * 12) + 10; | |
AP = _rank + 15; | |
attacking = _attacking; | |
} | |
void attack() | |
{ | |
if (attacking) | |
std::cout << name << " attacks!" << std::endl; | |
else | |
std::cout << name << " is waiting to attack." << std::endl; | |
} | |
void display() | |
{ | |
std::cout << "A"; | |
if (attacking) | |
std::cout << "n attacking level "; | |
else | |
std::cout << " waiting level "; | |
std::cout << rank << " " << name << " with " << HP << " HP and " << AP << " AP" << std::endl; | |
} | |
void drop() | |
{ | |
if (species) | |
std::cout << name << " had died and dropped ITEM: meat" << std::endl; | |
else | |
std::cout << name << " had died and dropped ITEM: bones" << std::endl; | |
} | |
}; | |
class Lizard : public Enemy | |
{ | |
private: | |
bool attacking; | |
int HP; | |
int AP; | |
public: | |
Lizard(std::string _name, int _rank, bool _attacking) | |
: Enemy(_name, false, _rank) | |
{ | |
HP = (_rank * 5) + 5; | |
AP = _rank + 1; | |
attacking = _attacking; | |
} | |
void attack() | |
{ | |
if (attacking) | |
std::cout << name << " attacks!" << std::endl; | |
else | |
std::cout << name << " is waiting to attack." << std::endl; | |
} | |
void display() | |
{ | |
std::cout << "A"; | |
if (attacking) | |
std::cout << "n attacking level "; | |
else | |
std::cout << " waiting level "; | |
std::cout << rank << " " << name << " with " << HP << " HP and " << AP << " AP" << std::endl; | |
} | |
void drop() | |
{ | |
if (species) | |
std::cout << name << " had died and dropped ITEM: meat" << std::endl; | |
else | |
std::cout << name << " had died and dropped ITEM: bones" << std::endl; | |
} | |
}; | |
#endif | |