有一篇文章,只是一个字符移动,还是定向的,更气人的是他竟然收费。我一看见这篇文章,你说我是笑还是气呢?我跟他说:你不行啊,我给你弄个可操控的。于是……
上代码!!!
- #include
- #include
- #include
- using namespace std;
-
-
- int x=10,y=10;
- int key;
- bool xt=0;
- void hide_cursor()//隐藏光标,要不要都行,这里是复制的
- {
- HANDLE h_GAME =GetStdHandle(STD_OUTPUT_HANDLE);
- CONSOLE_CURSOR_INFO cursor_info;
- GetConsoleCursorInfo(h_GAME,&cursor_info);
- cursor_info.bVisible=false;
- SetConsoleCursorInfo(h_GAME,&cursor_info);
- }
-
- void gotoxy(int xpos, int ypos)//移动光标,还这里是复制的
- {
- COORD scrn;
- HANDLE hOuput = GetStdHandle(STD_OUTPUT_HANDLE);
- scrn.X = xpos; scrn.Y = ypos;
- SetConsoleCursorPosition(hOuput, scrn);
- }
- int main()
- {
- hide_cursor();
- gotoxy(x,y);
- cout<<"O";
- gotoxy(x,y+1);
- cout<<"|==";
- gotoxy(x,y+2);
- cout<<"一";
- gotoxy(x,y+3);
- cout<<"/";
- while(1)
- {
- if(_kbhit())
- {
- key = _getch();
- if(key==97)
- {
- if(x>0)x-=1;
- }
- if(key==119)
- {
- if(y>0)y-=1;
- }
- if(key==100)
- {
- x+=1;
- }
- if(key==115)
- {
- y+=1;
- }
- system("cls");
- gotoxy(x,y);
- cout<<"O";
- gotoxy(x,y+1);
- cout<<"|==";
- gotoxy(x,y+2);
- cout<<"一";
- gotoxy(x,y+3);
- cout<<"/";
- }
-
- }
- return 0;
- }
可在DEV-C++上运行!
记得点赞收藏评论关注转发订阅