最近裝那個虛擬機,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;
}

`