C语言代码实现飞机大战 您所在的位置:网站首页 飞机大战的游戏说明 C语言代码实现飞机大战

C语言代码实现飞机大战

2023-09-20 09:57| 来源: 网络整理| 查看: 265

本文实例为大家分享了C语言实现简单飞机大战的具体代码,供大家参考,具体内容如下

这个游戏的功能很单一,也就是“飞机大战”,哈哈哈哈。总共只有300多行代码左右,你也可以想想它会有多简陋,把它复制下来编译一下可以直接执行,需要的同学可以自取~

PS:我运行的环境是 dev c++,前提你要在C99的环境中执行

以下是源代码

#include #include #include //将用户从键盘获得的输入进行输出 #include //获得用户键盘的输入 //定义全局变量 int high,width; //定义边界 int position_x,position_y; //飞机位置 int bullet_x,bullet_y; //子弹位置 int enemy_x,enemy_y; //敌军飞机 int score; //获得分数 int flag; //飞机状态 void gotoxy(int x,int y); //光标移动到(x,y)位置 void welcometogame(); //初始化界面 int color(int c); //更改文字颜色 void explation(); //游戏右侧显示 void scoreandtips(); //显示游戏提示 void show(); //显示游戏界面 void endgame(); //游戏结束 /** * 文字颜色函数 */ int color(int c) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c); //更改文字颜色 return 0; } /** * 设置光标位置 */ void gotoxy(int x,int y) { COORD c; c.X=x; c.Y=y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c); } void welcometogame() //开始界面 { int n; color(15); gotoxy(43,10); printf("飞 机 大 战"); color(11); gotoxy(25, 22); printf("1.开始游戏"); gotoxy(45, 22); printf("2.游戏说明"); gotoxy(65, 22); printf("3.退出游戏"); gotoxy(40,27); color(3); printf("请选择 1 2 3:"); color(14); scanf("%d", &n); //输入选项 switch (n) { case 1: system("cls"); show(); break; case 2: explation(); //游戏说明函数 break; case 3: exit(0); //退出游戏 break; default: color(12); gotoxy(40,28); printf("请输入1-3之间的数!"); _getch(); //输入任意键 system("cls"); //清屏 welcometogame(); } } void explation() //游戏提示 { int i,j = 1; system("cls"); color(10); gotoxy(44,1); printf("游戏说明"); color(2); for (i = 3; i


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有