#include<stdio.h>
#include<windows.h>
#include<conio.h>
void pos(int x_pos,int y_pos){
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos={x_pos,y_pos};
SetConsoleCursorPosition(hOut,pos);
}
void ChangeColor(){
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hOut,FOREGROUND_GREEN|FOREGROUND_INTENSITY);
}
int main(){
int x_pos=1,y_pos=1;
ChangeColor();pos(20,5);printf("使用WSAD控制移动");
while(1){
switch(getch()){
case 'w':
y_pos-=1;break;
case 's':
y_pos+=1;break;
case 'a':
x_pos-=2;break;
case 'd':
x_pos+=2;break;
}
system("cls");
ChangeColor();
pos(x_pos,y_pos);printf("囧");
pos(40,20);printf("%d,%d",x_pos,y_pos);
}
return 0;
}
C语言写WSAD控制移动
最新推荐文章于 2023-07-24 11:54:28 发布