#include <bits/stdc++.h> #include <windows.h> #include <conio.h>//控制台输入输出头文件 using namespace std; int main(){ HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE);//获取标准输出的句柄 COORD coord={0,0};//保存光标坐标 SetConsoleCursorPosition(handle,coord); HANDLE handle1=GetStdHandle(STD_OUTPUT_HANDLE); COORD coord1={1,0}; SetConsoleCursorPosition(handle,coord); cout<<"HH"; SetConsoleCursorPosition(handle1,coord1); cout<<"H"; while(1){ if(kbhit()){ SetConsoleCursorPosition(handle,coord); cout<<" "; SetConsoleCursorPosition(handle1,coord1); cout<<" "; int key=getch(); switch(key){ case 72: coord.Y--;coord1.Y--;break; case 75: coord.X--;coord1.X--;break; case 77: coord.X++;coord1.X++;break; case 80: coord.Y++;coord1.Y++;break; case 119: while(coord1.Y>1){ SetConsoleCursorPosition(handle,coord); cout<<"HH"; coord1.Y--; SetConsoleCursorPosition(handle1,coord1); cout<<"H"; Sleep(30); SetConsoleCursorPosition(handle1,coord1); cout<<" "; } coord1.Y=coord.Y; break; case 115: while(coord1.Y<30){ SetConsoleCursorPosition(handle,coord); cout<<"HH"; coord1.Y++; SetConsoleCursorPosition(handle1,coord1); cout<<"H"; Sleep(30); SetConsoleCursorPosition(handle1,coord1); cout<<" "; } coord1.Y=coord.Y; break; case 97: while(coord1.X>1){ SetConsoleCursorPosition(handle,coord); cout<<"HH"; coord1.X--; SetConsoleCursorPosition(handle1,coord1); cout<<"H"; Sleep(30); SetConsoleCursorPosition(handle1,coord1); cout<<" "; } coord1.X=coord.X; break; case 100: while(coord1.X<38){ SetConsoleCursorPosition(handle,coord); cout<<"HH"; coord1.X++; SetConsoleCursorPosition(handle1,coord1); cout<<"H"; Sleep(30); SetConsoleCursorPosition(handle1,coord1); cout<<" "; } coord1.X=coord.X; break; default: break; } SetConsoleCursorPosition(handle,coord); cout<<"HH"; } } return 0; }
标签:handle,输入输出,coord,炮弹,SetConsoleCursorPosition,HANDLE,控制台,include From: https://www.cnblogs.com/fushuxuan/p/18147801