#include<stdio.h>


#include<string.h>


#include<conio.h>


#include<windows.h>


#include<stdlib.h>


#define MAX 100


long long int speed = 0;//控制敌机的速度?


int position_x, position_y;//飞机的所在位置?


int high, width;//地图的大小?


int bullet_x, bullet_y;//子弹的位置?


int enemy_x, enemy_y;//敌人的位置?


int map[MAX][MAX];


/*0表示空白,1表示战机*的区域,2表示敌人战机的位置。


3表示上下围墙,4表示左右围墙,5表示子弹的位置*/


int score;


void starup()//初始化所有的信息?


{


high = 20;


 width = 30;


 position_x = high / 2;


 position_y = width / 2;


  bullet_x = 0;


  bullet_y = position_y;


 enemy_x = 2;


  enemy_y = position_y - 1;


  score = 0;




}


void startMap()


{


  int i, j;


 for (i = 1; i <= high - 1; i++)


 {


 map[i][1] = 4;


 for (j = 2; j <= width - 1; j++)


 map[i][j] = 0;


 map[i][width] = 4;


 }


 i = high;


 for (j = 1; j <= width; j++)


 map[i][j] = 3;




 map[bullet_x][bullet_y] = 5;


 map[position_x - 1][position_y] = 1;


 i = position_x;


 for (j = position_y - 2; j <= position_y + 2; j++)


 map[i][j] = 1;


 map[position_x + 1][position_y - 1] = 1;


 map[position_x + 1][position_y + 1] = 1;


 map[enemy_x][enemy_y] = 2;


 map[enemy_x - 1][enemy_y - 1] = 2;


 map[enemy_x - 1][enemy_y + 1] = 2;




}


void HideCursor(){


 CONSOLE_CURSOR_INFO cursor_info = { 1, 0 };


 SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);


}


void gotoxy(int x, int y){


 HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);


 COORD pos;


 pos.X = x;


 pos.Y = y;


 SetConsoleCursorPosition(handle, pos);


}


void updateWithoutInput(){


 if (bullet_x > 0)


 bullet_x--;


 if ((bullet_x == enemy_x) && (bullet_y == enemy_y))


 {


 score++;


 enemy_x = 0;


 enemy_y = rand() % width;


 bullet_x = 0;


 }


 if (enemy_x > high){


 enemy_x = 0;


 enemy_y = rand() % width;


 }


 if (speed == 1)


 for (int i = 1; i <= 10000; i++){


for (int j = 1; j <= 1000; j++)


 {


 speed = 1;


  }

 }


 speed = 0;


 if (speed == 0)


 {


 enemy_x++;


 speed = 1;


}


}


void updateWithInput(){

char input;


 if (kbhit())


 {


 input = getch();


if (input == 'a')


 position_y--;


 if (input == 's')


 position_x++;


 if (input == 'd')


 position_y++;


 if (input == 'w')


 position_x--;


 if (input == ' ')


 {


 bullet_x = position_x - 1;


 bullet_y = position_y;


 }


 }


}

void show() {


 gotoxy(0, 0);


 int i, j;


 for (i = 1; i <= high; i++)


 {


 for (j = 1; j <= width; j++)


 {


 if (map[i][j] == 0)


 printf(" ");


 if (map[i][j] == 1)


 printf("*");


 if (map[i][j] == 2)


 printf("#");

 if (map[i][j] == 3)


 printf("~");


 if (map[i][j] == 4)


 printf("|");


 if (map[i][j] == 5)


 printf("|");


 }


 printf("\n");


 }


 printf("\n你的得分:%d\n\n", score);


 printf("操作说明: ASDW分别操作 左下右上四个的移动\n");


 printf("**空格是发出子弹**\n");


}


int main()


{


 starup();


while (1)


 {


 HideCursor();


startMap();


 show();


 updateWithoutInput();


 updateWithInput();


 }

return 0;


点赞(0)
 

0.0分

2 人评分

C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:

一点编程也不会写的:零基础C语言学练课程

解决困扰你多年的C语言疑难杂症特性的C语言进阶课程

从零到写出一个爬虫的Python编程课程

只会语法写不出代码?手把手带你写100个编程真题的编程百练课程

信息学奥赛或C++选手的 必学C++课程

蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程

手把手讲解近五年真题的蓝桥杯辅导课程

评论列表 共有 3 条评论

管理员 1年前 回复TA
好的,我立刻处理
codebris 1年前 回复TA
include后面的东西没了,可能重新编辑的时候被卡掉了,我也被卡掉过。
管理员 1年前 回复TA
代码制作不易,请多多点赞