Main.cpp
Spoiler
#include <iostream>
#include "Player.cpp"
#include "Enemy.cpp"
using namespace std;
int main()
{
int opc;
Player* player;
Enemy enemy;
player->SetHealth();
cout << "What's your name?" << endl;
player->SetName();
cout << endl << "Your name is: " << player->name << " and your health is: " << player->GetHealth() << endl;
// First enemy
enemy.SetHealth();
enemy.curhealth=100;
cout << endl << "An enemy appears!" << endl;
cout << "Enemy name: Chobi." << endl << "Enemy HP: " << enemy.GetHealth() << "." << endl;
option:
cout << endl << "What to do?" << endl;
cout << "1. Attack #1." << endl;
cin >> opc;
if (opc==1)
player->Attack(enemy);
goto option;
return 0;
}
Player:
Spoiler
// Player.h
#ifndef PLAYER_H_INCLUDED
#define PLAYER_H_INCLUDED
#include <cstring>
#include "Enemy.h"
using namespace std;
class Player
{
public:
int health, curhealth, atk1, atk2;
string name;
int GetHealth();
void SetHealth();
void TakeDamage(int);
void SetName();
void Attack(Enemy);
};
#endif // PLAYER_H_INCLUDED
// Player.cpp
#include <iostream>
#include <cstdlib>
#include <ctime>
#include "Player.h"
using namespace std;
int urand(int min, int max)
{
srand(time(NULL));
return rand() % (max - min + 1) + min;
}
void Player::SetHealth()
{
health = urand(100, 200);
curhealth = health;
}
int Player::GetHealth()
{
return curhealth;
}
void Player::TakeDamage(int damage)
{
curhealth -= damage;
}
void Player::SetName()
{
getline (cin, name);
}
void Player::Attack(Enemy enemy)
{
int atk = urand(10, 30);
enemy.curhealth = enemy.TakeDamage(atk);
cout << endl << "Attacked for: " << atk << "." << endl;
cout << "Enemy HP: " << enemy.curhealth << "." << endl;
}
Enemy:
Spoiler
// Enemy.h
#ifndef ENEMY_H_INCLUDED
#define ENEMY_H_INCLUDED
#include <cstring>
#include "Player.h"
using namespace std;
class Enemy
{
public:
int health;
int curhealth, atk1;
string name;
int GetHealth();
void SetHealth();
void TakeDamage(int);
};
#endif // ENEMY_H_INCLUDED
// Enemy.cpp
#include <iostream>
#include "Enemy.h"
using namespace std;
void Enemy::SetHealth()
{
health = urand(100, 120);
curhealth = health;
}
int Enemy::GetHealth()
{
return curhealth;
}
void Enemy::TakeDamage(int damage)
{
curhealth -= damage;
}

Find content
Not Telling