推箱子游戏总共就分为两部分
一、游戏的初始界面
二、游戏的界面
三、我先写初始界面(因为我也还没写完,纯粹就是归纳一下)
nSelect初始值定义的是0,这个主要是对选项的选择,总共就分为三个:开始、设置、退出
if (0 == nSelect)
{
cout << "--> 开始" << endl;
cout << " 设置" << endl;
cout << " 退出" << endl;
}
else if (1 == nSelect)
{
cout << " 开始" << endl;
cout << "--> 设置" << endl;
cout << " 退出" << endl;
}
else if (2 == nSelect)
{
cout << " 开始" << endl;
cout << " 设置" << endl;
cout << "--> 退出" << endl;
}
这块主要是对键盘的监听,通过上下犍来移动初始界面的箭头指向
if (Key_Listen(VK_UP))
{
nSelect--;
if (nSelect<0)
{
nSelect = 2;
}
}
else if (Key_Listen(VK_DOWN) & 0x8000)
{
nSelect++;
if (nSelect > 2)
{
nSelect = 0;
}
}
else if (Key_Listen(VK_RETURN) & 0x8000)
{
nScene = 1;
nClearScene = 1;
}
上面中Key_Listen()不是库里的函数,是我宏定义的一个按钮监听的一个函数吧(不知准不准确,我也只知道他的作用)
#define Key_Listen(code) (GetAsyncKeyState(code) & 0x8000)