C语言简单的飞机大战源代码

飞机大战源代码(没有用结构体和指针相关知识)
上代码
#include
#include
#include
#include
#include
void enter();
void times();
void play();
void enter()
{
printf("\t\t\t\t*************************************************\n");
printf("\t\t\t\t************ 欢迎来到飞机世界 \n");
printf("\t\t\t\t
\n");
printf("\t\t\t\t
-----注意事项------ \n");
printf("\t\t\t\t1.w上升 2.s为下降 3.a为左 4.d为右 5.空格为攻击
\n");
printf("\t\t\t\t
*** 确定(Enter进入) \n");
printf("\t\t\t\t
*************************************\n");
Sleep(1000);
}
void times()
{
system(“cls”);
int i;
printf(“游戏倒计时*\n”);
for (i = 3; i >= 0; i–)
{
printf(" %d\b\b\b\b\b\b\b\b\b\b\b\b", i);
Sleep(1000);
}
printf("\n");
}
void play()
{
int i, j;
int num = 0;
int blood = 10;
int x = 10, y = 5, vx = 1;
char input;
int isFire = 0;
int nx = 5;
int isKilled = 0;
srand((unsigned int)time(NULL));
while (1)
{
system(“cls”);
printf(“当前得分为:%d\n”, num);
printf(“当前血量为:%d\n”, blood);
if (!isKilled)
{
nx = nx + vx;
for (j = 0; j printf(" “);
printf(” ※\n");
}
if (isFire == 0)
{
for (i = 0; i printf("\n");
}
else
{
for (i = 0; i {
for (j = 0; j printf(" “);
printf(” ●\n");
}
if (x == nx)
blood–, num++;
if (blood == 0)
{
isKilled = 1;
MessageBox(NULL, “你成功击落了”,“系统提醒”, MB_YESNO);
}
isFire = 0;
}
for (j = 0; j <= x; j++)
printf(" ");
printf(“凸”);
if (kbhit())
{
input = getch();
switch (input)
{
case’a’:x–; break;
case’d’:x++; break;
case’w’:y–; break;
case’s’:y++; break;
case’ ‘:isFire = 1; break;
case’r’:isKilled = 0; nx = rand() % 20; break;
}
}
if (nx == 20 || nx == 0)
vx = -vx;
Sleep(100);
}
}
int main()
{
enter();
char gc = getchar();
if (gc == ‘\r’ || gc == ‘\n’) {
times();
}
play();
system(“pause”);
return 0;
}

你可能感兴趣的:(C语言简单的飞机大战源代码)