首页 新闻 会员 周边

飞机游戏(有没有大佬看看是什么问题,实现不了飞机的移动和子弹的发射)

0
悬赏园豆:5 [待解决问题]

include <stdio.h>

include <stdlib.h>

include <windows.h>

include <conio.h>

void keytouch();
void gotoxy(int x,int y);

static int height = 20;//边界高度
static int weight = 20;//边界宽度
static int position_x=height/2;
static int position_y=weight/2;

static int bullet_x = -1;//激光的位置变量
static int bullet_y = -1;//激光的位置变量
//初始位置为(-1,-1),使得激光在坐标轴之外不显示出来,如果设置成(0,0),则一开始会出现在窗口的左上角处

void main()
{
char key = 0;
keytouch();
while(1)
{

Sleep(500);
system("cls");//清屏函数
gotoxy(0,0);//光标移动函数
for(int i=0;i<height;i++)
{
for(int j=0;j<weight;j++)
{
if((i == position_x) && (j == position_y))
printf("*");
else
printf(" ");
}
printf("\n");
}

if(kbhit())
{
key = getch();

if(key == ' ')//激光发射
{
bullet_y = position_y;
bullet_x = position_x-1;
}
}

if(bullet_x > -1)//激光移动
bullet_x --;
}
}

void gotoxy(int x,int y)
{
COORD pos;
pos.X = x;
pos.Y = y;
HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(out,pos);
}

void keytouch()
{
char key = 0;
if(kbhit())
{
key = getch();

if(key == 'a')
position_y --;
if(key == 's')
position_x ++;
if(key == 'd')
position_y ++;
if(key == 'w')
position_x --;
}
}

舍我其谁bo的主页 舍我其谁bo | 菜鸟二级 | 园豆:203
提问于:2020-09-17 17:42
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册