#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<windows.h>//
#include<conio.h>//監聽鍵盤的輸入
int direct = '0';
void gotoxy(int x, int y)//輔助函式系統自帶 可以改變游標位置
{
COORD pos = { x,y };
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut, pos);//這個一定要定義到全域里面 這一串函式可以直接參考 不用管怎么來的
}
struct circle//定義一個球
{
int x;
int y;
}circle;
void move()
{
while (1)
{
if (_kbhit)
{
fflush(stdin);
direct = _getch();
gotoxy(circle.x, circle.y);
printf(" ");
switch (direct)
{
case 'w':
circle.y--;//這個是選擇陳述句之后執行的內容
break;
case 'a':
circle.x -= 2;
break;
case 's':
circle.y++;
break;
case 'd':
circle.x += 2;
break;
}
gotoxy(circle.x, circle.y);
printf("o");//這里是定義你想要移動物體的形狀可以隨意修改
gotoxy(80, 0);
}
}
}
int main()
{
printf("歡迎進入游戲的世界 w為向上運動 a為左 d為右 s為下運動");
move();
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/295746.html
標籤:其他
