最近装那个虚拟机,10.1号晚上搞了半天都搞不好,下次专门让老师搞吧
不过可喜的事情来了,我在windows编程上搞c++迈出了可喜的一步,我会用箭头来选择选项了。从而我在原则上能实现:元素卡牌模拟器
`
include
include <windows.h>
include
include "conio.h"
using namespace std;
void cursor_move(int x, int y) {
int upspace = 3;
int leftspace = 4;
COORD coord;
//使用头文件自带的坐标结构
coord.X = (x + leftspace) * 2;
//这里将int类型值传给short,不过程序中涉及的坐标值均不会超过short范围
coord.Y = y + upspace;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
//以标准输出的句柄为参数设置控制台光标坐标
}
int choose(int n) {
int pos_y = 1;
int key = 0; //按键的值
cursor_move(0, 0);
cout << "click a choice which you want:" << endl;
//打印初始语句
for (int i = 1; i <= n; i++) {
cursor_move(1, i);
cout << i << endl;
}//打印n个选项
cursor_move(0, 2);
printf(">>");
//打印箭头初始位置
while (key != 13) {//13是回车键
if (kbhit()) {// 检查是否有按键被按下
key = getch();
if (key == 'w') {
cursor_move(0, pos_y);
printf(" ");
//用空格替换原来的箭头
pos_y--;
//光标上移
}
if (key == 's') {
cursor_move(0, pos_y);
printf(" ");
//用空格替换原来的箭头
pos_y++;
//光标下移
}
if (pos_y > n)
pos_y -= n;//最下方光标回到最下方
if (pos_y < 1)
pos_y += n;//最上方光标回到最下方
cursor_move(0, pos_y);
printf(">>");
//打印箭头位置
}
}
return pos_y;
}
int main(int argc, char **argv) {
int ooo = choose(20);
cout << ooo;
return 0;
}
`
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律