#include <bits/stdc++.h> #include <windows.h> #include <conio.h> //控制台输入输出文件 using namespace std; int main() { HANDLE handle =GetStdHandle(STD_OUTPUT_HANDLE); //获取标准输出的句柄 COORD coord={15,5};//保存光标坐标 COORD coord1={22,5};//保存光标坐标 SetConsoleCursorPosition(handle,coord); cout<<"*"; char b[]={'s','s','s','a','a','a','d','d','d','d','d','d','a','a','a','s','s','a','a','d','d','d','d','s','s','a','a','a','a','w','s','s','s','d','d','d','d','w','s','a','a','s','s','a','a','a','d','d','d','d','d','d','a','a','a','s','s','s','s'}; vector<char> a(b,b+sizeof(b)/sizeof(char)); while(1) { if(kbhit()) { for(int i=0;i<a.size();i++) { if(a[i]=='w'||a[i]=='a'||a[i]=='s'||a[i]=='d') { switch(a[i]) { SetConsoleCursorPosition(handle,coord); case 's': coord.Y++;break; case 'a': coord.X--;break; case 'd': coord.X++;break; case 'w': coord.Y--;break; default: break; } SetConsoleCursorPosition(handle,coord); cout<<"*"; Sleep(1000); } } return 0; } } return 0; }
标签:handle,一半,cmd,int,HANDLE,sizeof,include From: https://www.cnblogs.com/hanxuyao/p/18211629