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

📄 crole.cpp

📁 这是我用VC写的一个RPG的文字游戏
💻 CPP
字号:

#include "CRole.h"
#include<iostream>
#include"NPC.h"
#include"head.h"
#include"Color.h"
using namespace std;
extern mygame call;//调用已经声明的对象
extern color c;//调用已经声明的对象
extern CRole k;//调用已经声明的对象,行走用
 CRole jk;
NPC npc;
CRole::CRole()
{
	 x = 50;
	 y = 50;
	 AP = 100;
	 LEVL=1;//等级
	 HP=100;//生命值
	 EP=10;//经验值
	 BI=30;//力量值
	 ID=10;//魔法值
     ME=0;//金钱数
	 P=0;
	 
}
CRole::~CRole()
{
}
void CRole::setx(int i) 
{x = i;}
void CRole::sety(int i)
{ y = i;}
void CRole::setLEVL(int levl)
{LEVL = levl;}
void CRole::setHP(int hp)
{HP = hp;}
void CRole::setEP(int ep)
{EP = ep;}
void CRole::setBI(int bi)
{BI = bi;}
void CRole::setID(int id)
{ID = id;}
void CRole::setME(int me)
{ME = me;}
void CRole::setAP(int ap)
{AP = ap;}


int CRole::getx()
{return x;}
int CRole::gety()
{return y;}
int CRole::getLEVL()
{return LEVL;}
int CRole::getHP()
{return HP;}
int CRole::getEP()
{return EP;}
int CRole::getBI()
{return BI;}
int CRole::getID()
{return ID;}
int CRole::getME()
{return ME;}
 

void CRole::shuxing()//玩家属性
{
	c.qingse();
	cout<<"〖"<<k.player<<"〗";
	c.baise();
	cout<<"的属性栏:"<<"\n"<<endl;
  c.anhuangse();
  call.image("   等级:",8);
  c.Hongse();
  cout<<getLEVL();
  c.anhuangse();
  call.image("   生命值:",10);
  c.Hongse();
  cout<<getHP();
  c.anhuangse();
  call.image("   经验值:",10);
  c.Hongse();
  cout<<getEP();
  c.anhuangse();
  call.image("   力量值:",10);
  c.Hongse();
  cout<<getBI();
   c.anhuangse();
  call.image("   魔法值:",10);
  c.Hongse();
  cout<<getID();
  c.anhuangse();
  call.image("   金钱数:",10);
  c.Hongse();
  cout<<getME()<<"\n"<<endl;
  if(call.zhuangtai==0)
	{
		c.lvse();
		cout<<"返回菜单请按c,(也可不返回而直接选择菜单选项):"<<endl;
	}
	if(call.zhuangtai==1)
	{
		c.lvse();
		cout<<"继续行走...:";
	}

}



void CRole::xingzou()
{
	c.qingse();
	cout<<"【";
	cout<<k.player;
	cout<<"】:"<<endl;
	
    cout<<"\n"<<endl;
	c.anhuangse();
	call.image(" 时已黄昏你已经来到村子的地下水路,此路线怪物:巨鼠,级别 :1,栖息在地下水路的巨大变形鼠,动作迅速,攻击性强,能看清黑暗中的一切。 ",133);
	cout<<"\n"<<endl;
	call.image(" 骷髅战士(斧子),级别 1,地下水路 因死于非命而离不开世间的战士的灵魂,其唯一目的是战斗!",90);
	cout<<"\n"<<endl;
	c.lvse();
	call.image(" 此路线通向正北方(蓬莱),按w键向北方前进(a,d键左右移动),地下水路宽10米,两面全为洞壁。",99);
	cout<<"\n"<<endl;
	cout<<"目前坐标:";
    c.qingse();
	cout<<"  X:"<<getx()<<"  Y:"<<gety()<<endl;
	cout<<"\n"<<endl;
	c.baise();
	cout<<"按 w 键向北(蓬莱)行走(a,d左右移动):"<<endl;
	while(true)
	{
	cin>>W;
	if(W[1]==NULL)
	{
		
		if(gety()<26)P=1;
	switch(W[0])
		{
		case'a':
			// npc.d=0;
			if(getx()>40||gety()<26) 
			{
				c.qingse();
			   cout<<"【";
			   cout<<k.player;
			   cout<<"】:"<<endl;
			   c.huangse();
				cout<<" :向西走了几步";
				setx(getx()-5);
				c.anhuangse();
	            cout<<"  目前坐标:";
	            c.qingse();
	            cout<<"  X:"<<getx()<<"  Y:"<<gety()<<endl;
			} 

			if(P==0 )
				
			  {
                
				  if(getx()<45)
				  {
				    cout<<"\n"<<endl;
				c.qingse();
			    cout<<"【";
			    cout<<"提示";
			    cout<<"】:";
				c.Hongse();
				cout<<" 你已经碰到了墙壁!"<<endl;
				c.anbaise();
				cout<<"  潮湿的洞壁上附有大量";
				c.Hongse();
				cout<<"『吸血虫』";
			   c.anbaise();
				cout<<"和";
				c.Hongse();
				cout<<"『毒蝎』"<<endl;
				c.qingse();
				cout<<"  分布范围:左右洞壁"<<endl;
				cout<<"  坐标范围:Y坐标26--45之间"<<endl;
				cout<<"  等级 1 尽量不要靠近洞壁!"<<"\n";
				c.baise();
				cout<<"继续行走按(w/a/d)"<<endl;
				npc.npc2_penglai();//////////////////////调用洞壁(左)
			  }
			}
              
			break;
		case'w':
           if(gety()>0){
			c.qingse();
			cout<<"【";
			cout<<k.player;
			cout<<"】:"<<endl;
			c.baise();

			cout<<" :向北走了一段距离";
			   sety(gety()-2);
			
			    c.anhuangse();
	            cout<<"  目前坐标:";
	            c.qingse();
	            cout<<"  X:"<<getx()<<"  Y:"<<gety()<<endl;
                npc.npc3_penglai();//////////////////////////遇怪/骷髅战士
				npc.sleep_money();                   ///////////////////////////休息,淘金
           }else
			{
				c.Hongse();
              cout<<" :已经碰到了城墙~~!"<<endl;
			}

			break;
          case's':
			if(gety()<100)
			{
			c.qingse();
			cout<<"【";
			cout<<k.player;
			cout<<"】:"<<endl;
			c.Lanse();
            sety(gety()+2);
            cout<<" :向南走了一段距离";
			
			
			    c.anhuangse();
	            cout<<"  目前坐标:";
	            c.qingse();
	            cout<<"  X:"<<getx()<<"  Y:"<<gety()<<endl;
            }else
			{
				c.Hongse();
				cout<<" :已经碰到了城墙~~!"<<endl;
			}

		case'd':
			//npc.d=0;

			if(getx()<60||gety()<26)
			{ 
				c.qingse();
			    cout<<"【";
			    cout<<k.player;
			    cout<<"】:"<<endl;
			    c.anqingse();
			  cout<<" :向东走了几步";

			  setx(getx()+5);

			    c.anhuangse();
	            cout<<"  目前坐标:";
	            c.qingse();
	            cout<<"  X:"<<getx()<<"  Y:"<<gety()<<endl;
            }
			if(P==0 )
			
			{


              
           if(getx()>55)
				{
					  
                cout<<"\n"<<endl;
				 c.qingse();
			    cout<<"【";
			    cout<<"提示";
			    cout<<"】:";
			  
				c.Hongse();
				cout<<" 你已经碰到了墙壁!"<<endl;
				c.anbaise();
				cout<<"  潮湿的洞壁上附有大量";
				c.Hongse();
				cout<<"『吸血虫』";
			   c.anbaise();
				cout<<"和";
				c.Hongse();
				cout<<"『毒蝎』"<<endl;
				c.qingse();
				cout<<"  分布范围:左右洞壁"<<endl;
				cout<<"  坐标范围:Y坐标26--45之间"<<endl;
				cout<<"  等级 1 尽量不要靠近洞壁!"<<"\n";
				c.baise();
				cout<<"继续行走按(w/a/d)"<<endl;

                 npc.npc2_penglai();/////////////////////////////////调用  洞壁  右
			}
			}
			 break;
		case'm':
			call.map();////////////////游戏中按'm'键随时查看地图
			
			//c.baise();
			//cout<<"继续行走..."<<endl;
			break;
		case 'b':
			shuxing();/////////////////游戏中按'b'键随时查看玩家属性
			//c.baise();
			//cout<<"继续行走..."<<endl;
			break;
		 
		case 'h':
			call.help();/////////////////游戏中按'h'键随时查看帮助
			//c.baise();
			//cout<<"继续行走..."<<endl;
			break;
		case 'k':
			call.wupin();/////////////////游戏中按'k'键随时查看物品栏
			//c.baise();
			//cout<<"继续行走..."<<endl;
			break;
		case 't':
			call.zhuangtai=2;
			npc.chose_wupin();/////////////////游戏中按't'键随时使用物品栏的物品
           // cout<<"继续行走..."<<endl;
			break;
		case 'e':
			//exit(0);//退出/////////////////游戏中按'e'键随时退出 
				c.huangse();
				cout<<"确认要退出吗?";
				c.lvse();
				cout<<"(y/n)"<<endl;
				cin>>call.M;
				 switch(call.M[0])
				  {
					case 'y':
					 exit(0);//退出
						break;
					case 'n':
                       cout<<"游戏继续..."<<endl;
						break;
				 }
			c.baise();
			cout<<"继续行走..."<<endl;
			break;
		default:
			c.qingse();
			cout<<"只能输入东(d),西(a),南(s),北(w)"<<endl;
	    }
		   npc.flower_penglai(); //////////////////////////////////强酸花
		   if(gety()<26)npc.last();//////////////////////////////////寻找田不易
           
      }else
		{
			c.Hongse();
			cout<<"只能输入东(d),西(a),南(s),北(w)"<<endl;
		}
    }
}

⌨️ 快捷键说明

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