Notice
Recent Posts
Recent Comments
250x250
Creative Code
[C++]텍스트 RPG게임 본문
728x90
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <math.h>
int Player_damage;
int Monster_damage;
int input;
class Player {
public:
int LV;
int HP;
int EXP;
bool DEAD;
int ATK;
int Total_EXP;
int Total_HP;
int liquid;
Player();
void attack();
void recover();
void show_status();
}player;
class Monster {
public:
int HP;
int ATK;
Monster();
void attack();
void show_status();
}monster;
Monster::Monster() {
HP = 30;
ATK = 3;
}
Player::Player() { // Player 생성
LV = 1;
HP = 50;
EXP = 0;
DEAD = false;
ATK = 5;
}
void Monster::attack() {
ATK = player.LV * 6;
Monster_damage = ATK;
player.HP -= Monster_damage;
if (player.HP <= 0) {
player.DEAD = true;
player.EXP =0;
if (player.EXP <= 0) {
player.EXP = 0;
}
std::cout << "플레이어님이 사망하셨습니다. 1을 누르시면 부활합니다. " << std::endl;
std::cin >> input;
if (input == 1) {
std::cout << "플레이어가 부활하였습니다." << std::endl;
player.DEAD = false;
player.HP = pow(player.LV, 1.25) * 50;
}
else {
std::cout << "잘못 누르셨습니다. 처음부터 다시키우세요 ^.^ " << std::endl;
player.LV = 1;
player.EXP = 0;
player.Total_HP = pow(player.LV, 1.25) * 50;
player.HP = player.Total_HP;
player.Total_EXP = 1500 * pow(1.15, player.LV);
player.ATK = 5 * pow(player.LV, 1.94);
}
}
}
void Player::attack() { // Player 몬스터 공격
Player_damage = ATK;
monster.HP -= Player_damage;
if (monster.HP <= 0) {
EXP += 72 * pow(1.09, LV);
monster.HP =30 * pow(LV, 1.63);
}
if (EXP >= Total_EXP) {
EXP = 0;
LV += 1;
Total_EXP = 500 * pow(1.08, LV);
Total_HP = pow(LV, 1.41) * 50;
HP = Total_HP;
monster.HP = 30 * pow(LV, 1.63);
ATK = 5 * pow(LV, 2.14);
liquid = Total_HP * 0.2;
}
}
void Player::recover() {
HP += liquid;
if (HP >= Total_HP) {
HP = Total_HP;
}
}
void Player::show_status() {
std::cout << "플레이어 상태 -- " << "레벨 : " << LV << " // " << " HP : " << HP << " // " << " 경험치 : " << EXP <<
" // " << " 공격력 : " << ATK << " ";
}
void Monster::show_status() {
std::cout << "몬스터 상태 -- " << "HP : " << HP << " 몬스터 공격력 :" << ATK << std::endl;
}
int main() {
player.show_status();
std::cout << std::endl;
for (;;) {
std::cout << std::endl;
std::cout << "몬스터 공격 : 1을 눌러주세요" << std::endl;
std::cout << "체력 회복 : 2를 눌러주세요" << std::endl;
std::cin >> input;
std::cout << std::endl;
if (input == 1) {
player.attack();
monster.attack();
player.show_status();
monster.show_status();
}
else if (input == 2) {
player.recover();
player.show_status();
}
else {
std::cout << "다시 입력해라 " << std::endl;
}
if (player.LV == 102) {
std::cout << "축하합니다. 만렙입니다! 1이랑 2누르느라 고생했음 " << std::endl;
break;
}
}
return 0;
}
728x90
'혼자 만든 Code' 카테고리의 다른 글
[Python]명함 관리 프로그램 (0) | 2023.10.16 |
---|---|
[C++]소수로 만들 수 있는 가장 긴 합성수 수열 (0) | 2023.08.28 |
[C]축구선수 관리 프로그램 (0) | 2023.08.28 |
[C]디데이 계산기 (0) | 2023.08.28 |
[C++]디데이 계산기 (0) | 2023.08.28 |