1. 데이터 테이블 몬스터, 아이템, 플레이어 데이터 로드하기
  2. 메뉴→ 1. 사냥, 2. 상점, 3. 인벤토리. 4. 저장. 5. 종료
  3. 사냥→경험치, 골드, 아이템 사기, 보스 →끝

구현 :

초보자로 시작하여 일정 레벨이상되면 전직을 할 수 있는 전직시스템을 구현함

 

끝내지 못한것 :

아이템 테이블 load에서 문자열 자르는과정에서 생각한대로 잘 안되는중

아이템 구매하면 장착효과 받는 기능

2차 전직 구현

221216 RPG게임(미완).zip
15.82MB

 

'C ++ > C++ 게임' 카테고리의 다른 글

221215 상점 게임 만들기  (0) 2022.12.16
221214 리그 게임 만들기 ( 확장판 )  (0) 2022.12.14
221213 리그 게임 만들기  (0) 2022.12.13
221213 포켓몬스터 간단하게 만들기  (0) 2022.12.13
221209 타자 치기 게임  (0) 2022.12.09
  1. 템플릿을 이용한 더블링크리스트 만들기
  2. 완성된 더블링크드 리스트를 이용하여 상점과 인벤토리 구현
  3. 상점 데이터 테이블에 아이템 정보 작성해서 로그하기, 로드한 정보를 상점에서 판매

구현 :

플레이어는 100골드를 가지고 시작하여 상점에 가서 무작위 아이템을 살수 있음

메뉴에서 하루를 보내면 상점의 아이템들이 하루단위로 무작위로 가격이 변함

플레이어는 산아이템으로 아이템을 더 비싸게 팔아 이득을 보도록 구현

 

코드는 다 되었으나 컴파일하면 링커 에러로 구동되지 않아서 오타 및 정의되지 않은 변수나 함수 사용한지 확인해보는중

221215 상점게임.zip
0.84MB

↓ 인벤토리 내부 구현 함수

template<typename T>
inline Inventory<T>::Inventory()
{
	gold = 100;
}

template<typename T>
inline Inventory<T>::~Inventory()
{
}

template<typename T>
inline void Inventory<T>::AddItem(T itemname, int quantity, int curprice, int boughtprice)
{
	Item<T>* newItem = new Item<T>(itemname, quantity, boughtprice);

	if (head == nullptr) // 첫 insert
	{
		head = newItem;
	}
	else
	{
		tail->next = newItem;
		newItem->prev = tail;
	}

	tail = newItem;

	invensize++;
}

template<typename T>
inline void Inventory<T>::Buy(T itemname, int quantity, int boutghtprice)
{
	Item<T>* newItem = new Item<T>(itemname, quantity, boutghtprice);

	if (head == nullptr) // 첫 insert
	{
		head = newItem;
	}
	else
	{
		tail->next = newItem;
		newItem->prev = tail;
	}

	tail = newItem;

	if (gold < quantity * boutghtprice)
	{
		cout << "골드가 부족합니다." << endl;
		Sleep(1000);
		return;
	}

	gold -= quantity * boutghtprice;

	invensize++;
}

template<typename T>
inline void Inventory<T>::Sell(T itemname, int quantity, int sellprice)
{
	Item<T>* selectitem = head;

	int count = 0;

	for (int i = 0; i < invensize; i++)
	{
		if (itemname == selectitem->itemname)
		{
			break;
		}

		if (i == invensize - 1)
		{
			cout << "판매하려는 아이템이 없습니다." << endl;
			Sleep(1000);
			return;
		}

		selectitem = selectitem->next;
	}

	selectitem->quantity -= quantity;
	gold += quantity * (sellprice - selectitem->boughtprice);

}

template<typename T>
inline Item<T>* Inventory<T>::Find(int index)
{
	Item<T>* selectitem = head;

	for (int i = 0; i < index - 1; i++)
	{
		selectitem = selectitem->next;
	}

	return selectitem;
}

template<typename T>
inline void Inventory<T>::PrintInven()
{
	if (head == nullptr)
	{
		cout << "인벤토리가 비어있습니다." << endl;
		Sleep(1000);
		return;
	}

	cout << "현재 골드 : " << gold << "G" << endl;

	int count = 0;

	for (Item<T>* item = head; item != nullptr; item = item->next)
	{
		cout << ++count << "번째 아이템 : " << item->itemname << endl;
		cout << "수량 : " << item->quantity << " 구매했던 가격 : " << item->boughtprice << endl;
	}
}

'C ++ > C++ 게임' 카테고리의 다른 글

221216 RPG 게임 만들기  (0) 2022.12.16
221214 리그 게임 만들기 ( 확장판 )  (0) 2022.12.14
221213 리그 게임 만들기  (0) 2022.12.13
221213 포켓몬스터 간단하게 만들기  (0) 2022.12.13
221209 타자 치기 게임  (0) 2022.12.09
  1. 리그게임 만든거에서 한 플레이어를 골라서 직접 컨트롤.
  2. (fstream of fscanf) 세이브 로드 구현하기, 플레이어 수, 모든 플레이어들 정보 다 저장해서 리그게임 그대로 이어서 하기
  3. 일정 게임 플레이 하면 승자 토너먼트 구현하기

구현 : 

플레이어로 참여하여 한 클래스로 골라서 리그에 참여

레벨시스템을 도입하여, 레벨업할때마다, 스킬포인트, 공격력, 체력이 레벨비례로 상승됨

각 플레이어끼리 한경기씩 마치면 종료되면서 자동으로 SAVE되어 플레이어의 이름에 맞춰서 레벨, 경험치가 저장되고,

다시 플레이하면 해당 레벨 경험치가 로드할수있고, 플레이했던 데이터 그대로 플레이가능

Load는 txt에 저장된 파일에 한줄을 먼저 getline으로 string을 따와서 substr함수로 " "을 기준으로 문자열을 잘라 각각 동적할당된 player의 이름, lv, exp에 새로 할당

성현준 리그게임(확장).zip
15.72MB

↓ Load 테스트

↓ Save 테스트

 

↓ 새로 추가한 Save, Load와 Load할때 불러온 레벨과 경험치에 따라서 능력치 설정 함수

void GameManager::Save()
{
    ofstream fout(FILE_NAME);
    
    for (int i = 0; i < playersize; i++)
    {
        fout << players[i]->GetStatus().playername << " " << players[i]->GetLevel() << 
        " " << players[i]->GetExp() << endl;
    }

    fout.close();
}

void GameManager::Load()
{
    ifstream fin(FILE_NAME);

    string temp;
    string separator = " ";
    int position;
    uint templv;
    uint tempexp;

    if (fin.is_open())
    {
        for (int i = 0; i < playersize; i++)
        {
            int cur_position = 0;
            getline(fin, temp);
            if ((position = temp.find(separator, cur_position)) != string::npos)
            {
                int len = position - cur_position;
                players[i]->SetPlayerName(temp.substr(cur_position, len));
                cur_position = position + 1;

                templv = stoi((temp.substr(cur_position, len)));
                cur_position = position + 2;

                tempexp = stoi((temp.substr(cur_position, len)));
                cur_position = position + 1;

                players[i]->LoadSetting(templv, tempexp);
            }
        }
        
        fin.close();
    }
}

void Player::LoadSetting(uint level, uint exp)
{
	this->level = level;
	this->exp = exp;
	maxSp += level - 1;
	curSp = maxSp;
	
	for (int i = 0; i < level - 1; i++)
	{
		SetAttack();
		SetMaxHp();
	}
}

'C ++ > C++ 게임' 카테고리의 다른 글

221216 RPG 게임 만들기  (0) 2022.12.16
221215 상점 게임 만들기  (0) 2022.12.16
221213 리그 게임 만들기  (0) 2022.12.13
221213 포켓몬스터 간단하게 만들기  (0) 2022.12.13
221209 타자 치기 게임  (0) 2022.12.09
  1. n개의 특색있는 직업을 가진 캐릭터 생성 ( 상속 ) 
  2. 리그 참가할 플레이어 갯수 입력 
  3. 각 플레이어는 직업을 가진 캐릭터를 이용해 리그 참가 
  4. 리그 게임 구현 

ex ) 티모, 잔나, 가렌, 리븐

참가할 플레이어 : 4

→ 1. 티모 2. 잔나 3. 리븐 4. 가렌 …

메뉴 : 1. 경기 시작 2. 리그 정보 3. 종료

1→ 1day : 1 -2, 3 -4

1→ 2day : 1 - 3, 2 - 4

1→ 3day : 1 - 4 , 2 - 3

3→ 티모 : 1승 2패 - 총 딜량

잔나 : 2승 1패

리븐 : ~ 승 ~패

 

구현 : 

플레이어가 7개의 클래스 중 하나를 선택하고, 나머지 플레이어들도 각자 클래스를 중복없이 선택하여 리그를 참여하게 구현 ( 최대 7플레이어 참여 가능 )

1일차가 끝날때마다 플레이들의 성적을 출력해주도록 구현, 게임이 끝날때도 성적 출력

다른 컴퓨터 플레이어들도 컴퓨터끼리의 전투때 스킬을 사용할수 있게끔 구현

성현준 리그게임.zip
14.97MB

  1. 플레이어 객체 만들기 → 변수 : 이름, 공격력, 방어력, 체력, 마나, 경험치, 레벨
  2. 플레이어 함수 : 기본 공격, 피격, 스킬, 정보 출력
  3. 몬스터 객체 만들기 → 변수 : 이름, 공격력, 방어력, 체력, 마나
  4. 몬스터 함수 : 기본 공격, 피격, 정보 출력
  5. 게임 시작하면 사냥할 몬스터를 입력, 입력값에 따라서 몬스터 동적 할당하고,
  6. 할당된 몬스터는 랜덤으로 공격력 체력 따로 가지기
  7. 할당된 몬스터 다잡으면 게임 클리어
  8. 루프돌리면서 다시 사냥하고 경험치랑 레벨 저장 로드하기

Pokemon.zip
1.91MB

#include <iostream>
#include <string>
#include <time.h>
#include <Windows.h>
#include "Pokemon.h"
#include "Pikachu.h"
#include "Bulbasaur.h"
#include "Charmander.h"
#define MIN 1
#define MAX_ATK 19
#define MAX_DEF 9
#define MAX_HP 99
#define MAX_POKEMON 3

using namespace std;

void Battle(PlayerPokemon* pp[], EnemyPokemon* ep[]);
int PickRandomPokemon(EnemyPokemon* ep[]);
bool CheckMiss(int damage);
bool CheckFinish(EnemyPokemon* ep[]);

int main()
{
	srand(time(NULL));
	Pikachu* pikachu = new Pikachu();
	Charmander* charmander = new Charmander();
	Bulbasaur* bulbasaur = new Bulbasaur();
	EnemyPokemon* enemy1 = new EnemyPokemon("피죤");
	EnemyPokemon* enemy2 = new EnemyPokemon("꼬렛");
	EnemyPokemon* enemy3 = new EnemyPokemon("고라파덕");

	PlayerPokemon* player[MAX_POKEMON] = { pikachu, charmander, bulbasaur };
	EnemyPokemon* enemy[MAX_POKEMON] = { enemy1, enemy2, enemy3 };
	cout << "=======포켓몬스터를 시작하겠습니다!=======" << endl;
	Sleep(1000);
	Battle(player, enemy);
}

void Battle(PlayerPokemon* pp[], EnemyPokemon* ep[])
{
	int enemypick = PickRandomPokemon(ep);
	int pinput;
	int input;
	int sinput;
	int change;
	int damage = 0;
	int iteminput;

	cout << "야생의 " << ep[enemypick]->GetName() << "이 나타났다!" << endl;
	Sleep(1000);
	cout << "내보낼 포켓몬을 선택해주세요." << endl;
	Sleep(1000);
	cout << "1. " << pp[0]->GetName() << " 2. " << pp[1]->GetName() << " 3. " << pp[2]->GetName() << endl;
	cin >> pinput;
	cout << "나와라! " << pp[pinput - 1]->GetName() << "!" << endl;
	Sleep(1000);
	system("cls");

	while (true)
	{
		cout << "자신의 포켓몬[" << pp[pinput - 1]->GetName() << "] 체력 : " << pp[pinput - 1]->GetHp() << endl;
		cout << "적 포켓몬[" << ep[enemypick]->GetName() << "] 체력 : " << ep[enemypick]->GetHp() << endl;
 		cout << "1. 공격 2. 자신의 스테이터스 보기 3. 적 스테이터스 보기 4. 아이템 사용"  << endl;
		cin >> input;

		switch (input)
		{
		case 1:
		{
			cout << "1. " << pp[pinput - 1]->GetSkill1name() << " 2. " << pp[pinput - 1]->GetSkill2name()
				<< " 3. " << pp[pinput - 1]->GetSkill3name() << endl;
			cin >> sinput;

			if (sinput == 1)
			{
				cout << pp[pinput - 1]->GetName() << "의 " << pp[pinput - 1]->GetSkill1name() << "!" << endl;
				Sleep(1000);
				damage = pp[pinput - 1]->GetAtk() - ep[enemypick]->GetDef();
			}
			else if (sinput == 2)
			{
				cout << pp[pinput - 1]->GetName() << "의 " << pp[pinput - 1]->GetSkill2name() << "!" << endl;
				Sleep(1000);
				damage = pp[pinput - 1]->GetAtk() * 2 - ep[enemypick]->GetDef();
			}
			else if (sinput == 3)
			{
				cout << pp[pinput - 1]->GetName() << "의 " << pp[pinput - 1]->GetSkill3name() << "!" << endl;
				Sleep(1000);
				damage = pp[pinput - 1]->GetAtk() * 5 - ep[enemypick]->GetDef();
			}

			cout << ep[enemypick]->GetName() << "에게 " << damage << "의 피해를 입혔다!" << endl;
			Sleep(1000);

			if (CheckMiss(damage) == false)
			{
				ep[enemypick]->SetHp(ep[enemypick]->GetHp() - damage);
			}

			cout << ep[enemypick]->GetName() << "이 " << pp[pinput - 1]->GetName() << "을 공격했다!" << endl;
			damage = ep[enemypick]->GetAtk() - pp[pinput - 1]->GetDef();
			Sleep(1000);
			cout << damage << "의 데미지를 입었다!" << endl;
			pp[pinput - 1]->SetHp(pp[pinput - 1]->GetHp() - damage);
			Sleep(1000);
			system("cls");
			
			if (pp[pinput - 1]->GetHp() <= 0)
			{
				cout << pp[pinput]->GetName() << "가 쓰러졌다!" << endl;
				pp[pinput]->SetDead();
				Sleep(1000);
				while (1)
				{
					cout << "교체할 포켓몬을 골라주세요." << endl;
					Sleep(1000);
					cout << "1. " << pp[0]->GetName() << " 2. " << pp[1]->GetName() << " 3. " << pp[2]->GetName() << endl;
					cin >> pinput;

					if (pp[pinput - 1]->CheckDead() == true)
					{
						cout << "이미 기절한 포켓몬입니다." << endl;
						Sleep(1000);
					}
					else
					{
						break;
					}
				}
				
			}

			if (ep[enemypick]->GetHp() <= 0)
			{
				cout << ep[enemypick]->GetName() << "이 쓰러졌다!" << endl;
				ep[enemypick]->SetDead();
				Sleep(1000);
				system("cls");
				Battle(pp, ep);
			}

			break;
		}
		case 2:
		{
			cout << "=========================================" << endl;
			cout << "  포켓몬 이름 : " << pp[pinput - 1]->GetName() << endl;
			cout << "  포켓몬 ATK : " << pp[pinput - 1]->GetAtk() << endl;
			cout << "  포켓몬 DEF : " << pp[pinput - 1]->GetDef() << endl;
			cout << "  포켓몬 HP : " << pp[pinput - 1]->GetHp() << endl;
			cout << "=========================================" << endl;
			Sleep(1000);
			system("cls");
			continue;
		}
		case 3:
		{
			cout << "=========================================" << endl;
			cout << "  적 포켓몬 이름 : " << ep[enemypick]->GetName() << endl;
			cout << "  적 포켓몬 ATK : " << ep[enemypick]->GetAtk() << endl;
			cout << "  적 포켓몬 DEF : " << ep[enemypick]->GetDef() << endl;
			cout << "  적 포켓몬 HP : " << ep[enemypick]->GetHp() << endl;
			cout << "=========================================" << endl;
			Sleep(1000);
			system("cls");
			continue;
		}
		case 4:
		{
			cout << "1. 상처약 2. 좋은 상처약 3. 포켓몬볼" << endl;
			cin >> iteminput;

			if (iteminput == 1)
			{
				cout << "상처약을 사용했다!" << endl;
				Sleep(1000);
				cout << "체력이 20만큼 올랐다!" << endl;
				pp[pinput - 1]->SetHp(pp[pinput - 1]->GetHp() + 20);
				Sleep(1000);
				system("cls");
				
			}
			else if (iteminput == 2)
			{
				cout << "좋은 상처약을 사용했다!" << endl;
				Sleep(1000);
				cout << "체력이 50만큼 올랐다!" << endl;
				pp[pinput - 1]->SetHp(pp[pinput - 1]->GetHp() + 50);
				Sleep(1000);
				system("cls");
			}
			
			continue;
		}
		
		}
	}
}

int PickRandomPokemon(EnemyPokemon* ep[])
{
	int pick = rand() % 3;

	while (true)
	{

		if (ep[pick]->CheckDead() == true)
		{
			pick = rand() % 3;
		}
		else
		{
			break;
		}
	}

	return pick;
}

bool CheckMiss(int damage)
{
	if (damage <= 0)
	{
		cout << "공격이 빗나갔습니다!" << endl;
		Sleep(1000);
		return true;
	}

	return false;
}

bool CheckFinish(EnemyPokemon* ep[])
{
	int count = 0;
	for (int i = 0; i < MAX_POKEMON; i++)
	{
		if (ep[i]->CheckDead() == true)
		{
			count++;
		}
		
		if (count == MAX_POKEMON)
		{
			cout << "야생 포켓몬이 전부 기절했습니다." << endl;
			Sleep(1000);
			cout << "Game Clear!" << endl;
			Sleep(1000);
			return true;
		}
	}

	return false;
}

'C ++ > C++ 게임' 카테고리의 다른 글

221214 리그 게임 만들기 ( 확장판 )  (0) 2022.12.14
221213 리그 게임 만들기  (0) 2022.12.13
221209 타자 치기 게임  (0) 2022.12.09
221208 슬라이드 게임 만들기  (0) 2022.12.08
221208 빙고 게임  (0) 2022.12.08

+ Recent posts