⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cgame.cpp

📁 一款c++ 文字MUD游戏 比较适合新手学习
💻 CPP
字号:
#include "iostream"
using namespace std;
#include "stdio.h"
#include "MAP.h"
#include "TEXT.h"
#include "ATTACK.h"

//对象的声明
Fight fight;
CFile cf;
map gamemap;
MY_HERO myhero;
NPC npc;
bool m=false;
bool m1=false;


//物品结构
struct beef
{
	char name[10];
	int num;
	int buHPnum;
}niu;
struct water
{
	char name[10];
	int num;
	int buMPnum;
}shui;


void  InitFOOD()
{
	strcpy(niu.name,"超级金疮药");
	niu.buHPnum = 20;
	niu.num = 999;
	strcpy(shui.name, "超级魔法药");
	shui.buMPnum = 20;
	shui.num = 999;
}

void use()
{

	cout<<"你想做什么?"<<endl;
	cout<<"1 服用超级金疮药 补血100点\t 2 服用超级魔法药 补蓝100点\t 3 什么都不做"<<endl;
	char c = '0';
	cin>>c;
	switch(c)
	{
	case '1':
		--niu.num;
		if (niu.num>0)
		{
			cout<<"已回血100点"<<endl;
			myhero.player1.hero_hp+=100;
			if (myhero.player1.hero_hp>200)
			{
				myhero.player1.hero_hp=200;

			}
			/*if (myhero.player1.hero_hp>100)
			{
			myhero.player1.hero_hp = 100;
			}   */
		}
		else
		{
			niu.num = 0;
			cout<<"已经没有东西可以使用了!"<<endl;
		}
		use();
		break;
	case '2':
		--shui.num;
		if (shui.num>0)
		{
			cout<<"已经回蓝20点"<<endl;
			myhero.player1.hero_mp+=20;
			if (myhero.player1.hero_mp>100)
			{
				myhero.player1.hero_mp = 100;
			}
		}
		else
		{
			shui.num = 0;
			cout<<"已经没有东西可以喝了"<<endl;
		}
		use();
		break;
	case '3':
		cout<<"回到旅行途中"<<endl;
		break;
	}
}
void shop()
{
	cout<<"欢迎来到武器店,作为礼物送你一把武器,请慎重挑选"<<endl;
	cout<<"  1 谷玉权杖   2 嗜魂法杖  "<<endl;

	char d='0';
	cin>>d;
	switch(d) {
case '1' :
	cout<<"你获得了一把谷玉权杖 "<<endl;
	m=true;
	m1=false;
	myhero.player1.hero_at+=50;
	myhero.player1.hero_hp+=100;
	break;
case '2':
	cout<<"你获得了一把嗜魂法杖"<<endl;
	m1=true;
	m=false;
	myhero.player1.hero_at+=25;
	myhero.player1.hero_hp+=200;
	}
}

void item()
{
	if (m==true)
	{
		cout<<"武器 谷玉权杖  攻击力+20   生命值+100"<<endl;

	}
	if (m1==true)
	{
		cout<<"武器 嗜魂法杖  攻击力+55   生命值+200 "<<endl;
	}
	if (m==false&&m1==false)
	{
		cout<<"您现在没有任何装备"<<endl;


	}


}
void take ()
{
	cout<<"你获得了超级金疮药和超级魔法药";
	niu.num+=100;
	shui.num+=100;
}

void menu()
{
	//printf("%c %c %c %c %c %c",1,2,3,4,5,6);return;
	printf("-----------------------------\n");
	printf("|        游戏主菜单         | \n");
	printf("-----------------------------\n");
	printf("|    E键       使用物品     |\n");
	printf("|    B键       查看装备     |\n");
	printf("|    V键       拾取物品     |\n");
	printf("|    W键       向上走       |\n");
	printf("|    S键       向下走       |\n");
	printf("|    A键       向左走       |\n");
	printf("|    D键       向右走       |\n");
	printf("|    6键       英雄状态     |\n");
	printf("|    7键       退出游戏     |\n");
	printf("-----------------------------\n");
	printf("|请输	入要进行的操作,回车确认|\n");
	printf("-----------------------------\n");
	char in;
	while (1)
	{
		switch(getchar(in))
		{/*add*/
		case 'm':
			gamemap.printmap(gamemap.mapMax);
			menu();
			break;
		case 'e':
			InitFOOD();
			use();
			break;
		case 'b':
			item();
			break;
		case 'w':
			cout<<"向上走了一步"<<endl;
			myhero.hero_y--;
			if (gamemap.mapMax[myhero.hero_y][myhero.hero_x] == 5)
			{
				myhero.hero_y++;
			}
			gamemap.Initmap();
			if (myhero.hero_y<0)
			{
				myhero.hero_y = 0;
				gamemap.move(0,myhero.hero_x);
				printf("您已经走到尽头了,再往前走就和墙KISS了!\n");
			}
			else
			{
				gamemap.move(myhero.hero_y,myhero.hero_x);
			}
			gamemap.printmap(gamemap.mapMax);
			if ((myhero.hero_x == 1 && myhero.hero_y == 1) 
				||(myhero.hero_x == 1 && myhero.hero_y == 3)
				||(myhero.hero_x == 3 && myhero.hero_y == 5)
				||(myhero.hero_x == 11 && myhero.hero_y == 6))
			{
				fight.playerattack(myhero,npc);
			}
			if (myhero.hero_x==6&&myhero.hero_y==4)
			{
				shop();
			}
			if (myhero.hero_x==2&&myhero.hero_y==8)
			{
				cout<<"城主:我的英雄终于等到你的到来了"<<endl;
				cout<<"侠:现在情况怎么样了?"<<endl;
				cout<<"城主:强大的怪物已经开始攻打城墙了,不知道我们还能坚持多久。"<<endl;
				cout<<"侠:这里就交给我了,你带领其他人先撤退吧。"<<endl;

			}
			menu();
			break;
		case 's':
			cout<<"向下走了一步"<<endl;
			myhero.hero_y++;
			if (gamemap.mapMax[myhero.hero_y][myhero.hero_x] == 5)
			{
				myhero.hero_y--;
			}
			gamemap.Initmap();
			if (myhero.hero_y>9)
			{
				myhero.hero_y = 9;
				gamemap.move(9,myhero.hero_x);
				printf("您已经走到尽头了,再往前走就和墙KISS了!\n");
			}
			else
			{
				gamemap.move(myhero.hero_y,myhero.hero_x);
			}
			gamemap.printmap(gamemap.mapMax);
			if ((myhero.hero_x == 1 && myhero.hero_y == 1) 
				||(myhero.hero_x == 1&& myhero.hero_y == 3)
				||(myhero.hero_x == 3 && myhero.hero_y == 5)
				||(myhero.hero_x == 11 && myhero.hero_y == 6))
			{
				fight.playerattack(myhero,npc);
			}
			if (myhero.hero_x==6&&myhero.hero_y==4)
			{
				shop();
			}

			if (myhero.hero_x==2&&myhero.hero_y==8)
			{
				cout<<"城主:我的英雄终于等到你的到来了"<<endl;
				cout<<"侠:现在情况怎么样了?"<<endl;
				cout<<"城主:强大的怪物已经开始攻打城墙了,不知道我们还能坚持多久。"<<endl;
				cout<<"侠:这里就交给我了,你带领其他人先撤退吧。"<<endl;

			}
			menu();
			break;
		case 'a':
			cout<<"向左走了一步"<<endl;
			myhero.hero_x--;
			if (gamemap.mapMax[myhero.hero_y][myhero.hero_x] == 5)
			{
				myhero.hero_x++;
			}
			gamemap.Initmap();
			if (myhero.hero_x<0)
			{
				myhero.hero_x = 0;
				gamemap.move(myhero.hero_y,0);
				printf("您已经走到尽头了,再往前走就和墙KISS了!\n");
			}
			else
			{
				gamemap.move(myhero.hero_y,myhero.hero_x);
			}
			gamemap.printmap(gamemap.mapMax);
			if ((myhero.hero_x == 1 && myhero.hero_y == 1) 
				||(myhero.hero_x == 1 && myhero.hero_y == 3)
				||(myhero.hero_x == 3 && myhero.hero_y == 5)
				||(myhero.hero_x == 11 && myhero.hero_y == 6))
			{
				fight.playerattack(myhero,npc);
			}
			if (myhero.hero_x==6&&myhero.hero_y==4)
			{
				shop();
			}
			if (myhero.hero_x==2&&myhero.hero_y==8)
			{
				cout<<"城主:我的英雄终于等到你的到来了"<<endl;
				cout<<"侠:现在情况怎么样了?"<<endl;
				cout<<"城主:强大的怪物已经开始攻打城墙了,不知道我们还能坚持多久。"<<endl;
				cout<<"侠:这里就交给我了,你带领其他人先撤退吧。"<<endl;

			}
			menu();
			break;
		case 'd':
			cout<<"向右走了一步"<<endl;
			myhero.hero_x++;
			if (gamemap.mapMax[myhero.hero_y][myhero.hero_x] == 5)
			{
				myhero.hero_x--;
			}
			gamemap.Initmap();
			if (myhero.hero_x>13)
			{
				myhero.hero_x = 13;
				gamemap.move(myhero.hero_y,13);
				printf("您已经走到尽头了,再往前走就和墙KISS了!\n");
			}
			else
			{
				gamemap.move(myhero.hero_y,myhero.hero_x);
			}
			gamemap.printmap(gamemap.mapMax);
			if ((myhero.hero_x == 1 && myhero.hero_y == 1) 
				||(myhero.hero_x == 1 && myhero.hero_y == 3)
				||(myhero.hero_x == 3 && myhero.hero_y == 5)
				||(myhero.hero_x == 11 && myhero.hero_y == 6))
			{
				fight.playerattack(myhero,npc);
			}
			if (myhero.hero_x==6&&myhero.hero_y==4)

			{
				shop();
			}
			if (myhero.hero_x==2&&myhero.hero_y==8)
			{
				cout<<"城主:我的英雄终于等到你的到来了"<<endl;
				cout<<"侠:现在情况怎么样了?"<<endl;
				cout<<"城主:强大的怪物已经开始攻打城墙了,不知道我们还能坚持多久。"<<endl;
				cout<<"侠:这里就交给我了,你带领其他人先撤退吧。"<<endl;
			}
			menu();
			break;
		case '6':
			cout<<"生命值\t"<<myhero.player1.hero_hp<<endl<<"等级\t"<<myhero.player1.hero_lev<<endl
				<<"攻击力\t"<<myhero.player1.hero_at<<endl<<"魔法值\t"<<myhero.player1.hero_mp<<endl;
			//<<"当前生命值\t"<<myhero.player1.hero_curhp<<endl;
			menu();
			break;
		case '7':
			exit(1);
			break;
		case 'v':
			take();
			break;
		}


	}
}

void main()
{
	cout<<"                             "<<"游 戏  : 传奇世界"<<endl<<endl<<endl;
	cf.open();
	cf.put();
	printf("\n\n");
	gamemap.Initmap();
	cout<<"           "<<"游戏地图"<<endl<<endl;
	gamemap.move(myhero.hero_y,myhero.hero_x);
	gamemap.printmap(gamemap.mapMax);
	myhero.Inithero();
	npc.InitNPC();
	printf("\n\n");
	menu();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -