C语言飞机大战源码
下面是一个简单的C语言飞机大战游戏源码。
游戏免费源码分享网站```c
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#define WIDTH 30
#define HEIGHT 20
#define KEY_UP 72
#define KEY_DOWN 80
#define KEY_LEFT 75
#define KEY_RIGHT 77
#define KEY_SPACE 32
int score = 0;
int gameover = 0;
int bulletX = -1;
int bulletY = -1;
int bulletFired = 0;
int enemyX = -1;
int enemyY = -1;
void gotoxy(int x, int y)
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
void drawBorde
int i;
for (i = 0; i <= HEIGHT + 1; i++)
gotoxy(0, i);
printf("#");
gotoxy(WIDTH + 1, i);
printf("#");
}
for (i = 0; i <= WIDTH + 1; i++)
gotoxy(i, 0);
printf("#");
gotoxy(i, HEIGHT + 1);
printf("#");
}
void drawPlayer(int x, int y)
gotoxy(x, y);
printf("\033[0m");
void drawBullet(int x, int y)
gotoxy(x, y);
printf("\033[0;31m,");
printf("\033[0m");
void drawEnemy(int x, int y)
gotoxy(x, y);
printf("\033[0;33mO");
printf("\033[0m");
void eraseBullet(int x, int y)
gotoxy(x, y);
printf(" ");
void eraseEnemy(int x, int y)
gotoxy(x, y);
printf(" ");
void updateScor
gotoxy(WIDTH + 5, HEIGHT + 2);
printf("Score: %d", score);
int isEnemyKilled(int bulletX, int bulletY, int enemyX, int enemyY)
if (bulletX == enemyX && bulletY == enemyY)
return 1;
}
return 0;
int isGameover(int x, int y)
if (y == HEIGHT , (x == enemyX && y == enemyY))
return 1;
}
return 0;
void movePlayer(int key, int *x, int *y)
eraseBullet(*x, *y);
switch (key)
case KEY_UP:
if (*y > 1)
(*y)--;
}
break;
case KEY_DOWN:
if (*y < HEIGHT)
(*y)++;
}
break;
case KEY_LEFT:
if (*x > 1)
(*x)--;
}
break;
case KEY_RIGHT:
if (*x < WIDTH)
(*x)++;
}
break;
case KEY_SPACE:
if (!bulletFired)
bulletX = *x;
bulletY = *y - 1;
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论