c语言自创军旗游戏源码.zip
立即下载
资源介绍:
c语言自创军旗游戏源码.zip
/* 【自学去】网站收集 http://www.zixue7.com */
#include
#include
#define CHESIZE 40 // 棋盘尺寸,不能随意调整
#define RESETX 170
#define RESETY 350 // 重置原点
typedef enum // 要用到的棋子ID
{
si, jun, shi, lv, tuan,
ying, lian, pai, ban, gong,
fei, chao, zha, qi, lei, bian,
xian, sheng, shen
}CHESSID;
typedef enum // 攻击类型
{
comatt, preatt, noatt
}ATTSTYLE;
typedef enum // 当前游戏方和棋子所属方
{
blue, red, white
}TEAM;
typedef enum // 选中与未选中
{
alchoose, unchoose
}CHOOSESTATE;
typedef enum // 区域状态
{
unknow, empty, exist
}STATE;
typedef struct // 坐标
{
int x;
int y;
}COOR;
typedef struct // 棋子
{
CHESSID id; // 棋子的ID
int power; // 棋子的等级
TEAM team; // 所属方
char *image; // 该棋子的图片,考虑到运行问题,本程序用字代替
int scoopc; // 工兵是挖到的地雷数
}CHESS;
typedef struct // 区域
{
COOR crdld; // 区域的左下坐标
CHESS chess; // 区域的棋子
STATE state; // 区域状态
}AREA;
typedef struct // 用户的选择信息
{
int i;
int j;
CHOOSESTATE state; // 选择状态
}CHOOSE;
IMAGE image;
AREA area[6][6]; // 定义棋盘大小
CHESS datachess[19]; // 几种基本棋子类型
CHOOSE choose; // 用户选择信息
MOUSEMSG mmsg; // 鼠标信息
TEAM user; // 执棋方
int lockchessboard = 0; // 是否锁定棋盘
int i; // 当前鼠标所在区域的坐标
int j;
char *str[]={"工","班","排","连","营","团","旅","师","军","司","棋","炸","变","雷","飞","超","升","神","仙"};
void init();
void initchessbute(); // 给初始化棋子基本参数
void initvalue();
void drawboard(); // 画棋盘
void randomarr(int *); // 实现棋的随机排列
void judge();
void getpreij(); // 获得当前鼠标所在区域坐标
int checkij(); // 检查当鼠标所在区域
void open(); // 打开所在区域
int whemove(); // 判断是否能移动
void move(); // 移动
int judgeunknow(); // 检测当前未翻开棋子数
ATTSTYLE wheattack(); // 判断是否能攻击
void kill(); // 杀死当前选择的棋
void killself(); // 自杀
void perishtogether(); // 同归于尽
void getteam(); // 用作改变棋子类型时,对棋子所属方赋值
void userchange(); // 交换执棋方
void judgebunko(); // 判断输赢
void choosearea(); // 选定区域
void cancelchoose(); // 取消选定
void change(); // 变身
void bluewin(); // 蓝方胜利
void redwin(); // 红方胜利
void gamehelp(); // 规则说明
void quit(); // 退出游戏
void peace(); // 和棋
void surrender(); // 投降
void resetchessboard(); // 重置
// 下面几个函数为判断棋子的攻击类型
ATTSTYLE judgegong(); // 判断工兵
ATTSTYLE judgecom(); // 判普通人物
ATTSTYLE judgezha(); // 判断炸弹
void main() // 主函数
{
init();
while (true)
{
mmsg = GetMouseMsg();
getpreij();
if (mmsg.uMsg == WM_LBUTTONDOWN) //单击左键
{
judge();
}
else if (mmsg.uMsg == WM_RBUTTONDOWN
&& choose.state==alchoose) //单击右键
{
cancelchoose();
}
else if (mmsg.uMsg == WM_MBUTTONDOWN
&& choose.state == alchoose
&& area[choose.i][choose.j].chess.id != zha) //单击中键
{
killself();
cancelchoose();
userchange();
judgebunko();
}
}
}
void init()
{
initgraph(640, 480);
setorigin(RESETX, RESETY); // 重置原点
setaspectratio(1, -1); // 把 y 轴上方设为正半轴
drawboard();
initvalue();
}
void drawboard() // 画棋盘
{
int i1;
setlinecolor(WHITE);
for (i1=0; i1<7; i1++)
{
line(i1*CHESIZE, 0, i1*CHESIZE, CHESIZE*6);
}
for (i1=0; i1<7; i1++)
{
line(0, i1*CHESIZE, CHESIZE*6, i1*CHESIZE);
}
setlinecolor(WHITE);
setfillcolor(RED);
rectangle(-10, -10, CHESIZE*6+10, CHESIZE*6+10);
floodfill(-1, -1, WHITE);
rectangle(7*CHESIZE, CHESIZE, 9*CHESIZE, 6*CHESIZE);
line(7*CHESIZE, 5*CHESIZE, 9*CHESIZE, 5*CHESIZE);
line(7*CHESIZE, 4*CHESIZE, 9*CHESIZE, 4*CHESIZE);
line(7*CHESIZE, 3*CHESIZE, 9*CHESIZE, 3*CHESIZE);
line(7*CHESIZE, 2*CHESIZE, 9*CHESIZE, 2*CHESIZE);
setaspectratio(1, 1);
settextstyle(35, 18, "黑体");
settextcolor(RED);
outtextxy(7*CHESIZE+2, -6*CHESIZE+2, "帮助");
settextcolor(BROWN);
outtextxy(7*CHESIZE+2, -5*CHESIZE+2, "投降");
settextcolor(GREEN);
outtextxy(7*CHESIZE+2, -4*CHESIZE+2, "和棋");
settextcolor(YELLOW);
outtextxy(7*CHESIZE+2, -3*CHESIZE+2, "重置");
settextcolor(CYAN);
outtextxy(7*CHESIZE+2, -2*CHESIZE+2, "退出");
settextcolor(LIGHTMAGENTA);
settextstyle(50, 20, "黑体");
outtextxy(CHESIZE, -CHESIZE*8, "两国军旗");
setaspectratio(1, -1);
}
void initchessbute() // 设置棋子基本参数
{
datachess[0].id = gong;
datachess[0].power = 1;
datachess[0].image = str[0];
datachess[0].scoopc = 0;
datachess[1].id = ban;
datachess[1].power = 2;
datachess[1].image = str[1];
datachess[1].scoopc = 0;
datachess[2].id = pai;
datachess[2].power = 3;
datachess[2].image = str[2];
datachess[2].scoopc = 0;
datachess[3].id = lian;
datachess[3].power = 4;
datachess[3].image = str[3];
datachess[3].scoopc = 0;
datachess[4].id = ying;
datachess[4].power = 5;
datachess[4].image = str[4];
datachess[4].scoopc = 0;
datachess[5].id = tuan;
datachess[5].power = 6;
datachess[5].image = str[5];
datachess[5].scoopc = 0;
datachess[6].id = lv;
datachess[6].power = 7;
datachess[6].image = str[6];
datachess[6].scoopc = 0;
datachess[7].id = shi;
datachess[7].power = 8;
datachess[7].image = str[7];
datachess[7].scoopc = 0;
datachess[8].id = jun;
datachess[8].power = 9;
datachess[8].image = str[8];
datachess[8].scoopc = 0;
datachess[9].id = si;
datachess[9].power = 10;
datachess[9].image = str[9];
datachess[9].scoopc = 0;
datachess[10].id = qi;
datachess[10].power = 100;
datachess[10].image = str[10];
datachess[10].scoopc = 0;
datachess[11].id = zha;
datachess[11].power = 99;
datachess[11].image = str[11];
datachess[11].scoopc = 0;
datachess[12].id = bian;
datachess[12].power = 0;
datachess[12].image = str[12];
datachess[12].scoopc = 0;
datachess[13].id = lei;
datachess[13].power = 98;
datachess[13].image = str[13];
datachess[13].scoopc = 0;
datachess[14].id = fei;
datachess[14].power = 9;
datachess[14].image = str[14];
datachess[14].scoopc = 0;
datachess[15].id = chao;
datachess[15].power = 11;
datachess[15].image = str[15];
datachess[15].scoopc = 0;
datachess[16].id = sheng;
datachess[16].power = 10;
datachess[16].image = str[16];
datachess[16].scoopc = 0;
datachess[17].id = shen;
datachess[17].power = 11;
datachess[17].image = str[17];
datachess[17].scoopc = 0;
datachess[18].id = xian;
datachess[18].power = 11;
datachess[18].image = str[18];
datachess[18].scoopc = 0;
}
void initvalue() // 初始化值
{
CHESS chess[36];
int random[36];
int count;
int i1, j1;
initchessbute();
randomarr(random);
for (i1=0; i1<=11; i1++)
{
chess[i1] = datachess[i1];
chess[i1].team = red;
}
chess[i1] = datachess[11];
chess[i1].team = red;
chess[i1+1] = datachess[0];
chess[i1+1].team = red;
for (i1=0; i1<=11; i1++)
{
chess[i1+14] = datachess[i1];
chess[i1+14].team = blue;
}
chess[i1+14] = datachess[11];
chess[i1+14].team = blue;
chess[i1+15] = datachess[0];
chess[i1+15].team = blue;
for (i1=0; i1<4; i1++)
{
chess[i1+28] = datachess[12];
chess[i1+28].team = white;
chess[i1+32] = datachess[13];
chess[i1+32].team = white;
}
setfillcolor(YELLOW);
for (count=0, i1=0; i1<6; i1++)
{
for (j1=0; j1<6; j1++, count++)
{
area[i1][j1].chess = chess[random[count]];
area[i1][j1].crdld.x = i1 * CHESIZE + 1;
area[i1][j1].crdld.y = j1 * CHESIZE + 1;
area[i1][j1].state = unknow;
floodfill(area[i1][j1].crdld.x, area[i1][j1].crdld.y, WHITE);
}
}
user = red;
choose.state = unchoose;
}
void randomarr(int random[]) // 得到0~36数字的随机排列
{
int i1, j1;
int flag = 0;