#include <iostream> #include <vector> #include <windows.h> #include <conio.h> using namespace std; int main(){ HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); COORD coord = {0,5}; SetConsoleCursorPosition(handle,coord); vector<char> a; string s = "dddddaasssaaddddaasssaaadddddd"; string s1 = "wwwdd"; string s2 = "ddddd"; string s3 = "wwwwdddd"; string s4 = "ssssssswwwdddddwwwssssss"; string z = s+s1+s2+s3+s4; for(int i = 0;i<z.size();i++){ a.push_back(z[i]); } char key; int i = 0; while(i<=z.size()){ key = a[i]; switch(key){ case 'w': coord.Y--;break; case 'a': coord.X-=2;break; case 'd': coord.X+=2;break; case 's': coord.Y++;break; default: break; } SetConsoleCursorPosition(handle,coord); if(i>=0 && i<s.size()){ cout<<"王"; }else if(i>=s.size() && i<s.size()+s1.size()){ cout<<" "; }else if(i>=s1.size() && i<s.size()+s1.size()+s2.size()){ cout<<"一"; }else if(i>=s2.size() && i<s.size()+s1.size()+s2.size()+s3.size()){ cout<<" "; }else if(i>=s3.size() && i<s.size()+s1.size()+s2.size()+s3.size()+s4.size()){ cout<<"H"; } i++; Sleep(100); } return 0; }
标签:王一,string,s3,s2,打印,键盘,&&,include,size From: https://www.cnblogs.com/wangyihang-xh/p/18211621