Difference between r1.12 and the current
@@ -1847,4 +1847,6 @@
}}}
* 다음 버전에서는 몬스터 등을 아얘 따로 저장하는 파일을 만들어서 그걸 읽어들여서 몹들을 생성하게 해야겠습니다. 일일이 메인 cpp에서 만들려고 하니 한없이 코드 줄만 길어지네요. 그리고 프로그래밍 공부를 좀 더 해야겠다는 생각이 들었습니다 ㅋㅋ 분명히 저기서 제가 삽질을 한 부분이 있을거에요 ㅠㅠ 이제 버전 1.2에선 소켓프로그래밍을 이용해서 네트워크 대전을 넣을 예정입니다.- [신기호]
* 다음 버전에서는 몬스터 등을 아얘 따로 저장하는 파일을 만들어서 그걸 읽어들여서 몹들을 생성하게 해야겠습니다. 일일이 메인 cpp에서 만들려고 하니 한없이 코드 줄만 길어지네요. 그리고 프로그래밍 공부를 좀 더 해야겠다는 생각이 들었습니다 ㅋㅋ 분명히 저기서 제가 삽질을 한 부분이 있을거에요 ㅠㅠ 이제 버전 1.2에선 소켓프로그래밍을 이용해서 네트워크 대전을 넣을 예정입니다.- [신기호]
* 초반에 드랍한테 잡혔더니 도망치기가 매번 실패해서 나보다 센 몹한테 잡히면 도망 못치나보다 했는데 코드 읽어보니 그냥 50%네... 근데 난 왜 도망을 못쳤지ㅠㅠㅠㅠㅠㅠ - [김수경]
----1.1. simplegame.cpp ¶
// 신기호. all rights reserved.
//simplegame.cpp simple huh?
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <io.h>
#define MAX_STRING 100
#define MAX_TOWN 5
#define MAX_ENEMY 5
#define MAX_ITEMS 40
#define FILE_NAME "csave.dat"
typedef struct{
int base_hp;
int hp;
int max_hp;
int att;
int base_att;
int def;
int base_def;
char name[MAX_STRING];
int townNum;
int level;
unsigned int xp;
unsigned int next_xp;
int money;
}entity;
typedef struct{
char name[MAX_STRING];
int att;
int def;
int hp_plus;
char tooltip[MAX_STRING];
}inventory;
typedef struct{
char name[MAX_STRING];
}town;
town T[MAX_TOWN];
inventory inven[MAX_ITEMS];
inventory tmpInven;
int i_top=-1;
inventory storage[3];
int cost[3];
entity Main;
entity Enemy[MAX_ENEMY];
FILE *state;
bool gameover=false;
void init(bool first);
void itemPush(inventory item);
inventory itemFind(int index);
void discardItem(int index);
void store();
void travel(town dest,int distance,int townNum);
void setTravelDest();
void battle();
void rest();
void viewItems();
void setStat();
void start(bool first);
void buyItem(inventory item,int index);
bool loadGame(FILE *state){
int count=0;
i_top=-1;
inventory tmpItem;
state=fopen(FILE_NAME,"r");
if(state==NULL){
return false;
}
printf("Loading...\n");
char buff[MAX_STRING];
while(strcmp(buff,"EOF")!=0){
fscanf(state,"%s",buff);
if(strcmp(buff,"level:")==0)
fscanf(state,"%d",&Main.level);
else if(strcmp(buff,"base_hp:")==0)
fscanf(state,"%d",&Main.base_hp);
else if(strcmp(buff,"hp:")==0)
fscanf(state,"%d",&Main.hp);
else if(strcmp(buff,"base_att:")==0)
fscanf(state,"%d",&Main.base_att);
else if(strcmp(buff,"base_def:")==0)
fscanf(state,"%d",&Main.base_def);
else if(strcmp(buff,"name:")==0){
char tmp;
char tmpName[MAX_STRING];
int i=0;
fscanf(state,"%c",&tmp);
do{
fscanf(state,"%c",&tmp);
tmpName[i++]=tmp;
}while(tmp!='\n');
tmpName[i-1]='\0';
strcpy(Main.name,tmpName);
}
else if(strcmp(buff,"townNum:")==0)
fscanf(state,"%d",&Main.townNum);
else if(strcmp(buff,"xp:")==0)
fscanf(state,"%u",&Main.xp);
else if(strcmp(buff,"next_xp:")==0)
fscanf(state,"%u",&Main.next_xp);
else if(strcmp(buff,"money:")==0)
fscanf(state,"%d",&Main.money);
else if(strcmp(buff,"inven:")==0){
int num;
fscanf(state,"%d",&num);
for(int i=0;i<num;i++){
do{
fscanf(state,"%s",buff);
if(strcmp(buff,"name:")==0){
char tmp;
char tmpName[MAX_STRING];
int i=0;
fscanf(state,"%c",&tmp);
do{
fscanf(state,"%c",&tmp);
tmpName[i++]=tmp;
}while(tmp!='\n');
tmpName[i-1]='\0';
strcpy(tmpInven.name,tmpName);
}
else if(strcmp(buff,"att:")==0)
fscanf(state,"%d",&tmpInven.att);
else if(strcmp(buff,"def:")==0)
fscanf(state,"%d",&tmpInven.def);
else if(strcmp(buff,"hp_plus:")==0)
fscanf(state,"%d",&tmpInven.hp_plus);
else if(strcmp(buff,"tooltip:")==0){
char tmp;
char tmpName[MAX_STRING];
int i=0;
fscanf(state,"%c",&tmp);
do{
fscanf(state,"%c",&tmp);
tmpName[i++]=tmp;
}while(tmp!='\n');
tmpName[i-1]='\0';
strcpy(tmpInven.tooltip,tmpName);
}
}while(strcmp(buff,"END")!=0);
itemPush(tmpInven);
}
}
}
fclose(state);
setStat();
printf("Load complete!\n");
fflush(stdin);
getchar();
return true;
}
void saveState(FILE *state){
state=fopen(FILE_NAME,"w+");
printf("Saving...\n");
fprintf(state,"level: %d\n",Main.level);
fprintf(state,"base_hp: %d\n",Main.base_hp);
fprintf(state,"hp: %d\n",Main.hp);
fprintf(state,"base_att: %d\n",Main.base_att);
fprintf(state,"base_def: %d\n",Main.base_def);
fprintf(state,"name: %s\n",Main.name);
fprintf(state,"townNum: %d\n",Main.townNum);
fprintf(state,"xp: %u\n",Main.xp);
fprintf(state,"next_xp: %u\n",Main.next_xp);
fprintf(state,"money: %d\n",Main.money);
fprintf(state,"inven: %d\n",i_top+1);
for(int i=0;i<=i_top;i++){
fprintf(state,"name: %s\n",inven[i].name);
fprintf(state,"att: %d\n",inven[i].att);
fprintf(state,"def: %d\n",inven[i].def);
fprintf(state,"hp_plus: %d\n",inven[i].hp_plus);
fprintf(state,"tooltip: %s\n",inven[i].tooltip);
fprintf(state,"END\n");
}
fprintf(state,"EOF");
fclose(state);
printf("Save complete!\n");
fflush(stdin);
getchar();
}
int main(void){
char buff;
while(true){
fflush(stdin);
printf("<<중대생 rpg ver1.0 made by 신기호>>\n<<버그가 발생할 시 바로 알려주세요.>>\n");
printf("1.새로하기\n2.이어하기\n3.종료\n");
scanf("%c",&buff);
switch(buff){
case '1':
system("cls");
init(true);
start(true);
break;
case '2':
system("cls");
if(loadGame(state)){
init(false);
start(false);
}
else{
init(true);
start(true);
}
break;
case '3':
return 0;
}
system("cls");
}
return 0;
}
void init(bool first){
gameover=false;
strcpy(T[0].name,"208관");
strcpy(T[1].name,"봅스트홀");
strcpy(T[2].name,"R&D센터");
strcpy(T[3].name,"흑석역");
strcpy(T[4].name,"청룡탕");
if(first){
i_top=-1;
inventory item;
item.att=1;
item.def=0;
item.hp_plus=0;
strcpy(item.name,"볼 마우스");
strcpy(item.tooltip,"구시대적인 마우스다.");
itemPush(item);
Main.base_hp=30;
Main.hp=Main.base_hp;
Main.base_att=1;
Main.base_def=1;
Main.townNum=0;
Main.level=1;
Main.xp=0;
Main.next_xp=30;
strcpy(Main.name,"");
}
strcpy(Enemy[0].name,"과제");
strcpy(Enemy[1].name,"씨드");
strcpy(Enemy[2].name,"쌍권총");
strcpy(Enemy[3].name,"드랍");
strcpy(Enemy[4].name,"청룡");
Enemy[0].att=3;
Enemy[0].def=0;
Enemy[0].hp=15;
Enemy[0].max_hp=15;
Enemy[0].money=15;
Enemy[0].xp=10;
Enemy[0].townNum=0;
Enemy[1].att=10;
Enemy[1].def=8;
Enemy[1].hp=50;
Enemy[1].max_hp=50;
Enemy[1].money=35;
Enemy[1].xp=20;
Enemy[1].townNum=1;
Enemy[2].att=40;
Enemy[2].def=18;
Enemy[2].hp=130;
Enemy[2].max_hp=130;
Enemy[2].money=46;
Enemy[2].xp=30;
Enemy[2].townNum=2;
Enemy[3].att=68;
Enemy[3].def=37;
Enemy[3].hp=350;
Enemy[3].max_hp=350;
Enemy[3].money=58;
Enemy[3].xp=64;
Enemy[3].townNum=3;
Enemy[4].att=726;
Enemy[4].def=427;
Enemy[4].hp=5430;
Enemy[4].max_hp=5430;
Enemy[4].money=70;
Enemy[4].xp=120;
Enemy[4].townNum=4;
}
void start(bool first){
char buff;
if(first){
char name[MAX_STRING];
printf("이름을 입력하세요: ");
scanf("%s",name);
strcpy(Main.name,name);
}
setStat();
while(true){
if(gameover)
break;
system("cls");
printf("당신은 %s에 있습니다.\n무엇을 하시겠습니까?\n",T[Main.townNum].name);
printf("1.아이템을 산다\n2.쉰다\n3.보유 아이템 확인\n4.다른 마을로 이동한다\n5.저장\n6.불러오기\n7.종료\n");
scanf("%c",&buff);
switch(buff){
case '1':
system("cls");
store();
break;
case '2':
system("cls");
rest();
break;
case '3':
system("cls");
viewItems();
break;
case '4':
system("cls");
setTravelDest();
break;
case '5':
system("cls");
saveState(state);
break;
case '6':
system("cls");
loadGame(state);
break;
case '7':
system("cls");
gameover=true;
break;
}
}
return;
}
void rest(){
fflush(stdin);
printf("충분한 휴식을 취했습니다.\n");
Main.hp=Main.max_hp;
getchar();
}
void store(){
float num;
bool exit=false;
srand((unsigned)time(NULL));
num=(rand()%10)/10+rand()%2;
if(num<=0.4){
strcpy(storage[0].name,"혁명의 구슬(오브)");
storage[0].att=6;
storage[0].def=2;
storage[0].hp_plus=4;
cost[0]=1300;
strcpy(storage[0].tooltip,"기분이 상쾌해진다.");
}
else if(num<=0.7){
strcpy(storage[0].name,"교수님의 노트(부적)");
storage[0].att=10;
storage[0].def=4;
storage[0].hp_plus=20;
cost[0]=2400;
strcpy(storage[0].tooltip,"지식이 깊어진다.\n");
}
else if(num<=0.9){
strcpy(storage[0].name,"절대 마우스(유니크)");
storage[0].att=100;
storage[0].def=100;
storage[0].hp_plus=200;
cost[0]=13500;
strcpy(storage[0].tooltip,"모든것을 지배하는 하나의 마우스.\n");
}
else{
strcpy(storage[0].name,"희미한 혁명의 기운(구슬)");
storage[0].att=2;
storage[0].def=1;
storage[0].hp_plus=0;
cost[0]=200;
strcpy(storage[0].tooltip,"용기가 약간 생긴다.");
}
strcpy(storage[1].name,"컴공 과잠(방어구)");
storage[1].att=0;
storage[1].def=2;
storage[1].hp_plus=5;
cost[1]=320;
strcpy(storage[1].tooltip,"40주년 과잠.");
strcpy(storage[2].name,"교수님의 노트 조각(부적)");
storage[2].att=3;
storage[2].def=0;
storage[2].hp_plus=0;
cost[2]=350;
strcpy(storage[2].tooltip,"교수님의 노트 중 일부.");
while(true){
if(exit)
break;
printf("보유하고 있는 돈: %d원\n",Main.money);
for(int i=0;i<3;i++){
printf("%d: %s\t--가격: %d 원\n",i+1,storage[i].name,cost[i]);
}
printf("무엇을 하시겠습니까?\n1.산다\n2.편의점을 나간다\n");
scanf("%f",&num);
switch((int)num){
case 1:
int num2;
printf("무엇을 사시겠습니까?: ");
scanf("%d",&num2);
buyItem(storage[num2],num2-1);
system("cls");
break;
case 2:
exit=true;
break;
}
}
}
void buyItem(inventory item,int index){
if(Main.money<cost[index]){
printf("돈이 부족합니다.\n");
fflush(stdin);
getchar();
return;
}
if(i_top<=MAX_ITEMS-1){
printf("점원: 감사합니다!\n");
Main.money-=cost[index];
printf("당신은 %s을 구입했습니다.\n",storage[index].name);
itemPush(storage[index]);
setStat();
fflush(stdin);
getchar();
return;
}
else{
printf("더 이상 아이템을 가질 수 없습니다.");
fflush(stdin);
getchar();
return;
}
}
void viewItems(){
inventory tmp;
char buff;
bool flag=false;
while(true){
if(flag)
break;
system("cls");
fflush(stdin);
int att_plus=0,def_plus=0;
for(int i=0;i<=i_top;i++){
att_plus+=inven[i].att;
def_plus+=inven[i].def;
}
printf("--%s 상태--\n레벨:%d\n경험치:%d\n다음 레벨까지:%d\n공격력:%d + %d\n방어력:%d + %d\n체력:%d / %d\n",Main.name,
Main.level,Main.xp,Main.next_xp,Main.base_att,att_plus,Main.base_def,def_plus,Main.hp,Main.max_hp);
printf("인벤토리:\n");
for(int i=0;i<=i_top;i++){
tmp=itemFind(i);
printf("%d: %s\n",i+1,tmp.name);
}
printf("------------------\n");
printf("무엇을 하시겠습니까?\n1.인벤토리 관리\n2.나간다\n");
scanf("%c",&buff);
switch(buff){
case '1':
int num;
printf("선택: ");
scanf("%d",&num);
if(num>=1&&num<=i_top+1){
bool flag2=false;
int num2;
while(true){
if(flag2)
break;
fflush(stdin);
tmp=itemFind(num-1);
printf("<%s>\n옵션:\n1.살펴보기\n2.버리기\n3.취소\n",tmp.name);
scanf("%d",&num2);
switch(num2){
case 1:
printf("%s\n",inven[num-1].tooltip);
printf("공격력 보너스: %d\n방어력 보너스: %d\n체력 보너스: %d\n",tmp.att,tmp.def,tmp.hp_plus);
flag2=true;
fflush(stdin);
getchar();
system("cls");
break;
case 2:
printf("아이템을 버렸습니다.\n");
discardItem(num-1);
flag2=true;
system("cls");
break;
case 3:
flag2=true;
system("cls");
break;
}
}
}
break;
case '2':
flag=true;
break;
}
}
}
void setTravelDest(){
char buff;
bool exit=false;
int distance;
printf("어디로 가시겠습니까?(거리에 따라 전투의 발생 횟수가 변할 수 있습니다.)\n");
for(int i=0;i<MAX_TOWN;i++){
if(i!=Main.townNum){
distance=i-Main.townNum;
if(distance<0)
printf("%s: 거리 %d\n",T[i].name,-distance);
else
printf("%s: 거리 %d\n",T[i].name,distance);
}
}
printf("----------------------------\n");
int count=0;
int T_ptr[MAX_TOWN-1];
for(int i=0;i<MAX_TOWN;i++){
if(i!=Main.townNum){
printf("%d, %s\n",count+1,T[i].name);
T_ptr[count++]=i;
}
}
while(true){
if(exit)
break;
fflush(stdin);
printf("선택: ");
scanf("%c",&buff);
switch(buff){
case '1':
travel(T[T_ptr[0]],distance,T_ptr[0]);
exit=true;
break;
case '2':
travel(T[T_ptr[1]],distance,T_ptr[1]);
exit=true;
break;
case '3':
travel(T[T_ptr[2]],distance,T_ptr[2]);
exit=true;
break;
case '4':
travel(T[T_ptr[3]],distance,T_ptr[3]);
exit=true;
break;
case '5':
travel(T[T_ptr[4]],distance,T_ptr[4]);
exit=true;
break;
}
}
}
void travel(town dest,int distance,int townNum){
if(distance<0){
for(int i=0;i<-distance;i++){
srand((unsigned)time(NULL));
int num=rand()%10+1;
if(num<=6)
battle();
if(gameover)
return;
}
Main.townNum=townNum;
}
else{
for(int i=0;i<distance;i++){
srand((unsigned)time(NULL));
int num=rand()%10+1;
if(num<4)
battle();
if(gameover)
return;
}
Main.townNum=townNum;
}
}
void battle(){
char buff;
int en;
bool end=false;
system("cls");
entity tmpEn=Enemy[Main.townNum];
printf("%s이(가) 싸우고 싶어합니다!!\n",tmpEn.name);
fflush(stdin);
getchar();
while(true){
if(end)
break;
fflush(stdin);
system("cls");
printf("플레이어:%s---\n체력: %d / %d\n적:%s---\n체력: %d / %d\n",Main.name,Main.hp,Main.max_hp,tmpEn.name,tmpEn.hp,tmpEn.max_hp);
if(tmpEn.hp<=0){
printf("승리!\n");
printf("보상:\n");
srand((unsigned)time(NULL));
int money,xp;
money=tmpEn.money;
xp=tmpEn.xp;
printf("1.돈: %d 원\n",money);
printf("2.경험치: %d\n",xp);
Main.money+=money;
Main.xp+=xp;
if(Main.xp>=Main.next_xp){
Main.level++;
Main.next_xp=Main.xp*2;
Main.base_hp=Main.base_hp+Main.level*10;
Main.base_att=Main.base_att+Main.level*2;
Main.base_def=Main.base_def+Main.level;
setStat();
printf("레벨업!\n현재 레벨: %d\t다음 레벨까지 남은 경험치: %d\n체력: %d\t공격력: %d\t방어력: %d",Main.level,Main.next_xp,Main.max_hp,Main.att,Main.def);
}
setStat();
fflush(stdin);
getchar();
end=true;
continue;
}
else if(Main.hp<=0){
printf("패배했습니다.\n");
fflush(stdin);
getchar();
gameover=true;
end=true;
continue;
}
else{
printf("1.공격\n2.방어\n3.도망\n");
scanf("%c",&buff);
switch(buff){
case '1':
srand((unsigned)time(NULL));
en=rand()%10;
printf("%s을(를) 공격했다!\n",tmpEn.name);
fflush(stdin);
getchar();
if(en<=4){
if(tmpEn.def-Main.att>0)
tmpEn.hp--;
else
tmpEn.hp-=Main.att;
printf("적 %s이(가) 공격했다!\n",tmpEn.name);
fflush(stdin);
getchar();
if(Main.def-tmpEn.att>0)
Main.hp--;
else
Main.hp-=tmpEn.att;
}
else if(en>4&&en<=8){
if(tmpEn.def-Main.att>0)
tmpEn.hp--;
else
tmpEn.hp-=Main.att-tmpEn.def;
printf("적 %s이(가) 자신을 방어했다.\n",tmpEn.name);
fflush(stdin);
getchar();
}
else{
printf("적 %s이(가) 도망갔다.\n",tmpEn.name);
fflush(stdin);
getchar();
end=true;
continue;
}
break;
case '2':
srand((unsigned)time(NULL));
en=rand()%10;
printf("방어했습니다.\n");
fflush(stdin);
getchar();
if(en<=4){
printf("적 %s이(가) 공격했다!\n",tmpEn.name);
fflush(stdin);
getchar();
if(Main.def-tmpEn.att>0)
Main.hp--;
else
Main.hp-=tmpEn.att-Main.def;
}
else if(en>4&&en<=8){
printf("적 %s이(가) 자신을 방어했다.\n",tmpEn.name);
fflush(stdin);
getchar();
}
else{
printf("적 %s이(가) 도망갔다.\n",tmpEn.name);
fflush(stdin);
getchar();
end=true;
continue;
}
break;
case '3':
srand((unsigned)time(NULL));
int flee=rand()%10;
if(flee>=6){
printf("당신은 전투에서 도망쳤습니다.\n");
fflush(stdin);
getchar();
end=true;
continue;
}
else{
printf("당신은 도망칠 수 없었습니다.\n");
fflush(stdin);
getchar();
break;
}
}
}
}
}
void setStat(){
Main.max_hp=Main.base_hp;
Main.att=Main.base_att;
Main.def=Main.base_def;
for(int i=0;i<=i_top;i++){
Main.max_hp=Main.max_hp+inven[i].hp_plus;
Main.att=Main.att+inven[i].att;
Main.def=Main.def+inven[i].def;
}
}
void itemPush(inventory item){
if(i_top>=MAX_ITEMS-1)
return;
inven[++i_top]=item;
}
inventory itemFind(int index){
return inven[index];
}
void discardItem(int index){
inventory tmpItem;
tmpItem=inven[index];
for(int i=index+1;i<=i_top;i++)
inven[i-1]=inven[i];
i_top--;
Main.max_hp-=tmpItem.hp_plus;
Main.att-=tmpItem.att;
Main.def-=tmpItem.def;
}
2.1. game_comp.h ¶
#pragma once
#ifndef _GAME_COMP_H_
#define _GAME_COMP_H
#define MAX_STRING 100
#define MAX_ITEMS 40
class item{
private:
char name[MAX_STRING];
int att;
int def;
int hp_plus;
char tooltip[MAX_STRING];
int cost;
public:
item(){}
void setInfo(char *_name,int _att,int _def,int _hp_plus,char *_tooltip,int _cost);
char* getName();
void setName(char *_name);
void setatt(int _att);
void setdef(int _def);
void sethp(int _hp);
void settool(char *_tool);
void setcost(int _cost);
int getatt();
int getdef();
int gethp_plus();
char* gettooltip();
int getcost();
};
class inventory{
private:
item inven[MAX_ITEMS];
int i_top;
public:
inventory(){}
void init();
void add(item _item);
void discard(int index);
item find(int index);
int gettop();
};
class town{
private:
char name[MAX_STRING];
int num;
public:
town(){}
void setInfo(char *_name,int _num);
char* getName();
int getNum();
};
class entity{
private:
char name[MAX_STRING];
int base_hp;
int hp;
int max_hp;
unsigned long xp;
unsigned long next_xp;
int base_att;
int att;
int base_def;
int def;
int townNum;
int level;
int money;
public:
entity(){};
void setInfo(char *_name,int _base_hp,int _hp,int _max_hp,unsigned int _xp,unsigned int _next_xp,int _base_att,int _base_def,int _townNum,int _level,int _money);
void setStat(inventory _inventory);
void sethp(int amount);
void refresh();
char* getName();
int getbase_hp();
int gethp();
int getmax_hp();
unsigned long getxp();
unsigned long getnext_xp();
int getbase_att();
int getatt();
int getbase_def();
int getdef();
int gettownNum();
int getlevel();
int getmoney();
void travel(town dest);
void setmoney(int _cost);
void addxp(unsigned int _xp);
void checkLevel(inventory &inven);
};
#endif _GAME_COMP_H_
2.2. game_comp_entity.cpp ¶
#include "game_comp.h"
#include <string.h>
#include <stdio.h>
void entity::setInfo(char *_name,int _base_hp,int _hp,int _max_hp,unsigned int _xp,unsigned int _next_xp,int _base_att,int _base_def,int _townNum,int _level,int _money){
strcpy(name,_name);
base_hp=_base_hp;
hp=_hp;
max_hp=_max_hp;
xp=_xp;
next_xp=_next_xp;
base_att=_base_att;
base_def=_base_def;
townNum=_townNum;
level=_level;
money=_money;
}
void entity::setStat(inventory _inventory){
int top=_inventory.gettop();
item tmp;
max_hp=base_hp;
att=base_att;
def=base_def;
for(int i=0;i<=top;i++){
tmp=_inventory.find(i);
max_hp+=tmp.gethp_plus();
att+=tmp.getatt();
def+=tmp.getdef();
}
}
int entity::getatt(){
return att;
}
int entity::getdef(){
return def;
}
char* entity::getName(){
return name;
}
int entity::getbase_hp(){
return base_hp;
}
int entity::gethp(){
return hp;
}
int entity::getmax_hp(){
return max_hp;
}
int entity::getbase_att(){
return base_att;
}
int entity::getbase_def(){
return base_def;
}
int entity::gettownNum(){
return townNum;
}
int entity::getlevel(){
return level;
}
int entity::getmoney(){
return money;
}
unsigned long entity::getxp(){
return xp;
}
unsigned long entity::getnext_xp(){
return next_xp;
}
void entity::travel(town dest){
townNum=dest.getNum();
}
void entity::refresh(){
hp=max_hp;
}
void entity::sethp(int amount){
if(hp+amount<=0)
hp=0;
else if(hp+amount<=max_hp)
hp+=amount;
else
hp=max_hp;
}
void entity::setmoney(int _cost){
money-=_cost;
}
void entity::addxp(unsigned int _xp){
xp+=_xp;
}
void entity::checkLevel(inventory &inven){
if(xp>=next_xp){
level++;
next_xp=xp*2;
base_hp+=level*10;
base_att+=level*2;
base_def+=level;
setStat(inven);
printf("레벨업!\n현재 레벨: %d\t다음 레벨까지 남은 경험치: %d\n체력: %d\t공격력: %d\t방어력: %d",level,next_xp,max_hp,att,def);
}
setStat(inven);
}
2.3. game_comp_inven.cpp ¶
#include "game_comp.h"
void inventory::init(){
i_top=-1;
}
void inventory::add(item _item){
if(i_top<MAX_ITEMS-1)
inven[++i_top]=_item;
}
void inventory::discard(int index){
for(int i=index;i<i_top;i++)
inven[i]=inven[i+1];
i_top--;
}
item inventory::find(int index){
return inven[index];
}
int inventory::gettop(){
return i_top;
}
2.4. game_comp_item.cpp ¶
#include "game_comp.h"
#include <string.h>
void item::setInfo(char *_name,int _att,int _def,int _hp_plus,char* _tooltip,int _cost){
strcpy(name,_name);
strcpy(tooltip,_tooltip);
att=_att;
def=_def;
hp_plus=_hp_plus;
cost=_cost;
}
char* item::getName(){
return name;
}
int item::getatt(){
return att;
}
int item::getdef(){
return def;
}
int item::gethp_plus(){
return hp_plus;
}
char* item::gettooltip(){
return tooltip;
}
int item::getcost(){
return cost;
}
void item::setName(char *_name){
strcpy(name,_name);
}
void item::setatt(int _att){
att=_att;
}
void item::setdef(int _def){
def=_def;
}
void item::sethp(int _hp){
hp_plus=_hp;
}
void item::settool(char *_tool){
strcpy(tooltip,_tool);
}
void item::setcost(int _cost){
cost=_cost;
}
2.5. game_comp_town.h ¶
#include "game_comp.h"
#include <string.h>
void town::setInfo(char *_name,int _num){
strcpy(name,_name);
num=_num;
}
char* town::getName(){
return name;
}
int town::getNum(){
return num;
}
2.6. game_file.h ¶
#ifndef _GAME_FILE_H_
#define _GAME_FILE_H_
#include <stdio.h>
#include "game_comp.h"
class fileManager{
private:
FILE *file;
public:
fileManager(){};
bool loadGame(char *FILENAME,entity &PLAYER,inventory &inven);
bool saveGame(char *FILENAME,entity &PLAYER,inventory &inven);
};
#endif _GAME_FILE_H_
2.7. game_file.cpp ¶
#include "game_file.h"
#include <string.h>
bool fileManager::loadGame(char *FILENAME,entity &PLAYER,inventory &inven){
inven.init();
file=fopen(FILENAME,"r");
if(file==NULL)
return false;
printf("불러오는중...\n");
char buff[MAX_STRING];
int basehp,hp,baseatt,basedef,townnum,inum,level,money,att,def,hpplus;
unsigned int xp,nextxp;
char name[MAX_STRING];
item itmp;
while(strcmp(buff,"EOF")!=0){
fscanf(file,"%s",buff);
if(strcmp(buff,"name:")==0){
char tmp;
int i=0;
fscanf(file,"%c",&tmp);
do{
fscanf(file,"%c",&tmp);
name[i++]=tmp;
}while(tmp!='\n');
name[i-1]='\0';
}
else if(strcmp(buff,"level:")==0)
fscanf(file,"%d",&level);
else if(strcmp(buff,"base_hp:")==0)
fscanf(file,"%d",&basehp);
else if(strcmp(buff,"hp:")==0)
fscanf(file,"%d",&hp);
else if(strcmp(buff,"base_att:")==0)
fscanf(file,"%d",&baseatt);
else if(strcmp(buff,"base_def:")==0)
fscanf(file,"%d",&basedef);
else if(strcmp(buff,"townNum:")==0)
fscanf(file,"%d",&townnum);
else if(strcmp(buff,"xp:")==0)
fscanf(file,"%lu",&xp);
else if(strcmp(buff,"next_xp:")==0)
fscanf(file,"%lu",&nextxp);
else if(strcmp(buff,"money:")==0)
fscanf(file,"%d",&money);
else if(strcmp(buff,"inven:")==0){
fscanf(file,"%d",&inum);
for(int j=0;j<=inum;j++){
do{
fscanf(file,"%s",buff);
if(strcmp(buff,"iname:")==0){
char tmp;
int i=0;
char tmpName[MAX_STRING];
fscanf(file,"%c",&tmp);
do{
fscanf(file,"%c",&tmp);
tmpName[i++]=tmp;
}while(tmp!='\n');
tmpName[i-1]='\0';
itmp.setName(tmpName);
}
else if(strcmp(buff,"att:")==0){
fscanf(file,"%d",&att);
itmp.setatt(att);
}
else if(strcmp(buff,"def:")==0){
fscanf(file,"%d",&def);
itmp.setdef(def);
}
else if(strcmp(buff,"hp_plus:")==0){
fscanf(file,"%d",&hpplus);
itmp.sethp(hpplus);
}
else if(strcmp(buff,"tooltip:")==0){
char tmp;
int i=0;
char tmpName[MAX_STRING];
fscanf(file,"%c",&tmp);
do{
fscanf(file,"%c",&tmp);
tmpName[i++]=tmp;
}while(tmp!='\n');
tmpName[i-1]='\0';
itmp.settool(tmpName);
}
}while(strcmp(buff,"END")!=0);
itmp.setcost(0);
inven.add(itmp);
}
}
}
PLAYER.setInfo(name,basehp,hp,0,xp,nextxp,baseatt,basedef,townnum,level,money);
PLAYER.setStat(inven);
printf("불러오기 완료!\n");
fflush(stdin);
getchar();
return true;
}
bool fileManager::saveGame(char *FILENAME,entity &PLAYER,inventory &inven){
file=fopen(FILENAME,"w+");
printf("저장중...\n");
fprintf(file,"name: %s\n",PLAYER.getName());
fprintf(file,"level: %d\n",PLAYER.getlevel());
fprintf(file,"base_hp: %d\n",PLAYER.getbase_hp());
fprintf(file,"hp: %d\n",PLAYER.gethp());
fprintf(file,"base_att: %d\n",PLAYER.getbase_att());
fprintf(file,"base_def: %d\n",PLAYER.getbase_def());
fprintf(file,"townNum: %d\n",PLAYER.gettownNum());
fprintf(file,"xp: %lu\n",PLAYER.getxp());
fprintf(file,"next_xp: %lu\n",PLAYER.getnext_xp());
fprintf(file,"money: %d\n",PLAYER.getmoney());
fprintf(file,"inven: %d\n",inven.gettop());
for(int i=0;i<=inven.gettop();i++){
item tmp=inven.find(i);
fprintf(file,"iname: %s\n",tmp.getName());
fprintf(file,"att: %d\n",tmp.getatt());
fprintf(file,"def: %d\n",tmp.getdef());
fprintf(file,"hp_plus: %d\n",tmp.gethp_plus());
fprintf(file,"tooltip: %s\n",tmp.gettooltip());
fprintf(file,"END\n");
}
fprintf(file,"EOF");
fclose(file);
printf("저장 완료!\n");
fflush(stdin);
getchar();
return true;
}
2.8. game.cpp ¶
#include "game_comp.h"
#include "game_file.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <io.h>
#include <math.h>
#define MAX_TOWN 8
#define MAX_ENEMY 8
#define MAX_STORAGE 3
#define MAX_COLLEN 4
#define MAX_LEVEL 30
#define FILE_NAME "csave.dat"
entity PLAYER;
inventory INVENTORY;
town TOWN[MAX_TOWN];
entity ENEMY[MAX_ENEMY];
entity COLLOSEUM[MAX_TOWN][MAX_COLLEN];
item storage[MAX_STORAGE];
fileManager FILEMGR;
bool gameover=false;
void init(bool first);
void store();
void travel(town dest,int distance);
void setTravelDest();
void battle(entity &enemy);
void rest();
void viewItems();
void setStat();
void start(bool first);
void buyItem(item _item,int index);
void colloseum(entity *colloseum);
int main(void){
char buff;
while(true){
printf("<<중대생 rpg ver1.1.0 made by 신기호>>\n");
printf("1.새로하기\n2.이어하기\n3.패치노트\n4.종료\n");
scanf("%c",&buff);
switch(buff){
case '1':
system("cls");
init(true);
start(true);
break;
case '2':
system("cls");
if(FILEMGR.loadGame(FILE_NAME,PLAYER,INVENTORY)){
init(false);
start(false);
}
else{
init(true);
start(true);
}
break;
case '3':
system("cls");
printf("CAU RPG ver 1.1.0 Patch notes(What's new)\n");
printf("------------------------------------------\n");
printf("1.전투중 방어를 하게 되면 데미지를 입은 후 자신의 최대체력의 10%%만큼 회복을 하게 됩니다.\n");
printf("2.각 마을에 콜로세움이 생겼습니다! 더 강력한 적에게 도전하세요.\n");
printf("3.새로운 마을이 생겼습니다. 현재 총 마을의 개수는 8개 입니다.\n");
fflush(stdin);
getchar();
break;
case '4':
return 0;
}
system("cls");
}
return 0;
}
void init(bool first){
gameover=false;
TOWN[0].setInfo("208관",0);
TOWN[1].setInfo("봅스트홀",1);
TOWN[2].setInfo("R&D센터",2);
TOWN[3].setInfo("흑석역",3);
TOWN[4].setInfo("청룡탕",4);
TOWN[5].setInfo("대운동장",5);
TOWN[6].setInfo("학생회실",6);
TOWN[7].setInfo("캡스톤 연구실",7);
if(first){
INVENTORY.init();
item tmp=item();
tmp.setInfo("볼 마우스",1,0,0,"구시대적인 마우스다.",0);
INVENTORY.add(tmp);
PLAYER.setInfo("",30,30,30,0,30,1,1,0,1,0);
PLAYER.setStat(INVENTORY);
}
ENEMY[0].setInfo("과제",15,15,15,10,0,3,0,0,1,15);
ENEMY[1].setInfo("씨드",50,50,50,20,0,10,8,1,3,35);
ENEMY[2].setInfo("쌍권총",130,130,130,30,0,40,18,2,5,46);
ENEMY[3].setInfo("드랍",350,350,350,64,0,68,37,3,10,58);
ENEMY[4].setInfo("청룡",3200,3200,3200,120,0,430,357,4,15,70);
ENEMY[5].setInfo("컴공깃발",430,430,430,80,0,124,43,5,13,102);
ENEMY[6].setInfo("과제에 절망한 학생회",530,530,530,134,0,245,150,6,17,130);
ENEMY[7].setInfo("분노한 새싹강사",340,340,340,165,0,563,230,7,20,160);
COLLOSEUM[0][0].setInfo("선대과제",200,200,200,60,0,50,34,0,7,70);
COLLOSEUM[0][1].setInfo("고장난NXT",450,450,450,80,0,87,56,0,10,95);
COLLOSEUM[0][2].setInfo("빨간모자",640,640,640,110,0,95,104,0,12,134);
COLLOSEUM[0][3].setInfo("말 안듣는 NXT",1000,1000,1000,106,0,130,56,0,15,185);
COLLOSEUM[1][0].setInfo("블루스크린",430,430,430,75,0,84,96,0,8,96);
COLLOSEUM[1][1].setInfo("무한재부팅",360,360,360,96,0,120,87,0,10,143);
COLLOSEUM[1][2].setInfo("Olleh 3G",140,140,140,132,0,204,108,0,14,235);
COLLOSEUM[1][3].setInfo("쳥룡의 붓",1030,1030,1030,165,0,342,105,0,20,260);
COLLOSEUM[2][0].setInfo("자벌레",530,530,530,85,0,103,178,0,16,113);
COLLOSEUM[2][1].setInfo("공수퀴즈",2054,2054,2054,150,0,260,234,0,21,176);
COLLOSEUM[2][2].setInfo("과제에 분노한 학생회",1043,1043,1043,160,0,203,549,0,24,200);
COLLOSEUM[2][3].setInfo("청룡의 지구본",3400,3400,3400,241,0,540,426,0,28,243);
COLLOSEUM[3][0].setInfo("끈질긴 선대과제",400,400,400,120,0,100,68,0,15,140);
COLLOSEUM[3][1].setInfo("돌아온 고장난NXT",900,900,900,160,0,174,112,0,16,190);
COLLOSEUM[3][2].setInfo("돌아온 빨간모자",1280,1280,1280,220,0,190,208,0,23,268);
COLLOSEUM[3][3].setInfo("분노의 말 안듣는 NXT",2000,2000,2000,212,0,260,112,0,26,370);
COLLOSEUM[4][0].setInfo("새파란 블루스크린",860,860,860,150,0,168,192,0,17,192);
COLLOSEUM[4][1].setInfo("영원의 무한재부팅",720,720,720,192,0,240,174,0,20,286);
COLLOSEUM[4][2].setInfo("찍찍의 Olleh 3G",280,280,280,264,0,408,216,0,18,470);
COLLOSEUM[4][3].setInfo("철갑의 쳥룡의 붓",2060,2060,2060,330,0,684,210,0,30,520);
COLLOSEUM[5][0].setInfo("혁명의 자벌레",1060,1060,1060,170,0,206,256,0,30,226);
COLLOSEUM[5][1].setInfo("파멸의 공수퀴즈",4108,4108,4108,300,0,520,468,0,30,352);
COLLOSEUM[5][2].setInfo("복수의 과제에 분노한 학생회",2086,2086,2086,320,0,406,1098,0,30,400);
COLLOSEUM[5][3].setInfo("이무기의 청룡의 여의주",5400,5400,5400,406,0,860,652,0,30,526);
COLLOSEUM[6][0].setInfo("폭발의 무한과제",2120,2120,2120,340,0,500,430,0,30,512);
COLLOSEUM[6][1].setInfo("매우 단단한 NXT",4300,4300,4300,300,0,480,880,0,30,540);
COLLOSEUM[6][2].setInfo("숨어있던 게이",6400,6400,6400,430,0,1800,598,0,30,612);
COLLOSEUM[6][3].setInfo("불타오르는 중도의 시계탑의 시계의 초침",4600,4600,4600,506,0,430,640,0,30,622);
COLLOSEUM[7][0].setInfo("전설의 청룡의 붓",7400,7400,7400,600,0,1430,860,0,30,0);
COLLOSEUM[7][1].setInfo("전설의 청룡의 여의주",9700,9700,9700,600,0,1650,1300,0,30,0);
COLLOSEUM[7][2].setInfo("전설의 청룡의 지구본",13000,13000,13000,600,0,2400,1650,0,30,0);
COLLOSEUM[7][3].setInfo("전설의 청룡 완전체",53200,53200,53200,600,0,6450,4300,0,30,0);
}
void start(bool first){
char buff;
if(first){
char name[MAX_STRING];
printf("이름을 입력하세요: ");
scanf("%s",name);
PLAYER.setInfo(name,30,30,30,0,30,1,1,0,1,0);
}
PLAYER.setStat(INVENTORY);
while(true){
if(gameover)
break;
system("cls");
printf("당신은 %s에 있습니다.\n무엇을 하시겠습니까?\n",TOWN[PLAYER.gettownNum()].getName());
printf("1.아이템을 산다\n2.쉰다\n3.보유 아이템 확인\n4.다른 마을로 이동한다\n5.콜로세움 입장\n6.저장\n7.불러오기\n8.종료\n");
scanf("%c",&buff);
switch(buff){
case '1':
system("cls");
store();
break;
case '2':
system("cls");
rest();
break;
case '3':
system("cls");
viewItems();
break;
case '4':
system("cls");
setTravelDest();
break;
case '5':
system("cls");
colloseum(COLLOSEUM[PLAYER.gettownNum()]);
break;
case '6':
system("cls");
FILEMGR.saveGame(FILE_NAME,PLAYER,INVENTORY);
break;
case '7':
system("cls");
FILEMGR.loadGame(FILE_NAME,PLAYER,INVENTORY);
break;
case '8':
system("cls");
gameover=true;
break;
}
}
return;
}
void rest(){
printf("충분한 휴식을 취했습니다.\n");
PLAYER.refresh();
fflush(stdin);
getchar();
}
void store(){
float num;
bool exit=false;
srand((unsigned)time(NULL));
num=(rand()%10+1)/10+rand()%2;
if(num<=1.2&&num>0.6)
storage[0].setInfo("혁명의 구슬(오브)",6,2,4,"기분이 상쾌해진다.",1300);
else if(num<=1.6&&num>1.2)
storage[0].setInfo("교수님의 노트(부적[완])",10,4,20,"지식이 깊어진다.",2400);
else if(num<=1.8&&num>1.6)
storage[0].setInfo("절대 마우스(유니크)",100,100,200,"모든것을 지배하는 하나의 마우스.",13500);
else
storage[0].setInfo("희믜한 혁명의 기운(구슬)",2,1,0,"용기가 약간 생긴다.",200);
storage[1].setInfo("컴공 과잠(방어구)",0,2,5,"40주년 기념 과잠.",320);
storage[2].setInfo("교수님의 노트 조각(부적[일부])",3,0,0,"교수님의 노트 중 일부.",350);
while(true){
if(exit)
break;
printf("보유하고 있는 돈: %d원\n",PLAYER.getmoney());
for(int i=0;i<3;i++){
printf("%d: %s\t--가격: %d 원\n",i+1,storage[i].getName(),storage[i].getcost());
}
printf("무엇을 하시겠습니까?\n1.산다\n2.편의점을 나간다\n");
scanf("%f",&num);
switch((int)num){
case 1:
int num2;
printf("무엇을 사시겠습니까?: ");
scanf("%d",&num2);
buyItem(storage[num2-1],num2-1);
system("cls");
break;
case 2:
exit=true;
break;
}
}
}
void buyItem(item _item,int index){
if(PLAYER.getmoney()<_item.getcost()){
printf("돈이 부족합니다.\n");
fflush(stdin);
getchar();
return;
}
if(INVENTORY.gettop()<=MAX_ITEMS-1){
printf("점원: 감사합니다!\n");
PLAYER.setmoney(_item.getcost());
printf("당신은 %s을(를) 구입했습니다.\n",_item.getName());
INVENTORY.add(_item);
PLAYER.setStat(INVENTORY);
fflush(stdin);
getchar();
return;
}
else{
printf("더 이상 아이템을 가질 수 없습니다.");
fflush(stdin);
getchar();
return;
}
}
void viewItems(){
char buff;
bool flag=false;
while(true){
if(flag)
break;
system("cls");
fflush(stdin);
int att_plus=0,def_plus=0;
for(int i=0;i<=INVENTORY.gettop();i++){
att_plus+=INVENTORY.find(i).getatt();
def_plus+=INVENTORY.find(i).getdef();
}
printf("--%s 상태--\n레벨:%d\n경험치:%lu\n다음 레벨까지:%lu\n공격력:%d + %d\n방어력:%d + %d\n체력:%d / %d\n",PLAYER.getName(),
PLAYER.getlevel(),PLAYER.getxp(),PLAYER.getnext_xp(),PLAYER.getbase_att(),att_plus,PLAYER.getbase_def(),def_plus,
PLAYER.gethp(),PLAYER.getmax_hp());
printf("인벤토리:\n");
for(int i=0;i<=INVENTORY.gettop();i++){
item tmp=item();
tmp=INVENTORY.find(i);
printf("%d: %s\n",i+1,tmp.getName());
if(i>=5){
printf("...more...\n");
break;
}
}
printf("------------------\n");
printf("무엇을 하시겠습니까?\n1.인벤토리 관리\n2.나간다\n");
scanf("%c",&buff);
switch(buff){
case '1':
system("cls");
for(int i=0;i<=INVENTORY.gettop();i++){
item tmp=item();
tmp=INVENTORY.find(i);
printf("%d: %s\n",i+1,tmp.getName());
}
int num;
printf("선택: ");
scanf("%d",&num);
if(num>=1&&num<=INVENTORY.gettop()+1){
bool flag2=false;
while(true){
if(flag2)
break;
int num2;
item tmp=item();
tmp=INVENTORY.find(num-1);
printf("<%s>\n옵션:\n1.살펴보기\n2.버리기\n3.취소\n",tmp.getName());
scanf("%d",&num2);
switch(num2){
case 1:
printf("%s\n",tmp.gettooltip());
printf("공격력 보너스: %d\n방어력 보너스: %d\n체력 보너스: %d\n",tmp.getatt(),tmp.getdef(),tmp.gethp_plus());
flag2=true;
fflush(stdin);
getchar();
system("cls");
break;
case 2:
printf("아이템을 버렸습니다.\n");
INVENTORY.discard(num-1);
flag2=true;
system("cls");
break;
case 3:
flag2=true;
system("cls");
break;
}
}
}
break;
case '2':
flag=true;
break;
}
}
}
void setTravelDest(){
bool exit=false;
int distance;
printf("어디로 가시겠습니까?(거리에 따라 전투의 발생 횟수가 변할 수 있습니다.)\n");
for(int i=0;i<MAX_TOWN;i++){
if(i!=PLAYER.gettownNum()){
distance=i-PLAYER.gettownNum();
printf("%s: 거리 %d\n",TOWN[i].getName(),abs(distance));
}
}
printf("----------------------------\n");
int count=0;
int T_ptr[MAX_TOWN-1];
for(int i=0;i<MAX_TOWN;i++){
if(i!=PLAYER.gettownNum()){
printf("%d, %s\n",count+1,TOWN[i].getName());
T_ptr[count++]=i;
}
}
while(true){
int dest;
if(exit)
break;
fflush(stdin);
printf("선택: ");
scanf("%d",&dest);
if(dest>=1&&dest<=MAX_TOWN){
travel(TOWN[T_ptr[dest-1]],abs(PLAYER.gettownNum()-T_ptr[dest-1]));
exit=true;
}
}
}
void travel(town dest,int distance){
if(distance<0){
for(int i=0;i<-distance;i++){
srand((unsigned)time(NULL));
int num=rand()%10+1;
if(num<=6){
entity tmpEn=ENEMY[PLAYER.gettownNum()];
battle(tmpEn);
}
if(gameover)
return;
}
PLAYER.travel(dest);
}
else{
for(int i=0;i<distance;i++){
srand((unsigned)time(NULL));
int num=rand()%10+1;
if(num<=6){
entity tmpEn=ENEMY[PLAYER.gettownNum()];
battle(tmpEn);
}
if(gameover)
return;
}
PLAYER.travel(dest);
}
}
void colloseum(entity *colloseum){
bool exit=false;
printf("콜로세움에 오신것을 환영합니다!\n");
fflush(stdin);
getchar();
while(!exit&&!gameover){
system("cls");
char buff;
printf("----콜로세움 상대----\n");
for(int i=0;i<MAX_COLLEN;i++){
printf("%d: %s --- Lv.%d\n",i+1,colloseum[i].getName(),colloseum[i].getlevel());
}
printf("1.상대 결정\n2.나가기\n");
scanf("%c",&buff);
switch(buff){
case '1':
int num;
printf("상대를 결정하세요: ");
scanf("%d",&num);
if(num>=1&&num<=MAX_COLLEN){
fflush(stdin);
printf("결투를 시작합니다!\n");
getchar();
entity tmpEn=colloseum[num-1];
battle(tmpEn);
}
break;
case '2':
exit=true;
break;
}
}
}
void battle(entity &enemy){
char buff;
int en;
bool end=false;
system("cls");
printf("%s이(가) 싸우고 싶어합니다!!\n",enemy.getName());
fflush(stdin);
getchar();
while(true){
if(end)
break;
fflush(stdin);
system("cls");
printf("플레이어:%s Lv.%d ---\n체력: %d / %d\n적:%s Lv.%d ---\n체력: %d / %d\n",PLAYER.getName(),PLAYER.getlevel(),
PLAYER.gethp(),PLAYER.getmax_hp(),enemy.getName(),enemy.getlevel(),enemy.gethp(),enemy.getmax_hp());
if(enemy.gethp()<=0){
printf("승리!\n");
printf("보상:\n");
srand((unsigned)time(NULL));
int money;
unsigned long xp;
money=enemy.getmoney();
xp=enemy.getxp();
printf("1.돈: %d 원\n",money);
printf("2.경험치: %lu\n",xp);
PLAYER.setmoney(-money);
if(PLAYER.getlevel()<MAX_LEVEL)
PLAYER.addxp(xp);
PLAYER.checkLevel(INVENTORY);
fflush(stdin);
getchar();
end=true;
continue;
}
else if(PLAYER.gethp()<=0){
printf("패배했습니다.\n");
fflush(stdin);
getchar();
gameover=true;
end=true;
continue;
}
else{
printf("1.공격\n2.방어\n3.도망\n");
scanf("%c",&buff);
switch(buff){
case '1':
srand((unsigned)time(NULL));
en=rand()%10;
printf("%s을(를) 공격했다!\n",enemy.getName());
fflush(stdin);
getchar();
if(en<=5){
enemy.sethp(-PLAYER.getatt());
printf("적 %s이(가) 공격했다!\n",enemy.getName());
fflush(stdin);
getchar();
PLAYER.sethp(-enemy.getbase_att());
}
else{
if(enemy.getbase_def()-PLAYER.getatt()>0)
enemy.sethp(-1);
else
enemy.sethp(-(PLAYER.getatt()-enemy.getbase_def())+(int)(enemy.getmax_hp()*0.1));
printf("적 %s이(가) 자신을 방어했다.\n",enemy.getName());
fflush(stdin);
getchar();
}
break;
case '2':
srand((unsigned)time(NULL));
en=rand()%10;
printf("방어했습니다.\n");
fflush(stdin);
getchar();
if(en<=5){
printf("적 %s이(가) 공격했다!\n",enemy.getName());
fflush(stdin);
getchar();
if(PLAYER.getdef()-enemy.getbase_att()>0)
PLAYER.sethp(-1);
else
PLAYER.sethp(-(enemy.getbase_att()-PLAYER.getdef())+(int)(PLAYER.getmax_hp()*0.1));
}
else{
printf("적 %s이(가) 자신을 방어했다.\n",enemy.getName());
fflush(stdin);
getchar();
}
break;
case '3':
srand((unsigned)time(NULL));
int flee=rand()%10;
if(flee>=6){
printf("당신은 전투에서 도망쳤습니다.\n");
fflush(stdin);
getchar();
end=true;
continue;
}
else{
printf("당신은 도망칠 수 없었습니다.\n");
fflush(stdin);
getchar();
break;
}
}
}
}
}
- 다음 버전에서는 몬스터 등을 아얘 따로 저장하는 파일을 만들어서 그걸 읽어들여서 몹들을 생성하게 해야겠습니다. 일일이 메인 cpp에서 만들려고 하니 한없이 코드 줄만 길어지네요. 그리고 프로그래밍 공부를 좀 더 해야겠다는 생각이 들었습니다 ㅋㅋ 분명히 저기서 제가 삽질을 한 부분이 있을거에요 ㅠㅠ 이제 버전 1.2에선 소켓프로그래밍을 이용해서 네트워크 대전을 넣을 예정입니다.- 신기호
- 초반에 드랍한테 잡혔더니 도망치기가 매번 실패해서 나보다 센 몹한테 잡히면 도망 못치나보다 했는데 코드 읽어보니 그냥 50%네... 근데 난 왜 도망을 못쳤지ㅠㅠㅠㅠㅠㅠ - 김수경










