1 /* 2 //单人游戏 3 #include <iostream> 4 #include <windows.h> 5 #include <conio.h> 6 using namespace std; 7 int main(int argc, char** argv) { 8 HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE); 9 COORD coord={0,0}; 10 SetConsoleCursorPosition(handle,coord); 11 cout<<"h"; 12 while (1){ 13 if(kbhit()){ 14 SetConsoleCursorPosition(handle,coord); 15 cout<<" "; 16 int key=getch(); 17 switch(key){ 18 case 72: coord.Y--;break; 19 case 75: coord.X--;break; 20 case 77: coord.X++;break; 21 case 80: coord.Y++;break; 22 default: break; 23 } 24 SetConsoleCursorPosition(handle,coord); 25 cout<<"h"; 26 } 27 } 28 return 0; 29 } 30 //双人游戏 31 #include <iostream> 32 #include <windows.h> 33 #include <conio.h> 34 using namespace std; 35 int main() { 36 HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE); 37 HANDLE Handle=GetStdHandle(STD_OUTPUT_HANDLE); 38 COORD coord={0,0}; 39 COORD Coord={0,1}; 40 SetConsoleCursorPosition(handle,coord); 41 cout<<"JIA"; 42 SetConsoleCursorPosition(Handle,Coord); 43 cout<<"LIU"; 44 while (1){ 45 if(kbhit()){ 46 int key=getch(); 47 int s=0; 48 switch(key){ 49 case 72: SetConsoleCursorPosition(handle,coord);cout<<" ";coord.Y--;break; 50 case 75: SetConsoleCursorPosition(handle,coord);cout<<" ";coord.X--;break; 51 case 77: SetConsoleCursorPosition(handle,coord);cout<<" ";coord.X++;break; 52 case 80: SetConsoleCursorPosition(handle,coord);cout<<" ";coord.Y++;break; 53 default: break; 54 } 55 SetConsoleCursorPosition(handle,coord); 56 cout<<"JIA"; 57 s=0; 58 switch(key){ 59 SetConsoleCursorPosition(handle,coord); 60 cout<<" "; 61 case 87: SetConsoleCursorPosition(Handle,Coord);cout<<" ";Coord.Y--;break; 62 case 65: SetConsoleCursorPosition(Handle,Coord);cout<<" ";Coord.X--;break; 63 case 68: SetConsoleCursorPosition(Handle,Coord);cout<<" ";Coord.X++;break; 64 case 83: SetConsoleCursorPosition(Handle,Coord);cout<<" ";Coord.Y++;break; 65 default: break; 66 } 67 SetConsoleCursorPosition(Handle,Coord); 68 cout<<"LIU"; 69 } 70 } 71 return 0; 72 } 73 //在一块的 74 #include <iostream> 75 #include <windows.h> 76 #include <conio.h> 77 using namespace std; 78 int main() { 79 HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE); 80 HANDLE Handle=GetStdHandle(STD_OUTPUT_HANDLE); 81 COORD coord={0,0}; 82 COORD Coord={0,1}; 83 SetConsoleCursorPosition(handle,coord); 84 cout<<"JIA"; 85 SetConsoleCursorPosition(Handle,Coord); 86 cout<<"LIU"; 87 while (1){ 88 if(kbhit()){ 89 int key=getch(); 90 int s=0; 91 switch(key){ 92 case 72: SetConsoleCursorPosition(handle,coord);cout<<" ";coord.Y--;SetConsoleCursorPosition(Handle,Coord);cout<<" ";Coord.Y--;break; 93 case 75: SetConsoleCursorPosition(handle,coord);cout<<" ";coord.X--;SetConsoleCursorPosition(Handle,Coord);cout<<" ";Coord.X--;break; 94 case 77: SetConsoleCursorPosition(handle,coord);cout<<" ";coord.X++;SetConsoleCursorPosition(Handle,Coord);cout<<" ";Coord.X++;break; 95 case 80: SetConsoleCursorPosition(handle,coord);cout<<" ";coord.Y++;SetConsoleCursorPosition(Handle,Coord);cout<<" ";Coord.Y++;break; 96 default: break; 97 } 98 SetConsoleCursorPosition(handle,coord); 99 cout<<"JIA"; 100 SetConsoleCursorPosition(Handle,Coord); 101 cout<<"LIU"; 102 } 103 } 104 return 0; 105 }*/
标签:STD,操控,handle,GetStdHandle,coord,键盘,HANDLE,include From: https://www.cnblogs.com/liujiaxing-/p/18132987