[C++] 내가 만든 선택지형 textRPG
2022. 6. 20. 18:31ㆍ돌다리도 두드려보고 건너라 <복만살>
728x90
#include <iostream>
#include <Windows.h>
#include <vector>
#include <string>
#include <cstdlib>
#include <time.h>
using namespace std;
// 구조체 선언부
struct Game;
struct Player;
struct Inventory;
enum Job
{
Warrior = 1, // 전사
Wizard = 2, // 마법사
Archer = 3, // 궁수
Thief = 4, // 도적
Pirate = 5 // 해적
};
enum Mon
{
slime = 01, // 슬라임
dragon = 02, // 드래곤
gargoyle = 03, // 가고일
giant = 04, // 거인
zombie = 05, // 좀비
kraken = 06, // 크라켄
medusa = 07 // 메두사
};
enum Vill
{
hotel = 001, // 여관
weaponstore = 002, // 무기상점
defencestore = 003, // 방어구상점
hunter = 004, // 사냥터
storage = 005, // 개인창고
smithy = 006 // 대장간
};
// 플레이어 정보
string name; // 이름
int hp; // 체력
int atk; // 공격력
int def; // 방어력
string item; // 드롭아이템
// 몬스터 정보
string m_name; // 이름
int m_hp; // 체력
int m_atk; // 공격력
int m_def; // 방어력
string m_item; // 드롭아이템
// 글자색변경함수
void SetColor(int colorNumber)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), colorNumber);
}
// 구조체 정의부
struct Game
{
Game();
void Opening(); //오프닝
void Start(); //시작
void Ending(); //엔딩
void Job(); //직업선택
void warrior(); //전사정보
void wizard(); //마법사정보
void archer(); //궁수정보
void thief(); //도적정보
void pirate(); //해적정보
void map(); //맵선택+도망선택
void vill(); //마을선택
void hot(); //여관선택
void wea(); //무기상점선택
void defen(); //방어구상점선택
void hun(); //사냥터선택
void sto(); //개인창고선택(인벤토리)
void smithy(); //대장간선택
void mon(); //몬스터(랜덤)
void sl(); //슬라임정보
void dr(); //드래곤정보
void gar(); //가고일정보
void gi(); //거인정보
void zom(); //좀비정보
void kra(); //크라켄정보
void med(); //메두사정보
void att(); //전투선택
void dropItem(); //드롭아이템
};
struct Player
{
string name = 0;
int id = 0;
int itemCount = 0;
Player();
vector<Inventory*> inventory;
void PrintInventory();
void AddItem(Inventory* item);
void UsedItem(int _id);
void ThrowItem(int _id);
};
struct Inventory
{
string name = 0;
int id = 0;
int itemCount = 0;
Inventory();
Inventory(string _name, int _id, int _itemCount);
};
void main()
{
srand(time(0));
Game game;
}
// 구조체 구현부
Game::Game()
{
Opening();
Start();
}
void Game::Opening()
{
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " 어느날 " << endl;
Sleep(3000);
system("cls");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " 문득 잠에서 깼다 " << endl;
Sleep(2000);
system("cls");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " 갑자기 누가 문을 쿵쾅 뚜드린다 " << endl;
Sleep(3000);
system("cls");
SetColor(4);
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " 쿵쿵쿵! " << endl;
Sleep(2000);
system("cls");
SetColor(7);
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " (고요한 방 안) " << endl;
Sleep(3000);
system("cls");
SetColor(4);
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " 쿵쿵쿵쿵쿵쿵쿵쿵쿵쿵쿵쿵쿵쿵쿵쿵! " << endl;
Sleep(1000);
system("cls");
SetColor(9);
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " ...... '누구세요?' " << endl;
Sleep(3000);
system("cls");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " 갑자기 문이 열린다 " << endl;
SetColor(11);
Sleep(1000);
system("cls");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " 강한 섬광과 함께 수상한 소용돌이가 보인다 " << endl;
SetColor(15);
Sleep(2000);
system("cls");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " 나는 그 소용돌이를 보고 순간 홀려 그것에 빨려들어갔다 " << endl;
Sleep(2000);
system("cls");
}
void Game::Start()
{
int input = 0;
SetColor(15);
cout << "게임을 시작하겠습니까?" << endl;
Sleep(1000);
cout << "선택하십시오." << endl;
SetColor(11);
cout << "__________________________________________________________________" << endl;
cout << " 1. 시작 " << endl;
cout << " 2. 종료 " << endl;
cout << "__________________________________________________________________" << endl;
cout << ">>>";
cin >> input;
switch (input)
{
case 1:
{
SetColor(15);
cout << "게임시작을 선택하셨습니다." << endl;
Job(); // 직업 선택
break;
}
case 2:
{
SetColor(15);
cout << "게임종료를 선택하셨습니다." << endl;
Ending(); // 엔딩 선택
}
default:
cout << "게임에 오류가 발생하였습니다" << endl;
cout << "처음부터 다시 시작하세요" << endl;
}
}
void Game::Ending()
{
SetColor(10);
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " ....... " << endl;
Sleep(5000);
system("cls");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " 뭐야 " << endl;
Sleep(3000);
system("cls");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " 꿈이잖아... " << endl;
SetColor(8);
Sleep(3000);
system("cls");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " 게임을 끝까지 즐겨주셔서 감사합니다♥ " << endl;
SetColor(15);
Sleep(4000);
system("cls");
cout << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ " << endl;
cout << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ " << endl;
cout << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ " << endl;
cout << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@ " << endl;
cout << "@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@ @@@@@@@@ @@@@@@@@@@@@@@@@@@@ " << endl;
cout << "@@@@@@@@@@@@@@@@@@@@ @@@@@ @@@@@@@@@@@@@@@@@@@@@@@ @@@@@@ @@@@@@@@@@ @@@@@@@@@@@@@@@@@@@ " << endl;
cout << "@@@@@@@@@@@@@@@@@@ @@@@@@@ @@@@@@@@@@@@@@@@@@@@@ @@@@@@@ @@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@ " << endl;
cout << "@@@@@@@@@@@@@@@@@ @@@@@@@ @@@@@@@@@@@@@@@@@@@ @@@ @@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@ " << endl;
cout << "@@@@@@@@@@@@@@@@@@ @@@@ @@@@@@@@@@@@@@@@@@@@ @@@@ @ @@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@ " << endl;
cout << "@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@ @@@@@@@@ @@ @@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@ " << endl;
cout << "@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@ @@@@@@@@@ @@@@@@ @@@@@@@@@ @@@@@@@@@@@@@@@@@@@ " << endl;
cout << "@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@ @@@@@@@ @@@@@@@@@@@@@@@@@@@ " << endl;
cout << "@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@ " << endl;
cout << "@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@ " << endl;
cout << "@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@ " << endl;
cout << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@ " << endl;
cout << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ " << endl;
cout << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ " << endl;
cout << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ " << endl;
cout << endl << endl;
cout << "prod by 오씨" << endl;
}
void Game::Job()
{
int ch;
SetColor(10);
cout << "캐릭터를 고르세요" << endl;
Sleep(1000);
SetColor(11);
cout << "__________________________________________________________________" << endl;
cout << " 1. 전사 " << endl;
cout << " 2. 마법사 " << endl;
cout << " 3. 궁수 " << endl;
cout << " 4. 도적 " << endl;
cout << " 5. 해적 " << endl;
cout << "__________________________________________________________________" << endl;
cout << ">>>";
cin >> ch;
switch (ch)
{
case Warrior:
{
SetColor(8);
cout << "전사를 선택하셨습니다." << endl;
warrior(); // 전사 선택
map();
}
case Wizard:
{
SetColor(9);
cout << "마법사를 선택하셨습니다." << endl;
wizard(); // 마법사 선택
map();
}
case Archer:
{
SetColor(10);
cout << "궁수를 선택하셨습니다." << endl;
archer(); // 궁수 선택
map();
}
case Thief:
{
SetColor(11);
cout << "도적를 선택하셨습니다." << endl;
thief(); // 도적 선택
map();
}
case Pirate:
{
SetColor(12);
cout << "해적를 선택하셨습니다." << endl;
pirate(); // 해적 선택
map();
}
default:
cout << "다시 선택해주세요" << endl;
Job(); // 직업 재선택
}
}
void Game::warrior()
{
name = "전사";
hp = 300;
atk = 150;
def = 30;
item = "앱솔랩스 데스페라도, 트릭스터 워리어팬츠, 버츄스 메달+5, 50000메소";
}
void Game::wizard()
{
name = "마법사";
hp = 250;
atk = 120;
def = 50;
item = "포이즈닉 완드, 분노한 메두사의 망토+7, 페어리 하트+3, 40000메소";
}
void Game::archer()
{
name = "궁수";
hp = 350;
atk = 130;
def = 25;
item = "네크로 롱보우, 레볼루션 슈트+4, 파란색가운+8 ,18000메소";
}
void Game::thief()
{
name = "도적";
hp = 200;
atk = 160;
def = 30;
item = "베즐러드, 유성도+4, 일비, 도루코대거+8, 9999만 메소";
}
void Game::pirate()
{
name = "해적";
hp = 300;
atk = 170;
def = 20;
item = "플린트락 피스톨, 불완전한 마음의 목걸이+6, 연금술사의 반지+6, 10억 메소";
}
void Game::map()
{
SetColor(10);
cout << "어디로 갈지 선택해주세요." << endl;
Sleep(1000);
SetColor(11);
cout << "__________________________________________________________________" << endl;
cout << " 1. 마을 " << endl;
cout << " 2. 사냥터 " << endl;
cout << "__________________________________________________________________" << endl;
cout << ">>>";
int ch1;
cin >> ch1;
switch (ch1)
{
case 1:
{
SetColor(6);
cout << "마을로 이동합니다......" << endl;
vill(); // 마을 이동
break;
}
case 2:
{
SetColor(6);
cout << "사냥터로 이동합니다......" << endl;
hun(); // 사냥터 이동
break;
}
default:
SetColor(6);
cout << "다시 선택해주세요" << endl;
map();
}
}
void Game::vill()
{
SetColor(5);
cout << "마을에 도착했습니다" << endl;
SetColor(10);
cout << "다음 행동을 고르세요" << endl;
Sleep(1000);
SetColor(11);
cout << "__________________________________________________________________" << endl;
cout << " 1. 여관(체력증가) " << endl;
cout << " 2. 무기상점(공격력증가) " << endl;
cout << " 3. 방어구상점(방어력증가) " << endl;
cout << " 4. 사냥터 " << endl;
cout << " 5. 인벤토리 " << endl;
cout << " 6. 대장간 " << endl;
cout << "__________________________________________________________________" << endl;
cout << ">>>";
int ch2;
cin >> ch2;
switch (ch2)
{
case 001:
{
SetColor(6);
cout << "여관으로 이동합니다......" << endl;
SetColor(7);
hot(); // 여관 이동
SetColor(15);
map();
}
case 002:
{
SetColor(6);
cout << "무기상점으로 이동합니다......" << endl;
SetColor(9);
wea(); // 무기상점 이동
SetColor(15);
map();
}
case 003:
{
SetColor(6);
cout << "방어구상점으로 이동합니다......" << endl;
SetColor(11);
defen(); // 방어구상점 이동
SetColor(15);
map();
}
case 004:
{
SetColor(6);
cout << "사냥터로 이동합니다......" << endl;
SetColor(15);
hun(); // 사냥터 이동
}
case 005:
{
SetColor(6);
cout << "인벤토리로 이동합니다......" << endl;
SetColor(13);
sto(); // 인벤토리 이동
SetColor(15);
map();
}
case 006:
{
SetColor(6);
cout << "대장간으로 이동합니다......" << endl;
SetColor(15);
smithy(); // 대장간 이동
SetColor(15);
map();
}
default:
SetColor(6);
cout << "다시 선택해주세요....." << endl;
vill();
}
}
void Game::hot()
{
SetColor(10);
cout << "체력이 300 증가하여 회복되었습니다" << endl;
hp += 300;
SetColor(15);
vill();
}
void Game::wea()
{
//플레이어 정보
cout << "__________________________________________________________________" << endl;
cout << "현재 " << name << "의 정보 입니다" << endl;
cout << "체력 : " << hp << " / " << "공격력 : " << atk << " / " << "방어력 : " << def << " / " << "착용아이템 : " << item << endl;
cout << "__________________________________________________________________" << endl;
SetColor(10);
cout << "무기를 업그레이드 하시겠습니까? 공격력이 증가됩니다" << endl;
Sleep(1000);
SetColor(11);
cout << "__________________________________________________________________" << endl;
cout << " 1. 산다 " << endl;
cout << " 2. 나간다 " << endl;
cout << "__________________________________________________________________" << endl;
cout << ">>>";
int ch3;
cin >> ch3;
switch (ch3)
{
case 1:
{
SetColor(6);
cout << "공격력이 50 증가하였습니다" << endl;
atk += 50;
SetColor(15);
wea();
}
case 2:
{
SetColor(6);
cout << "안녕히 가십시오" << endl;
SetColor(15);
vill();
break;
}
default:
SetColor(6);
cout << "다시 선택해주세요" << endl;
wea();
}
}
void Game::defen()
{
//플레이어 정보
cout << "__________________________________________________________________" << endl;
cout << "현재 " << name << "의 정보 입니다" << endl;
cout << "체력 : " << hp << " / " << "공격력 : " << atk << " / " << "방어력 : " << def << " / " << "착용아이템 : " << item << endl;
cout << "__________________________________________________________________" << endl;
SetColor(10);
cout << "방어구를 업그레이드 하시겠습니까? 방어력이 증가합니다" << endl;
Sleep(1000);
SetColor(11);
cout << "__________________________________________________________________" << endl;
cout << " 1. 산다 " << endl;
cout << " 2. 나간다 " << endl;
cout << "__________________________________________________________________" << endl;
cout << ">>>";
int ch3;
cin >> ch3;
switch (ch3)
{
case 1:
{
SetColor(6);
cout << "방어력이 15 증가하였습니다" << endl;
def += 15;
SetColor(15);
defen();
}
case 2:
{
SetColor(6);
cout << "안녕히 가십시오" << endl;
SetColor(15);
vill();
break;
}
default:
SetColor(6);
cout << "다시 선택해주세요" << endl;
defen();
}
}
void Game::sto()
{
SetColor(10);
cout << "인벤토리입니다" << endl;
Player player;
player.AddItem(new Inventory("마스터리북", 1, 5));
player.AddItem(new Inventory("아니의 상자", 2, 2));
player.AddItem(new Inventory("익스트림 골드", 1, 30));
player.AddItem(new Inventory("위대한 전설의 소울 교환권", 3, 3));
player.AddItem(new Inventory("푸른 별 항아리", 1, 500));
player.AddItem(new Inventory("유니크 잠재능력 무기강화 주문서", 1, 10));
player.PrintInventory();
SetColor(10);
cout << "인벤토리를 수정하시겠습니까?" << endl;
Sleep(1000);
SetColor(11);
cout << "__________________________________________________________________" << endl;
cout << " 1. 아이템을 사용한다 " << endl;
cout << " 2. 아이템을 버린다 " << endl;
cout << " 3. 나간다 " << endl;
cout << "__________________________________________________________________" << endl;
cout << ">>>";
int ch4;
cin >> ch4;
switch (ch4)
{
case 1:
{
vector<Inventory*> inventory;
SetColor(5);
cout << "몇번째 아이템을 사용하시겠습니까?" << endl;
cout << ">>>";
int x;
cin >> x;
for (int x = 0; x < inventory.size(); x++)
{
player.UsedItem(x);
}
sto();
break;
}
case 2:
{
vector<Inventory*> inventory;
SetColor(5);
cout << "몇번째 아이템을 버리시겠습니까?" << endl;
cout << ">>>";
int y;
cin >> y;
for (int y = 0; y < inventory.size(); y++)
{
player.ThrowItem(y);
}
sto();
break;
}
case 3:
{
SetColor(6);
cout << "인벤토리를 나갑니다" << endl;
Sleep(2000);
cout << "마을로 이동합니다" << endl;
vill();
}
default:
SetColor(6);
cout << "다시 선택해주세요" << endl;
sto();
}
vill();
}
void Game::smithy()
{
SetColor(10);
cout << "대장간입니다" << endl;
Sleep(3000);
system("cls");
cout << "이곳에선 무기를 강화할수가 있습니다" << endl;
Sleep(3000);
system("cls");
SetColor(11);
string weapon;
cout << "__________________________________________________________________" << endl;
cout << " 강화하고 싶은 무기는 무엇인가요? " << endl;
cout << " >>>";
cin >> weapon;
int iUpgrade = 0;
cout << "__________________________________________________________________" << endl;
cout << " Upgrade 기본 수치를 입력하세요 : " << endl;
cout << " >>>";
cin >> iUpgrade; // 아이템 등급 입력
srand((unsigned int)time(0));
tryAgain:
char ask;
// 강화 확률 구하기
float fPercent = rand() % 10000 / 100.f;
cout << "Upgrade : " << iUpgrade << endl;
cout << "Percent : " << fPercent << endl;
// 강화 1단계 - 아이템 등급 1 ~ 3
if (iUpgrade < 4)
{
cout << weapon << " 강화 성공!!" << endl;
cout << weapon << " 강화 수치 : " << ++iUpgrade << endl;
cout << "강화를 계속 하시겠습니까? (Y/N)";
cin >> ask;
if (ask == 'y')
{
goto tryAgain;
}
}
// 강화 2단계 - 아이템 등급 4 ~ 6
else if (4 <= iUpgrade && iUpgrade <= 6)
{
if (fPercent < 50.f)
{
cout << weapon << " 강화 성공!!" << endl;
cout << weapon << " 강화 수치 : " << ++iUpgrade << endl;
cout << "강화를 계속 하시겠습니까? (y/n)";
cin >> ask;
if (ask == 'y')
{
goto tryAgain;
}
}
else
{
cout << weapon << " 강화 실패" << endl;
cout << weapon << " 강화 수치 : " << --iUpgrade << endl;
cout << "강화를 계속 하시겠습니까? (Y/N)";
cin >> ask;
if (ask == 'y')
{
goto tryAgain;
}
}
}
// 강화 3단계 - 아이템 등급 7 ~ 9
else if (7 <= iUpgrade && iUpgrade <= 9)
{
if (fPercent < 40.f)
{
cout << weapon << " 강화 성공!!" << endl;
cout << weapon << " 강화 수치 : " << ++iUpgrade << endl;
cout << "강화를 계속 하시겠습니까? (Y/N)";
cin >> ask;
if (ask == 'y')
{
goto tryAgain;
}
}
else
{
cout << weapon << " 강화 실패" << endl;
cout << weapon << " 강화 수치 : " << --iUpgrade << endl;
cout << "강화를 계속 하시겠습니까? (Y/N)";
cin >> ask;
if (ask == 'y')
{
goto tryAgain;
}
}
}
// 강화 4단계 - 아이템 등급 9
else if (iUpgrade == 9)
{
if (fPercent < 30.f)
{
cout << weapon << " 강화 성공!!" << endl;
cout << weapon << " 강화 수치 : " << ++iUpgrade << endl;
cout << "강화를 계속 하시겠습니까? (Y/N)";
cin >> ask;
if (ask == 'y')
{
goto tryAgain;
}
}
else
{
cout << weapon << " 강화 실패" << endl;
cout << weapon << " 강화 수치 : " << --iUpgrade << endl;
cout << "강화를 계속 하시겠습니까? (Y/N)";
cin >> ask;
if (ask == 'y')
{
goto tryAgain;
}
}
}
}
void Game::hun()
{
SetColor(10);
cout << "어떤 행동을 하시겠습니까?" << endl;
Sleep(1000);
SetColor(11);
cout << "__________________________________________________________________" << endl;
cout << " 1. 싸운다 " << endl;
cout << " 2. 도망친다 " << endl;
cout << " 3. 마을로 이동 " << endl;
cout << "__________________________________________________________________" << endl;
cout << ">>>";
SetColor(15);
int ch5;
cin >> ch5;
switch (ch5)
{
case 1:
{
SetColor(4);
cout << "전투를 시작합니다." << endl;
att();
break;
}
case 2:
{
SetColor(5);
cout << "도망칩니다." << endl;
cout << "치사하게 도망치면 그에 따른 응당한 댓가를 치를겁니다" << endl;
cout << "(응당한 댓가 : 플레이어의 공격력100과 방어력이 10씩 감소)" << endl;
atk -= 100;
def -= 10;
hun();
break;
}
case 3:
{
SetColor(6);
cout << "마을로 이동을 선택하셨습니다." << endl;
vill();
}
default:
SetColor(6);
cout << "다시 선택해주세요" << endl;
hun();
}
}
void Game::mon()
{
int ra; // 랜덤 선택된 몬스터 저장
ra = rand() % 7;
switch (ra)
{
case slime:
{
SetColor(1);
cout << "~~~~~~~~~~~~~~~~~~" << endl;
cout << "슬라임이 나타났다~~" << endl;
cout << "~~~~~~~~~~~~~~~~~~" << endl;
SetColor(15);
Sleep(1000);
sl();
break;
}
case dragon:
{
SetColor(2);
cout << "~~~~~~~~~~~~~~~~~~~~~" << endl;
cout << "▶▶▶보스몹 등장◀◀◀" << endl;
cout << "DRAGON이 나타났다!!!!!" << endl;
cout << "~~~~~~~~~~~~~~~~~~~~~" << endl;
SetColor(15);
Sleep(3000);
dr();
break;
}
case gargoyle:
{
SetColor(3);
cout << "~~~~~~~~~~~~~~~~~~" << endl;
cout << "가고일이 나타났다~~" << endl;
cout << "~~~~~~~~~~~~~~~~~~" << endl;
SetColor(15);
Sleep(1000);
gar();
break;
}
case giant:
{
SetColor(4);
cout << "~~~~~~~~~~~~~~~~~~~~~" << endl;
cout << "▶▶▶보스몹 등장◀◀◀" << endl;
cout << "GIANT가 나타났다!!!!!!" << endl;
cout << "~~~~~~~~~~~~~~~~~~~~~" << endl;
SetColor(15);
Sleep(3000);
gi();
break;
}
case zombie:
{
SetColor(5);
cout << "~~~~~~~~~~~~~~~~~~" << endl;
cout << "좀비가 나타났다~~~~" << endl;
cout << "~~~~~~~~~~~~~~~~~~" << endl;
SetColor(15);
Sleep(1000);
zom();
break;
}
case kraken:
{
SetColor(6);
cout << "~~~~~~~~~~~~~~~~~~~~~" << endl;
cout << "▶▶▶보스몹 등장◀◀◀" << endl;
cout << "KRAKEN가 나타났다!!!!!" << endl;
cout << "~~~~~~~~~~~~~~~~~~~~~" << endl;
SetColor(15);
Sleep(3000);
kra();
break;
}
case medusa:
{
SetColor(7);
cout << "~~~~~~~~~~~~~~~~~~~~~" << endl;
cout << "▶▶▶보스몹 등장◀◀◀" << endl;
cout << "MEDUSA가 나타났다!!!!!" << endl;
cout << "~~~~~~~~~~~~~~~~~~~~~" << endl;
SetColor(15);
Sleep(3000);
med();
break;
}
}
}
void Game::sl()
{
m_name = "슬라임";
m_hp = 130;
m_atk = 10;
m_def = 60;
m_item = "점액";
}
void Game::dr()
{
m_name = "DRAGON";
m_hp = 800;
m_atk = 150;
m_def = 180;
m_item = "드래곤의 날개";
}
void Game::gar()
{
m_name = "가고일";
m_hp = 150;
m_atk = 60;
m_def = 50;
m_item = "가고일의 이빨";
}
void Game::gi()
{
m_name = "GIANT";
m_hp = 300;
m_atk = 135;
m_def = 255;
m_item = "거대한 몽둥이";
}
void Game::zom()
{
m_name = "좀비";
m_hp = 100;
m_atk = 40;
m_def = 70;
m_item = "부두교 승려의 부적";
}
void Game::kra()
{
m_name = "KRAKEN";
m_hp = 1000;
m_atk = 100;
m_def = 250;
m_item = "오징어 통다리 구이";
}
void Game::med()
{
m_name = "MEDUSA";
m_hp = 1200;
m_atk = 120;
m_def = 330;
m_item = "메두사 머리";
}
void Game::att()
{
mon();
//플레이어 정보
cout << "__________________________________________________________________" << endl;
cout << "현재 " << name << "의 정보 입니다" << endl;
cout << "체력 : " << hp << " / " << "공격력 : " << atk << " / " << "방어력 : " << def << endl;
cout << "__________________________________________________________________" << endl;
//몬스터 정보
cout << "__________________________________________________________________" << endl;
cout << "현재 " << m_name << "의 정보 입니다" << endl;
cout << "체력 : " << m_hp << " / " << "공격력 : " << m_atk << " / " << "방어력 : " << m_def << endl;
cout << "__________________________________________________________________" << endl;
//죽을떄까지 전투 반복
while (1)
{
// 받은 데미지 저장
int m_dam = atk - m_def; //플레이어 공격력 - 몬스터 방어력 = 데미지
//몬스터의 방어력이 플레이어의 공격력 보다 높을경우 dam 변수에는 - 음수가 들어가기 떄문에 0으로 처리
if (m_dam < 0)
{
m_dam = 0;
}
//플레이어 선 공격 : 받은 데미지 값을 몬스터 hp에 -=로 넣음
cout << "_______________________" << endl;
cout << name << "가 공격을 합니다!" << endl;
cout << m_name << "가 " << m_dam << "만큼 데미지를 받았습니다!" << endl;
m_hp -= m_dam;
//플레이어의 데미지가 몬스터 hp보다 높을경우 몬스터 hp에 - 음수가 들어가기 떄문에 0으로 처리
if (m_hp < 0)
{
m_hp = 0;
//플레이어가 공격후 몬스터의 깍인 체력을 보여줌
SetColor(14);
cout << m_name << "의 남은 체력은 " << m_hp << "입니다!" << endl;
}
//몬스터가 죽었는지 살았는지 확인하기
if (m_hp == 0)
{
SetColor(13);
cout << m_name << "를 처치했습니다!" << endl;
dropItem();
hun();
break;
}
//몬스터가 죽지 않을경우 반격
int dam = m_atk - def; // 몬스터 공격 - 플레이어 방어력 = 데미지
//음수가 나올경우 0처리
if (dam < 0)
{
dam = 0;
}
//몬스터 공격
cout << "_______________________" << endl;
cout << m_name << "가 공격을 합니다!" << endl;
cout << name << "가 " << dam << "만큼 데미지를 받았습니다!" << endl;
hp -= dam;
//음수가 나올경우 0처리
if (hp < 0)
{
hp = 0;
//플레이어의 깍인 체력
SetColor(14);
cout << name << "의 남은 체력은 " << hp << "입니다!" << endl;
}
//플레이어가 죽었는지 살았는지 확인하기
if (hp == 0)
{
Sleep(3000);
SetColor(12);
cout << name << "는 결국 죽었습니다." << endl;
dropItem();
Sleep(2000);
cout << " " << endl;
system("cls");
Sleep(2000);
cout << "........" << endl;
system("cls");
Sleep(2000);
SetColor(14);
cout << "시공간이 바뀝니다" << endl;
Ending();
break;
}
}
}
void Game::dropItem()
{
if (hp == 0)
{
cout << item << "을 떨어트렸다" << endl;
}
if (m_hp == 0)
{
cout << m_item << "을 떨어트렸다" << endl;
}
}
Player::Player() {}
void Player::PrintInventory()
{
cout << "--------인벤토리--------" << endl;
for (int i = 0; i < inventory.size(); i++)
{
cout << i + 1 << "번 째 아이템 : " << inventory[i]->name << " / " << "수량 : " << inventory[i]->itemCount << endl;
}
cout << "--------------------------" << endl;
}
void Player::AddItem(Inventory* item)
{
inventory.push_back(item);
}
void Player::UsedItem(int _id)
{
for (int x = 0; x < inventory.size(); x++)
{
if (inventory[x]->itemCount == 1)
{
cout << inventory[x]->name << "을 사용합니다." << endl;
inventory.erase(inventory.begin() + x);
return;
}
else if (inventory[x]->itemCount > 1)
{
cout << inventory[x]->name << "을 사용합니다." << endl;
inventory[x]->itemCount--;
return;
}
}
}
void Player::ThrowItem(int _id)
{
for (int y = 0; y < inventory.size(); y++)
{
if (inventory[y]->id == _id)
{
cout << inventory[y]->name << "을 버립니다." << endl;
inventory.erase(inventory.begin() + y);
}
}
}
Inventory::Inventory() {}
Inventory::Inventory(string _name, int _id, int _itemCount)
{
name = _name;
id = _id;
itemCount = _itemCount;
}
728x90
'돌다리도 두드려보고 건너라 <복만살>' 카테고리의 다른 글
[C++] 자료구조 종합 정리 (0) | 2022.06.27 |
---|---|
[C++] string / vector / vector+구조체 (0) | 2022.06.15 |
[C++] 구조체/생성자와 소멸자/동적할당/동적배열/상속/가상함수 (0) | 2022.06.13 |
[C++] 배열/2차원배열/구조체/멤버함수/입력/랜덤 (0) | 2022.06.03 |
[C++] 출력/변수/지역성/조건문/연산자/반복문/함수/스택/포인터/배열 (0) | 2022.06.03 |