网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
正文
#define \_CRT\_SECURE\_NO\_WARNINGS 1
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
void target(int target_x, int target_y)//生成目标
{
int i = 0;
for (i = 1; i < target_y; i++)
printf("\n");
for (i = 1; i < target_x; i++)
printf("%c", 32);
printf("+\n");
}
void plane(int plane_x, int plane_y, int isfire)//生成飞机
{
int i = 0;
int j = 0;
for (i = 1; i < plane_y - 2; i++)
printf("\n");
if (isfire)//如果开火,显示竖线
{
for (j = 1; j < plane_x; j++)
putchar(32);
putchar('|');
}
printf("\n");
for (j = 1; j < plane_x; j++)
putchar(32);
putchar('\*');
printf("\n");
for (j = 1; j < plane_x - 2; j++)
putchar(32);
printf("\*\*\*\*\*\n");
for (j = 1; j < plane_x - 1; j++)
putchar(32);
printf("\* \*\n");
}
void game()//游戏主程序
{
int i = 0;
int isfire = 0;
int score = 0;//接收分数
int plane_x = 10;//飞机横坐标
int plane_y = 10;//飞机纵坐标
int target_x = 3;//目标横坐标
int target_y = 3;//目标纵坐标
int x = 0;
int y = 0;
srand((unsigned int)time(NULL));
target_x = rand() % 100 + 2;
target_y = rand() % (plane_y - 5) + 1;
target(target_x, target_y);
plane(plane_x, plane_y - target_y + 1, isfire);
while (1)
{
system("cls");
target(target_x, target_y);
plane(plane_x, plane_y, isfire);
for (i = 0; i < 20 - plane_y; i++)
printf("\n");
for (i = 0; i < 99; i++)
putchar(32);
printf("score: %d\n", score);
isfire = 0;
char key = \_getch();
switch (key)//判断按键信息
{
case 'w':
case 'W':
plane_y--; break;
case 's':
case 'S':
plane_y++; break;
case 'a':
case 'A':
plane_x--; break;
case 'd':
case 'D':
plane_x++; break;
case ' ':
isfire = 1;
}
if (isfire && plane_x == target_x)//如果击中目标,生成下一个目标
{
target_x = rand() % 100 + 2;
target_y = rand() % (plane_y - 5) + 1;
score++;
}
if (key == 'E' || key == 'e')break;//如果按下E或e,结束本次游戏
}
}
void menu()//打印菜单栏
{
printf("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\n");
![img](https://img-blog.csdnimg.cn/img_convert/53b44c0ffe4ea16c11235f8a3f6b8072.png)
![img](https://img-blog.csdnimg.cn/img_convert/2f2480300b88e51270570acdc1a083a9.png)
**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**
**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618545628)**
**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**
cs/618545628)**
**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**