好久没给大家看有意思的C语言实现的代码了,今天给大家分享一个C语言实现坦克大战的游戏源码,依旧是纯C语言,点c文件,但是是在VS2013的环境下,运行效果截图如下:
上下左右控制方向,空格为发射炮弹,还带声音哦!
小编亲自没有问题,大家可以自行上机实验,编译器下载见
C/C++开发和学习人员必备工具下载集合
/* time:2017/1/15 */
/* edit:www.dotcpp.com */
#include <graphics.h>
#include <stdlib.h>
#include <dos.h>
#include <conio.h>
#include <bios.h>
#define KEY_ESC 0x01
#define KEY_SPACE 0x39
#define KEY_UP 0x48
#define KEY_LEFT 0x4b
#define KEY_RIGHT 0x4d
#define KEY_DOWN 0x50
int map[20][20]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,2,2,2,2,0,0,2,2,2,2,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,2,0,0,2,0,1,1,1,1,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,2,2,2,2,2,2,2,0,0,0,0,0,0,0,2,2,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,0,1,
1,0,1,1,1,1,3,3,3,3,0,0,0,0,0,0,0,2,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,3,3,3,0,1,
1,0,0,0,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,3,3,3,1,1,1,1,1,1,1,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,2,2,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,1,
1,0,2,2,0,0,0,0,2,2,2,0,0,0,2,2,0,0,0,1,
1,0,0,0,0,0,0,8,2,5,2,0,0,0,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
struct f
{
int x;
int y;
int direction;
};
struct play
{
int x;
int y;
int direction;
struct f fire[5];
int score;
}Playone;
struct a
{
int x;
int y;
int color;
int direction;
int directiontwo;
int fireplay;
struct f fire;
}amy[5];
char key_state[128],key_pressed[128];
void Init();
void End();
void DrawMap();
void DrawWater(int x,int y);
void DrawBrick(int x,int y);
void DrawTone(int x,int y);
void DrawHome(int x,int y);
void DrawBlack(int x,int y);
void DrawPlay(int x,int y);
void DrawAmy(int x,int y,int i);
void Score();
void GamePlay();
void GameOver();
void TimeDelay(unsigned long microsec);
int GetKey(int ScanCode);
void interrupt far (*OldInt9Handler)();
void far interrupt NewInt9();
void InstallKeyboard();
void ShutDownKeyboard();
void main(void)
{
Init();
DrawMap();
GamePlay();
End();
}
void TimeDelay(unsigned long microsec)
{
union REGS r;
r.h.ah=0x86;
r.x.cx=microse