用控制台实现角色移动C++

用控制台实现角色移动C++,第1张

控制台实现角色移动C++

今天我写了一个可以让人物移动的代码,你肯定用得着!看看嘛,又不吃亏对吧!

当然,这是做游戏的关键!你可以配上细节!!细节!

话不多说,上代码!

(预告:下期发控制台制作逼真进度条)

-------------------------------------------------------------------------------------------------------------------------------

#include
#include
#include
#include
#include
#include
#include
#include 
#include 
#include 

using namespace std;
int main()
{



COORD coord;
coord.X = 2;
coord.Y = 1;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
int x = 0, y = 0, mm, tt = 1;
for (;;)
{
mm = _getch();
switch (mm)
{
case 'a': {
if (x != 2) {
for (int i = 0; i < tt; i++)
{ 
printf("我");
Sleep(100);
system("cls"); 
} 

x -= 1;

COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
break;
}
case 'd': {for (int i = 0; i < tt; i++)
{
printf("我");
Sleep(100);
system("cls"); 
}

x += 1;

COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
break; }
case 'w': {
for (int i = 0; i < tt; i++)
{
printf("我");
Sleep(100);
system("cls"); 
}

if (y != 1)
{
y -= 1;

COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
break;
}
}
case 's':
{for (int i = 0; i < tt; i++)
{
printf("我");
Sleep(100);
system("cls");
}
y += 1;

COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
break; }





}


}



return 0;
}

另外,角色的外观可以改变! 

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4751107.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-08
下一篇2022-11-08

发表评论

登录后才能评论

评论列表(0条)

    保存