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

📄 gamemap.cpp

📁 MUD文字游戏开发
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		DrawRole((*it).GetMonsterX(),(*it).GetMonsterY(),(*it).GetMonsterX(),(*it).GetMonsterY(),(*it).GetName());
	}
}

//在冰原地图的左下角画出城堡
void CGameMap::DrawCastle()
{
	COORD coTempPOS = {0,(SCREENHEIGHT - 8)};
	m_DrawMapElement->DrawMapElement(coTempPOS,"困困困困困困困");
	coTempPOS.X = 16;
	coTempPOS.Y = SCREENHEIGHT - 8;
	m_DrawMapElement->DrawMapElement(coTempPOS,"困困困");

	coTempPOS.X = 20;
	for(int i=1;i<=7;i++)
	{
		coTempPOS.Y = SCREENHEIGHT - 8 + i;
		m_DrawMapElement->DrawMapElement(coTempPOS,"困");
	}
}

//在冰原地图的右上角画出火魔的洞穴入库
void CGameMap::DrawBurrow()
{
	COORD coTempPOS = {SCREENWIDTH - 6,0};
	m_DrawMapElement->DrawMapElement(coTempPOS,"困困困");
	coTempPOS.X = SCREENWIDTH - 4;
	coTempPOS.Y = 1;
	m_DrawMapElement->DrawMapElement(coTempPOS,"火魔");
	coTempPOS.X = SCREENWIDTH - 6;
	coTempPOS.Y = 2;
	m_DrawMapElement->DrawMapElement(coTempPOS,"困困困");
}

//显示玩家和怪物
void CGameMap::DrawRole(int nOldX,int nOldY,int nCurrentX,int nCurrentY,string strRole)
{
	COORD coTempPOS;
	coTempPOS.X = nOldX;
	coTempPOS.Y = nOldY;
	m_DrawMapElement->DrawMapElement(coTempPOS,"  ");
	coTempPOS.X = nCurrentX;
	coTempPOS.Y = nCurrentY;
	m_DrawMapElement->DrawMapElement(coTempPOS,strRole);
}

//玩家与怪物的碰撞检测
void CGameMap::RolesHitCheck(int nPOSX,int nPOSY,int nDIR)
{
	switch (nDIR)
	{
	case 0://向上
		nPOSY -= 1;
		break;
	case 1://向下
		nPOSY += 1;
		break;
	case 2://向左
		nPOSX -=2;
		break;
	case 3://向右
		nPOSX +=2;
		break;
	}
	vector<CMonster>::iterator it;
	for(it = m_vecMonster.begin();it!=m_vecMonster.end();++it)
	{
		//判断玩家和其中的怪物是否发生了碰撞
		if ((nPOSX == (*it).GetMonsterX()) && (nPOSY == (*it).GetMonsterY()) && ((*it).GetCurrentHP() > 0))
		{
			m_bFight = true;
			m_pcMonster = &(*it);//记录下发生碰撞的怪物
			m_nPlayerX = (*it).GetMonsterMaxX()/2==1?(*it).GetMonsterMaxX()+1:(*it).GetMonsterMaxX()+2;
			m_nPlayerY = (*it).GetMonsterMaxY();
			system("cls");
			CreatFightMenu();//创建战斗菜单
			return;
		}
	}
}

//创建战斗菜单
void CGameMap::CreatFightMenu()
{
	COORD coPOS = {SCREENWIDTH/3,SCREENHEIGHT/3};
	m_DrawMapElement->CreateMenu(coPOS);
	m_DrawMapElement->AddMenuCell(" 攻  击 ");
	m_DrawMapElement->DrawMenu(1,1);//默认选中第一个菜单
	m_DrawMapElement->AddMenuCell(" 物  品 ");
	m_DrawMapElement->AddMenuCell(" 状  态 ");
	m_DrawMapElement->AddMenuCell(" 逃  脱 ");
}

//显示战斗画面
void CGameMap::Fighting()
{
	//CreatFightMenu();//创建战斗菜单
	int nSelect;
	int nAtt1,nAtt2;
	string strName;
	nSelect = m_DrawMapElement->SelectMenu();

	switch (nSelect)
	{
	case 1:
		nAtt1 = m_pcMonster->CalculatorHP(m_pcPlayer->GetAttack());
		strName = m_pcMonster->GetName();
		cout<<strName<<":受到"<<nAtt1<<"点伤害"<<endl;
		//------------战胜----------
		if (m_pcMonster->GetCurrentHP() == 0)
		{
			cout<<"你击退了"<<strName<<endl;
			m_pcPlayer->GetWin(m_pcMonster);//输出胜利画面
			DrawIceAgain(m_pcMonster,m_pcPlayer);
			m_bFight = false;
			break;
		}
		nAtt2 = m_pcPlayer->CalculatorHP(m_pcMonster->GetAttack());
		strName = m_pcPlayer->GetName();
		cout<<strName<<":中了"<<m_pcMonster->GetSkill()<<"受到"<<nAtt2<<"点伤害"<<endl;
		//------------战败----------
		if (m_pcPlayer->GetCurrentHP() == 0)
		{
			m_bStopMove = true;
			system("cls");
			m_DrawMapElement->ShowMessage("              ★★饮恨江湖★★",1);
			m_DrawMapElement->ShowMessage("-------------------------------------------",2);
			m_DrawMapElement->ShowMessage("( ⊙o⊙?)这世道没点水平不好混呀! o(︶︿︶)o唉",3);
			m_DrawMapElement->ShowMessage("                               除回车外,按任意键返回.....",16);
			while (1)
			{
				if(_getch() != 13) break;
			}
			system("cls");
			m_bRunIceMap = false;//退出游戏画面,返回主菜单
		}
		break;
	case 2://查看物品
		SeeGoods();
		break;
	case 3://查看状态
		SeeState();
		break;
	case 4://逃脱
		DrawIceAgain(m_pcMonster,m_pcPlayer);
		m_bFight = false;
		break;
	}
}

void CGameMap::DrawIceAgain(CMonster *pMonster,CPlayer *pPlayer)
{
	system("cls");
	DrawCastle();//在冰原地图的左下角画出城堡
	DrawBurrow();//在冰原地图的右上角画出火魔的洞穴入库
	DrawRole(pPlayer->GetPlayerX(),pPlayer->GetPlayerY(),pPlayer->GetPlayerX(),pPlayer->GetPlayerY(),pPlayer->GetName());
	//DrawRole(pMonster->GetMonsterX(),pMonster->GetMonsterY(),pMonster->GetMonsterX(),pMonster->GetMonsterY(),pMonster->GetName());
	if (pMonster->GetCurrentHP() > 0)
	{
		DrawRole(pMonster->GetMonsterX(),pMonster->GetMonsterY(),pMonster->GetMonsterX(),pMonster->GetMonsterY(),pMonster->GetName());
	}
}

void CGameMap::SeeState()
{
	//其起始坐标正好指向开始主菜单的位置
	COORD coPOS = {SCREENWIDTH/3+MenuWidth+1,SCREENHEIGHT/3+4};

	WORD wShadowAtt = BACKGROUND_INTENSITY; // 阴影属性
	WORD wTextAtt = FOREGROUND_RED |FOREGROUND_GREEN |FOREGROUND_BLUE | FOREGROUND_INTENSITY |
		BACKGROUND_RED | BACKGROUND_BLUE; // 文本属性

	COORD coShadowPOS = {coPOS.X+1,coPOS.Y+1};

	//增加菜单内容
	coShadowPOS.Y = SCREENHEIGHT/3+4+1;
	SetConsoleCursorPosition(CInput::getHout(),coShadowPOS);
	cout<<"-------玩家-------";
	++coShadowPOS.Y;
	SetConsoleCursorPosition(CInput::getHout(),coShadowPOS);
	cout<<"名  字:"<<m_pcPlayer->GetName();
	++coShadowPOS.Y;
	SetConsoleCursorPosition(CInput::getHout(),coShadowPOS);
	cout<<"生  命:"<<m_pcPlayer->GetCurrentHP()<<"/"<<m_pcPlayer->GetHP();
	++coShadowPOS.Y;
	SetConsoleCursorPosition(CInput::getHout(),coShadowPOS);
	cout<<"内  力:"<<m_pcPlayer->GetCurrentMP()<<"/"<<m_pcPlayer->GetMP();
	++coShadowPOS.Y;
	SetConsoleCursorPosition(CInput::getHout(),coShadowPOS);
	cout<<"攻击力:"<<m_pcPlayer->GetAttack();
	++coShadowPOS.Y;
	SetConsoleCursorPosition(CInput::getHout(),coShadowPOS);
	cout<<"防御力:"<<m_pcPlayer->GetDefence();
	++coShadowPOS.Y;
	SetConsoleCursorPosition(CInput::getHout(),coShadowPOS);
	cout<<"-------怪物-------";
	++coShadowPOS.Y;
	SetConsoleCursorPosition(CInput::getHout(),coShadowPOS);
	cout<<"名  字:"<<m_pcMonster->GetName();
	++coShadowPOS.Y;
	SetConsoleCursorPosition(CInput::getHout(),coShadowPOS);
	cout<<"生  命:"<<m_pcMonster->GetCurrentHP()<<"/"<<m_pcMonster->GetHP();
	++coShadowPOS.Y;
	SetConsoleCursorPosition(CInput::getHout(),coShadowPOS);
	cout<<"攻击力:"<<m_pcMonster->GetAttack();

	//给显示的菜单加上指定颜色
	coShadowPOS.Y = coPOS.Y+1;
	for (int i=0; i<12; ++i)
	{
		FillConsoleOutputAttribute(CInput::getHout(), wShadowAtt, 20, coShadowPOS, NULL);
		++coShadowPOS.Y;
	}
	for (int i=0; i<12; ++i)
	{
		FillConsoleOutputAttribute(CInput::getHout(), wTextAtt, 20, coPOS, NULL);
		++coPOS.Y;
	}
	//恢复坐标值
	coShadowPOS.X = 0;
	coShadowPOS.Y = 0;
	SetConsoleCursorPosition(CInput::getHout(),coShadowPOS);
}

//查看物品
void CGameMap::SeeGoods()
{
	//其起始坐标正好指向开始主菜单的位置
	COORD coPOS = {SCREENWIDTH/3+MenuWidth+1,SCREENHEIGHT/3+2};

	WORD wShadowAtt = BACKGROUND_INTENSITY; // 阴影属性
	WORD wTextAtt = FOREGROUND_RED |FOREGROUND_GREEN |FOREGROUND_BLUE | FOREGROUND_INTENSITY |
		BACKGROUND_RED | BACKGROUND_BLUE; // 文本属性

	COORD coShadowPOS = {coPOS.X+1,coPOS.Y+1};
	//增加菜单内容
	coShadowPOS.Y = SCREENHEIGHT/3+2+1;
	SetConsoleCursorPosition(CInput::getHout(),coShadowPOS);
	if (m_pcPlayer->GetAKey() == 1)
	{
		cout<<"一把神秘的钥匙";
	}
	else
	{
		cout<<"无物品";
	}

	//给显示的菜单加上指定颜色
	coShadowPOS.Y = coPOS.Y+1;
	for (int i=0; i<3; ++i)
	{
		FillConsoleOutputAttribute(CInput::getHout(), wShadowAtt, 16, coShadowPOS, NULL);
		++coShadowPOS.Y;
	}
	for (int i=0; i<3; ++i)
	{
		FillConsoleOutputAttribute(CInput::getHout(), wTextAtt, 16, coPOS, NULL);
		++coPOS.Y;
	}

	//恢复坐标值
	coShadowPOS.X = 0;
	coShadowPOS.Y = 0;
	SetConsoleCursorPosition(CInput::getHout(),coShadowPOS);
}

void CGameMap::ClueOnMESS()
{
	system("cls");
	m_bStopMove = true;
	if (m_pcPlayer->GetAKey())
	{
		m_DrawMapElement->ShowMessage("                ★★恭喜★★",1);
		m_DrawMapElement->ShowMessage("-------------------------------------------",2);
		m_DrawMapElement->ShowMessage("你打开了一个作者没时间开发的世界!!!",3);
		m_DrawMapElement->ShowMessage("    --------  更多精彩留待后续!(+﹏+)~狂晕",4);
		m_DrawMapElement->ShowMessage("   ╭∩╮(︶︿︶)╭∩╮鄙视未完成的作品",9);
	}
	else
	{
		m_DrawMapElement->ShowMessage("              ★★信息提示★★",1);
		m_DrawMapElement->ShowMessage("-------------------------------------------",2);
		m_DrawMapElement->ShowMessage("洞穴入口被封锁了,似乎需要什么东西来开启它!!!",3);
	}
}

⌨️ 快捷键说明

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