地空对决: /******************************************************************************* **程序名称:地空对决 **程序描述:敌军大批飞机前来空袭,我方高炮奋力反击…… **程序作者:宋元瑞 **技术指导:3+1 **最后修改:2009-4-4 *******************************************************************************/ #include <conio.h> #include <graphics.h> #include <stdlib.h> #include <dos.h> #define LEFT 0x4b00 #define RIGHT 0x4d00 #define UP 0x4800 #define BANK 14624 #define ESC 0x011b #define closegr closegraph /*设定初始化开关参数*/ int tankstart=0,planstart=0; int first=1; /******************************************************************************* ** 函数名称:drawmat ** 函数描述:依次:字模指针、点阵大小、起始坐标(x,y)、颜色 ** 输入参数:*mat,matsize,x,y,color ** 输出参数:无 *******************************************************************************/ void drawmat(char *mat,int matsize,int x,int y,int color) /*依次:字模指针、点阵大小、起始坐标(x,y)、颜色*/ { int i, j, k, n; n = (matsize - 1) / 8 + 1; for(j = 0; j < matsize; j++) for(i = 0; i < n; i++) for(k = 0;k < 8; k++) if(mat[j * n + i] & (0x80 >> k)) /*测试为1的位则显示*/ putpixel(x + i * 8 + k, y + j, color); } /*以下是字库*/ char di64H[]={ /* 以下是 '地' 的 64点阵华文行楷 字模,512 byte */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x3C,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x7E,0x00,0x00,0x00, 0x00,0x18,0x00,0x00,0x7F,0x00,0x00,0x00, 0x00,0x3F,0x00,0x00,0x7F,0x00,0x00,0x00, 0x00,0x1F,0x80,0x00,0x7F,0x00,0x00,0x00, 0x00,0x0F,0xE0,0x00,0x1F,0x00,0x00,0x00, 0x00,0x0F,0xE0,0x00,0x1E,0x1E,0x00,0x00, 0x00,0x07,0xF0,0x00,0x1E,0x7F,0x80,0x00, 0x00,0x07,0xF0,0x00,0x1C,0xFF,0xC0,0x00, 0x00,0x07,0xF0,0x00,0x1F,0xC7,0xE0,0x00, 0x00,0x07,0xF0,0x00,0x1F,0x87,0xF0,0x00, 0x00,0x07,0xFE,0x00,0x1F,0x07,0xF0,0x00, 0x00,0x07,0xFE,0x08,0x1E,0x07,0xE0,0x00, 0x00,0x07,0xFE,0x3C,0x3C,0x07,0xE0,0x00, 0x00,0x0F,0xFE,0x3C,0x7C,0x0F,0xC0,0x00, 0x00,0x1F,0xFE,0x3F,0xFC,0x0F,0xC0,0x00, 0x00,0x7F,0xF8,0x3F,0xFC,0x0F,0xC0,0x00, 0x00,0xFF,0xE0,0x1F,0xFC,0x1F,0x80,0x00, 0x03,0xFF,0xE0,0x1F,0xFC,0x1F,0x80,0x00, 0x0F,0xFF,0xE0,0x1F,0xBC,0x3F,0x00,0x00, 0x07,0xFF,0xE0,0x3F,0x3C,0x3F,0x00,0x00, 0x03,0xFF,0xE0,0x7E,0x3C,0x7F,0x00,0x00, 0x01,0xFF,0xE0,0xFE,0x38,0x7E,0x00,0x00, 0x00,0xFF,0xE1,0xFF,0x3F,0xFE,0x00,0x00, 0x00,0x0F,0xE3,0xF8,0xFF,0xFC,0x00,0x00, 0x00,0x0F,0xFE,0x30,0xFF,0xFC,0x00,0x00, 0x00,0x0F,0xFC,0x30,0x78,0xF8,0x00,0x00, 0x00,0x0F,0xFC,0x70,0x70,0xF0,0x00,0x08, 0x00,0x0F,0xF8,0x70,0x30,0x60,0x00,0x08, 0x00,0x0F,0xF8,0x70,0x30,0x00,0x00,0x18, 0x00,0x3F,0xF0,0x30,0x00,0x00,0x00,0x38, 0x00,0x7F,0xE0,0x30,0x00,0x00,0x00,0x7C, 0x01,0xFF,0x80,0x30,0x00,0x00,0x01,0xFC, 0x03,0xFF,0x00,0x38,0x00,0x00,0x07,0xFC, 0x07,0xFE,0x00,0x1F,0x00,0x00,0xFF,0xFC, 0x03,0xF8,0x00,0x0F,0xFF,0xFF,0xFF,0xFC, 0x01,0xF0,0x00,0x07,0xFF,0xFF,0xFF,0xF8, 0x00,0xE0,0x00,0x01,0xFF,0xFF,0xFF,0xC0, 0x00,0x40,0x00,0x00,0x3F,0xFF,0xE0,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; char kong64H[]={ /* 以下是 '空' 的 64点阵华文行楷 字模,512 byte */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x78,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x3E,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x1F,0x80,0x00,0x00,0x00, 0x00,0x00,0x00,0x0F,0x80,0x00,0x00,0x00, 0x00,0x00,0x00,0x0F,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x07,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x07,0xC0,0x7F,0xC0,0x00, 0x00,0x02,0x00,0x07,0xFF,0xFF,0xE0,0x00, 0x00,0x03,0x00,0x1F,0xFF,0xFF,0xF0,0x00, 0x00,0x03,0x03,0xFF,0xFE,0x00,0xF8,0x00, 0x00,0x03,0x3F,0xFF,0x80,0x01,0xF8,0x00, 0x00,0x03,0xFF,0xF8,0x00,0x03,0xFC,0x00, 0x00,0x03,0xFF,0xC0,0x20,0x07,0xFE,0x00, 0x00,0x07,0x81,0x00,0x78,0x1F,0xFC,0x00, 0x00,0x07,0x81,0x00,0x7C,0xFF,0xFC,0x00, 0x00,0x0F,0x01,0xC0,0x3F,0xFF,0xF8,0x00, 0x00,0x1F,0x01,0xE0,0x3E,0x3F,0x00,0x00, 0x00,0x3F,0x00,0xE0,0x3E,0x00,0x00,0x00, 0x00,0x3E,0x00,0xF0,0x3E,0x00,0x00,0x00, 0x00,0x3E,0x00,0xF0,0x3C,0x00,0x00,0x00, 0x00,0x3E,0x01,0xF8,0x3C,0x00,0x00,0x00, 0x00,0x3C,0x01,0xF0,0x3F,0x80,0x00,0x00, 0x00,0x3C,0x03,0xF0,0x3F,0xC0,0x00,0x00, 0x00,0x38,0x0F,0xE0,0x1F,0xE0,0x00,0x00, 0x00,0x38,0x1F,0xC0,0x1F,0xF0,0x00,0x00, 0x00,0x10,0x3F,0x80,0x0F,0xF0,0x00,0x00, 0x00,0x00,0x3F,0x00,0x0F,0xE0,0x00,0x00, 0x00,0x00,0x3E,0x00,0x1F,0x80,0x00,0x00, 0x00,0x00,0x3C,0x00,0x3C,0x00,0x00,0x00, 0x00,0x00,0x30,0x00,0xF0,0x00,0x00,0x00, 0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x1C,0x18,0x00,0x00,0x00, 0x00,0x00,0x00,0x60,0x7E,0x00,0x00,0x00, 0x00,0x00,0x00,0x81,0xFF,0x00,0x00,0x00, 0x00,0x00,0x01,0xFF,0xFF,0x00,0x00,0x00, 0x00,0x00,0x01,0xFF,0xFF,0x00,0x00,0x00, 0x00,0x00,0x01,0xFF,0xFE,0x00,0x00,0x00, 0x00,0x00,0x01,0xFC,0xFC,0x00,0x00,0x00, 0x00,0x00,0x00,0x61,0xF8,0x00,0x00,0x00, 0x00,0x00,0x00,0x01,0xF0,0x00,0x00,0x00, 0x00,0x00,0x00,0x03,0xF0,0x00,0x00,0x00, 0x00,0x00,0x00,0x07,0xE0,0x00,0x00,0x00, 0x00,0x00,0x00,0x0F,0xC0,0xFC,0x00,0x00, 0x00,0x00,0x00,0x1F,0xFF,0xFF,0x00,0x00, 0x00,0x00,0x01,0xFF,0xFF,0xFF,0x80,0x00, 0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xC0,0x00, 0x00,0x03,0xFF,0xFF,0xFF,0xFF,0xC0,0x00, 0x00,0x03,0xFF,0xFC,0x00,0x1F,0xE0,0x00, 0x00,0x01,0xFF,0x80,0x00,0x03,0xC0,0x00, 0x00,0x01,0xFC,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; char dui64H[]={ /* 以下是 '对' 的 64点阵华文行楷 字模,512 byte */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x7C,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x0E,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x07,0x80,0x00, 0x00,0x00,0x00,0x00,0x00,0x07,0x80,0x00, 0x00,0x00,0x00,0x00,0x00,0x07,0x80,0x00, 0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00, 0x00,0x00,0x03,0xE0,0x00,0x07,0x00,0x00, 0x00,0x00,0x07,0xF0,0x00,0x07,0x0F,0x00, 0x00,0x00,0x1F,0xF8,0x00,0x07,0xFF,0x80, 0x00,0x00,0x7F,0xFC,0x00,0x07,0xFF,0xC0, 0x00,0x03,0xFF,0xFE,0x00,0x0F,0xFF,0xC0, 0x00,0x01,0xFF,0xFE,0x00,0x7F,0xFF,0xC0, 0x00,0x01,0xFF,0xFE,0x01,0xFF,0xFF,0x80, 0x00,0x00,0xFF,0xFC,0x07,0xFF,0xC0,0x00, 0x00,0x00,0x7F,0xFC,0x1F,0xFF,0x00,0x00, 0x00,0x00,0x1F,0xF8,0x7F,0xE7,0x00,0x00, 0x00,0x00,0x00,0xF8,0xFF,0xC7,0x00,0x00, 0x00,0x00,0x01,0xF1,0xFF,0x07,0x00,0x00, 0x00,0x00,0x01,0xE1,0xFE,0x07,0x00,0x00, 0x00,0x00,0x03,0xE3,0x00,0x07,0x00,0x00, 0x00,0x0F,0xF3,0xC4,0x00,0x07,0x00,0x00, 0x00,0xFF,0xFF,0xC8,0x00,0x07,0x00,0x00, 0x01,0xFF,0xFF,0x80,0x00,0x07,0x00,0x00, 0x00,0x1F,0xFF,0xF0,0x7C,0x07,0x00,0x00, 0x00,0x00,0xFF,0xF0,0xFE,0x07,0x00,0x00, 0x00,0x00,0x3F,0xF8,0x7F,0x03,0x00,0x00, 0x00,0x00,0x7F,0xF8,0x3F,0x03,0x00,0x00, 0x00,0x00,0x7C,0xFC,0x1F,0x83,0x00,0x00, 0x00,0x00,0xF8,0x7C,0x0F,0x83,0x80,0x00, 0x00,0x01,0xF8,0x3E,0x03,0x03,0x80,0x00, 0x00,0x07,0xF0,0x1E,0x00,0x03,0x80,0x00, 0x01,0xFF,0xE0,0x1E,0x00,0x03,0x80,0x00, 0x00,0xFF,0x80,0x0E,0x00,0x03,0x80,0x00, 0x00,0x7F,0x00,0x00,0x00,0x03,0x80,0x00, 0x00,0x38,0x00,0x00,0x00,0x03,0x80,0x00, 0x00,0x00,0x00,0x00,0x10,0x03,0x80,0x00, 0x00,0x00,0x00,0x00,0x0C,0x03,0x80,0x00, 0x00,0x00,0x00,0x00,0x07,0x83,0x80,0x00, 0x00,0x00,0x00,0x00,0x07,0xFF,0x80,0x00, 0x00,0x00,0x00,0x00,0x03,0xFF,0x80,0x00, 0x00,0x00,0x00,0x00,0x01,0xFF,0x80,0x00, 0x00,0x00,0x00,0x00,0x00,0xFF,0x80,0x00, 0x00,0x00,0x00,0x00,0x00,0x7F,0x80,0x00, 0x00,0x00,0x00,0x00,0x00,0x3F,0x80,0x00, 0x00,0x00,0x00,0x00,0x00,0x1F,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x0F,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; char jue64H[]={ /* 以下是 '决' 的 64点阵华文行楷 字模,512 byte */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00, 0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x03,0xE0,0x00,0x00,0x00, 0x00,0x00,0x00,0x03,0xF0,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x78,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x7C,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x7C,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x7C,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x7C,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x78,0x20,0x00,0x00, 0x00,0x00,0x00,0x00,0x78,0xF8,0x00,0x00, 0x00,0x03,0xC0,0x00,0x7F,0xFC,0x00,0x00, 0x00,0x01,0xF0,0x00,0xFF,0xFE,0x00,0x00, 0x00,0x01,0xFC,0x00,0xFF,0xFF,0x00,0x00, 0x00,0x00,0xFC,0x00,0xFF,0xFF,0x80,0x00, 0x00,0x00,0xFE,0x03,0xFF,0x3F,0x80,0x00, 0x00,0x00,0x7E,0x1F,0xFE,0x3F,0x80,0x00, 0x00,0x00,0x7E,0x3F,0xF8,0x7F,0x80,0x00, 0x00,0x00,0xFE,0x0F,0xF0,0x7E,0x00,0x00, 0x00,0x00,0xF8,0x01,0xF0,0xFC,0x00,0x00, 0x00,0x01,0xC0,0x01,0xC0,0xF0,0x00,0x00, 0x00,0x03,0x00,0x01,0xC3,0xE0,0x00,0x00, 0x00,0x02,0x00,0x01,0xC1,0xE0,0x00,0x00, 0x00,0x04,0x00,0x01,0xC3,0xFF,0xC0,0x00, 0x00,0x00,0x00,0x01,0xC7,0xFF,0xF0,0x00, 0x00,0x00,0x00,0x03,0xFF,0xFF,0xF0,0x00, 0x00,0x00,0x10,0x03,0xFF,0xFF,0xF8,0x00, 0x00,0x00,0x20,0x03,0xFF,0xFF,0xF8,0x00, 0x00,0x00,0x60,0x0F,0xFF,0x80,0x10,0x00, 0x00,0x00,0x40,0x7F,0xFC,0x00,0x00,0x00, 0x00,0x00,0xC1,0xFF,0xE0,0x00,0x00,0x00, 0x00,0x01,0xC7,0xFF,0x80,0x00,0x00,0x00, 0x00,0x03,0xC7,0xFF,0x00,0x00,0x00,0x00, 0x00,0x07,0xC3,0xFF,0x00,0x00,0x00,0x00, 0x00,0x0F,0x80,0x0F,0x00,0x00,0x00,0x00, 0x00,0x3F,0x80,0x0F,0x00,0x00,0x00,0x00, 0x00,0x3F,0x80,0x0F,0x03,0x80,0x00,0x00, 0x00,0x3F,0x80,0x1E,0x01,0xFE,0x00,0x00, 0x00,0x1F,0x80,0x1E,0x00,0xFF,0x80,0x00, 0x00,0x1F,0x80,0x3C,0x00,0xFF,0x80,0x00, 0x00,0x0F,0x80,0x7C,0x00,0x7F,0xC0,0x00, 0x00,0x03,0x00,0xF8,0x00,0x3F,0xC0,0x00, 0x00,0x00,0x01,0xF0,0x00,0x1F,0xC0,0x00, 0x00,0x00,0x0F,0xE0,0x00,0x07,0xC0,0x00, 0x00,0x00,0x1F,0x80,0x00,0x03,0xC0,0x00, 0x00,0x00,0x06,0x00,0x00,0x01,0xC0,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; char song16S[]={ /* 以下是 '宋' 的 16点阵宋体 字模,32 byte */ 0x02,0x00,0x01,0x00,0x7F,0xFE,0x41,0x04, 0x81,0x08,0x01,0x00,0x7F,0xFC,0x03,0x80, 0x05,0x80,0x05,0x40,0x09,0x20,0x11,0x10, 0x21,0x0E,0x41,0x04,0x01,0x00,0x00,0x00, }; char yuan16S[]={ /* 以下是 '元' 的 16点阵宋体 字模,32 byte */ 0x00,0x00,0x1F,0xF8,0x00,0x00,0x00,0x00, 0x00,0x00,0x7F,0xFE,0x04,0x40,0x04,0x40, 0x04,0x40,0x04,0x40,0x08,0x40,0x08,0x40, 0x10,0x42,0x20,0x42,0x40,0x3E,0x00,0x00, }; char rui16S[]={ /* 以下是 '瑞' 的 16点阵宋体 字模,32 byte */ 0x00,0x20,0xF9,0x24,0x21,0x24,0x21,0x24, 0x21,0xFC,0x20,0x00,0xFB,0xFE,0x20,0x40, 0x23,0xFE,0x22,0x52,0x2A,0x52,0x32,0x52, 0xC2,0x52,0x02,0x52,0x02,0x4A,0x02,0x04, }; char zhi16S3[]={ /* 以下是 '指' 的 16点阵宋体 字模,32 byte */ 0x11,0x00,0x11,0x38,0x11,0xC0,0x11,0x04, 0xFD,0x04,0x11,0xFC,0x14,0x00,0x19,0xFC, 0x31,0x04,0xD1,0x04,0x11,0xFC,0x11,0x04, 0x11,0x04,0x11,0x04,0x51,0xFC,0x20,0x00, }; char dao16S[]={ /* 以下是 '导' 的 16点阵宋体 字模,32 byte */ 0x00,0x00,0x1F,0xF0,0x10,0x10,0x1F,0xF0, 0x10,0x04,0x10,0x04,0x0F,0xFC,0x00,0x20, 0x00,0x20,0xFF,0xFE,0x08,0x20,0x04,0x20, 0x06,0x20,0x04,0x20,0x00,0xA0,0x00,0x40, }; char liu16S[]={ /* 以下是 '刘' 的 16点阵宋体 字模,32 byte */ 0x10,0x04,0x08,0x04,0x04,0x04,0x7F,0xA4, 0x01,0x24,0x21,0x24,0x12,0x24,0x0A,0x24, 0x04,0x24,0x06,0x24,0x0A,0x24,0x11,0x04, 0x21,0x84,0x41,0x14,0x80,0x08,0x00,0x00, }; char chuan16S[]={ /* 以下是 '传' 的 16点阵宋体 字模,32 byte */ 0x10,0x40,0x18,0x48,0x17,0xFC,0x20,0x40, 0x20,0x80,0x60,0x84,0xAF,0xFE,0x20,0x80, 0x21,0x08,0x23,0xFC,0x20,0x08,0x21,0x10, 0x20,0xA0,0x20,0x40,0x20,0x20,0x00,0x00, }; char yao16S[]={ /* 以下是 '耀' 的 16点阵宋体 字模,32 byte */ 0x13,0xDC,0x12,0x44,0x95,0x54,0x54,0xCC, 0x11,0x54,0xFE,0xC4,0x29,0x20,0x29,0xFC, 0x2B,0x20,0x2D,0xFC,0x29,0x20,0x2B,0xFC, 0x5D,0x20,0x49,0x20,0x81,0xFE,0x01,0x00, }; char jiang16S[]={ /* 以下是 '江' 的 16点阵宋体 字模,32 byte */ 0x20,0x00,0x10,0x00,0x13,0xFC,0x00,0x40, 0x88,0x40,0x48,0x40,0x50,0x40,0x10,0x40, 0x10,0x40,0x20,0x40,0xE0,0x40,0x20,0x40, 0x20,0x40,0x2F,0xFE,0x20,0x00,0x00,0x00, }; char xi16S[]={ /* 以下是 '西' 的 16点阵宋体 字模,32 byte */ 0x00,0x00,0xFF,0xFE,0x04,0x40,0x04,0x40, 0x7F,0xFC,0x44,0x44,0x44,0x44,0x44,0x44, 0x44,0x44,0x48,0x3C,0x50,0x04,0x60,0x04, 0x40,0x04,0x7F,0xFC,0x40,0x04,0x00,0x00, }; char li16S[]={ /* 以下是 '理' 的 16点阵宋体 字模,32 byte */ 0x00,0x00,0x03,0xFC,0xFA,0x44,0x22,0x44, 0x23,0xFC,0x22,0x44,0xFA,0x44,0x23,0xFC, 0x22,0x44,0x20,0x40,0x23,0xFC,0x38,0x40, 0xC0,0x40,0x00,0x40,0x0F,0xFE,0x00,0x00, }; char gong16S[]={ /* 以下是 '工' 的 16点阵宋体 字模,32 byte */ 0x00,0x00,0x3F,0xFC,0x01,0x00,0x01,0x00, 0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00, 0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00, 0x01,0x00,0xFF,0xFE,0x00,0x00,0x00,0x00, }; char xue16S[]={ /* 以下是 '学' 的 16点阵宋体 字模,32 byte */ 0x01,0x08,0x10,0x8C,0x0C,0xC8,0x08,0x90, 0x7F,0xFE,0x40,0x04,0x8F,0xE8,0x00,0x40, 0x00,0x80,0x7F,0xFE,0x00,0x80,0x00,0x80, 0x00,0x80,0x00,0x80,0x02,0x80,0x01,0x00, }; char dian16S[]={ /* 以下是 '电' 的 16点阵宋体 字模,32 byte */ 0x01,0x00,0x01,0x00,0x01,0x00,0x3F,0xF8, 0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x08, 0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x08, 0x01,0x02,0x01,0x02,0x00,0xFE,0x00,0x00, }; char zi16S[]={ /* 以下是 '子' 的 16点阵宋体 字模,32 byte */ 0x00,0x00,0x3F,0xF0,0x00,0x20,0x00,0x40, 0x00,0x80,0x01,0x00,0x01,0x00,0x01,0x04, 0xFF,0xFE,0x01,0x00,0x01,0x00,0x01,0x00, 0x01,0x00,0x01,0x00,0x05,0x00,0x02,0x00, }; char xin16S[]={ /* 以下是 '信' 的 16点阵宋体 字模,32 byte */ 0x08,0x80,0x0C,0x60,0x18,0x40,0x17,0xFE, 0x30,0x00,0x33,0xF8,0x50,0x00,0x93,0xF8, 0x10,0x00,0x13,0xF8,0x12,0x08,0x12,0x08, 0x12,0x08,0x13,0xF8,0x12,0x08,0x00,0x00, }; char xi16S2[]={ /* 以下是 '息' 的 16点阵宋体 字模,32 byte */ 0x01,0x00,0x02,0x00,0x1F,0xF0,0x10,0x10, 0x1F,0xF0,0x10,0x10,0x1F,0xF0,0x10,0x10, 0x1F,0xF0,0x00,0x00,0x09,0x00,0x28,0x84, 0x28,0x92,0x68,0x12,0x07,0xF0,0x00,0x00, }; char ke16S[]={ /* 以下是 '科' 的 16点阵宋体 字模,32 byte */ 0x06,0x08,0x78,0x88,0x08,0x48,0x08,0x48, 0xFE,0x08,0x18,0x88,0x1C,0x48,0x2A,0x48, 0x28,0x0E,0x48,0x78,0x8B,0x88,0x08,0x08, 0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08, }; char yu16S[]={ /* 以下是 '与' 的 16点阵宋体 字模,32 byte */ 0x00,0x00,0x08,0x00,0x08,0x04,0x0F,0xFE, 0x08,0x00,0x08,0x00,0x0F,0xFC,0x00,0x04, 0x00,0x04,0x00,0x24,0x7F,0xF4,0x00,0x04, 0x00,0x04,0x00,0x48,0x00,0x30,0x00,0x00, }; char ji16S[]={ /* 以下是 '技' 的 16点阵宋体 字模,32 byte */ 0x10,0x20,0x10,0x20,0x10,0x20,0xFD,0xFE, 0x10,0x20,0x14,0x20,0x19,0xFC,0x31,0x08, 0xD0,0x88,0x10,0x90,0x10,0x60,0x10,0x60, 0x10,0x90,0x11,0x0E,0x56,0x04,0x20,0x00, }; char shu16S[]={ /* 以下是 '术' 的 16点阵宋体 字模,32 byte */ 0x01,0x00,0x01,0x20,0x01,0x10,0x01,0x00, 0xFF,0xFE,0x01,0x00,0x03,0x80,0x05,0x40, 0x05,0x20,0x09,0x10,0x11,0x18,0x21,0x0E, 0xC1,0x04,0x01,0x00,0x01,0x00,0x00,0x00, }; char cao16S[]={ /* 以下是 '操' 的 16点阵宋体 字模,32 byte */ 0x21,0xF8,0x21,0x08,0x21,0xF8,0xF8,0x00, 0x23,0xBC,0x22,0xA4,0x2A,0xA4,0x33,0xBC, 0x60,0x40,0xA7,0xFE,0x20,0x60,0x20,0xD0, 0x21,0x48,0x22,0x4E,0xAC,0x44,0x40,0x40, }; char zuo16S[]={ /* 以下是 '作' 的 16点阵宋体 字模,32 byte */ 0x08,0x80,0x0C,0x80,0x09,0x00,0x13,0xFE, 0x12,0x80,0x34,0x88,0x50,0xFC,0x90,0x80, 0x10,0x80,0x10,0x84,0x10,0xFE,0x10,0x80, 0x10,0x80,0x10,0x80,0x10,0x80,0x10,0x80, }; char shuo16S[]={ /* 以下是 '说' 的 16点阵宋体 字模,32 byte */ 0x42,0x08,0x21,0x88,0x31,0x10,0x23,0xF8, 0x02,0x08,0xE2,0x08,0x22,0x08,0x23,0xF8, 0x22,0xA8,0x20,0xA0,0x20,0xA0,0x29,0x20, 0x31,0x22,0x22,0x22,0x04,0x1E,0x08,0x00, }; char ming16S[]={ /* 以下是 '明' 的 16点阵宋体 字模,32 byte */ 0x00,0xFC,0x7C,0x84,0x44,0x84,0x44,0x84, 0x44,0xFC,0x7C,0x84,0x44,0x84,0x44,0x84, 0x44,0xFC,0x7C,0x84,0x00,0x84,0x01,0x04, 0x01,0x04,0x02,0x04,0x04,0x14,0x00,0x08, }; char tui16S[]={ /* 以下是 '退' 的 16点阵宋体 字模,32 byte */ 0x40,0x00,0x27,0xF0,0x24,0x10,0x07,0xF0, 0x04,0x10,0x04,0x10,0xE7,0xF0,0x24,0x88, 0x24,0x50,0x24,0x20,0x25,0x10,0x26,0x18, 0x24,0x08,0x50,0x00,0x8F,0xFE,0x00,0x00, }; char chu16S1[]={ /* 以下是 '出' 的 16点阵宋体 字模,32 byte */ 0x01,0x00,0x01,0x00,0x21,0x04,0x21,0x04, 0x21,0x04,0x21,0x04,0x3F,0xFC,0x21,0x04, 0x01,0x00,0x21,0x04,0x21,0x04,0x21,0x04, 0x21,0x04,0x3F,0xFC,0x20,0x04,0x00,0x00, }; char he16S[]={ /* 以下是 '核' 的 16点阵宋体 字模,32 byte */ 0x10,0x40,0x10,0x20,0x10,0x20,0x13,0xFE, 0xFC,0x40,0x10,0x44,0x38,0x88,0x35,0xF0, 0x50,0x22,0x50,0x44,0x90,0x88,0x13,0x10, 0x10,0x28,0x10,0xC4,0x13,0x06,0x10,0x04, }; char dan16S[]={ /* 以下是 '弹' 的 16点阵宋体 字模,32 byte */ 0x02,0x08,0xF9,0x0C,0x08,0x90,0x0B,0xFC, 0x7A,0x44,0x43,0xFC,0x42,0x44,0x42,0x44, 0xFB,0xFC,0x4A,0x44,0x08,0x40,0x0F,0xFE, 0x08,0x40,0x08,0x40,0x50,0x40,0x20,0x40, }; char yi16S[]={ /* 以下是 '医' 的 16点阵宋体 字模,32 byte */ 0x00,0x00,0x7F,0xFC,0x48,0x00,0x48,0x00, 0x4F,0xF8,0x50,0x80,0x60,0x88,0x5F,0xFC, 0x41,0x40,0x41,0x20,0x42,0x10,0x44,0x18, 0x48,0x10,0x40,0x00,0x7F,0xFE,0x00,0x00, }; char jiu16S[]={ /* 以下是 '救' 的 16点阵宋体 字模,32 byte */ 0x08,0x40,0x0A,0x60,0x0A,0x40,0xFF,0x7E, 0x08,0x44,0x4A,0x84,0x2A,0xC4,0x2D,0x48, 0x1C,0x28,0x2B,0x28,0x49,0x10,0x88,0x10, 0x08,0x28,0x08,0xC8,0x2B,0x06,0x10,0x04, }; char zhi16S[]={ /* 以下是 '支' 的 16点阵宋体 字模,32 byte */ 0x01,0x00,0x01,0x00,0x01,0x00,0x7F,0xFE, 0x01,0x00,0x01,0x00,0x1F,0xF8,0x08,0x10, 0x04,0x20,0x04,0x20,0x02,0x40,0x01,0x80, 0x02,0x40,0x0C,0x30,0x70,0x0E,0x00,0x04, }; char yuan16S2[]={ /* 以下是 '援' 的 16点阵宋体 字模,32 byte */ 0x10,0x3C,0x17,0xC0,0x12,0x8C,0xFD,0x50, 0x11,0xFC,0x14,0x80,0x18,0x80,0x17,0xFE, 0x30,0x80,0xD1,0xF8,0x11,0x10,0x12,0xA0, 0x14,0x60,0x18,0x90,0x51,0x0E,0x26,0x04, }; char chu16S[]={ /* 以下是 '除' 的 16点阵宋体 字模,32 byte */ 0x00,0x80,0xF8,0x80,0x89,0x40,0x91,0x20, 0xA2,0x10,0xA7,0xEC,0x98,0x80,0x90,0x80, 0x97,0xF8,0xD0,0x80,0xA2,0xA0,0x82,0x90, 0x84,0x8C,0x88,0x84,0x92,0x80,0x81,0x00, }; char lei16S[]={ /* 以下是 '雷' 的 16点阵宋体 字模,32 byte */ 0x1F,0xF8,0x01,0x00,0x7F,0xFE,0x41,0x04, 0x1D,0x70,0x01,0x00,0x1D,0x70,0x01,0x00, 0x3F,0xF8,0x21,0x08,0x21,0x08,0x3F,0xF8, 0x21,0x08,0x21,0x08,0x3F,0xF8,0x20,0x08, }; char di16S[]={ /* 以下是 '第' 的 16点阵宋体 字模,32 byte */ 0x10,0x40,0x1F,0x7E,0x28,0xA0,0x45,0x10, 0x9F,0xF8,0x00,0x88,0x1F,0xF8,0x10,0x80, 0x10,0x80,0x1F,0xFC,0x01,0x84,0x02,0x84, 0x0C,0x94,0x70,0x88,0x00,0x80,0x00,0x80, }; char liang16S[]={ /* 以下是 '辆' 的 16点阵宋体 字模,32 byte */ 0x10,0x00,0x13,0xFE,0xFC,0x90,0x20,0x90, 0x23,0xFE,0x52,0x92,0x52,0x92,0xFE,0x92, 0x12,0x92,0x12,0xD2,0x1F,0x2A,0xF3,0x46, 0x12,0x02,0x12,0x02,0x12,0x0A,0x12,0x04, }; char che16S[]={ /* 以下是 '车' 的 16点阵宋体 字模,32 byte */ 0x02,0x00,0x02,0x00,0x7F,0xFC,0x04,0x00, 0x04,0x80,0x08,0x80,0x10,0x80,0x3F,0xFC, 0x00,0x80,0x00,0x80,0xFF,0xFE,0x00,0x80, 0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80, }; char di16S2[]={ /* 以下是 '敌' 的 16点阵宋体 字模,32 byte */ 0x00,0x40,0x0E,0x60,0x70,0x40,0x10,0x40, 0x10,0x7E,0xFE,0x88,0x10,0x88,0x10,0x88, 0x11,0x88,0x7E,0x50,0x42,0x50,0x42,0x20, 0x42,0x20,0x7E,0x50,0x01,0x8E,0x06,0x04, }; char ji16S2[]={ /* 以下是 '机' 的 16点阵宋体 字模,32 byte */ 0x10,0x00,0x10,0xF8,0x10,0x88,0xFE,0x88, 0x10,0x88,0x10,0x88,0x38,0x88,0x34,0x88, 0x54,0x88,0x50,0x88,0x91,0x08,0x11,0x0A, 0x12,0x0A,0x12,0x0A,0x14,0x06,0x10,0x00, }; char da16S[]={ /* 以下是 '大' 的 16点阵宋体 字模,32 byte */ 0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00, 0x01,0x00,0xFF,0xFE,0x01,0x00,0x02,0x80, 0x02,0x80,0x02,0x40,0x04,0x40,0x04,0x20, 0x08,0x10,0x10,0x18,0x20,0x0E,0x40,0x04, }; char zhong16S[]={ /* 以下是 '中' 的 16点阵宋体 字模,32 byte */ 0x01,0x00,0x01,0x00,0x21,0x08,0x3F,0xFC, 0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08, 0x21,0x08,0x3F,0xF8,0x21,0x08,0x01,0x00, 0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00, }; char xiao16S[]={ /* 以下是 '小' 的 16点阵宋体 字模,32 byte */ 0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00, 0x09,0x40,0x0D,0x20,0x19,0x10,0x11,0x18, 0x21,0x0C,0x41,0x06,0x81,0x04,0x01,0x00, 0x01,0x00,0x01,0x00,0x05,0x00,0x02,0x00, }; char ji16S3[]={ /* 以下是 '击' 的 16点阵宋体 字模,32 byte */ 0x01,0x00,0x01,0x00,0x01,0x00,0x3F,0xF8, 0x01,0x00,0x01,0x00,0x01,0x04,0x7F,0xFE, 0x01,0x00,0x11,0x08,0x11,0x08,0x11,0x08, 0x11,0x08,0x1F,0xF8,0x10,0x08,0x00,0x00, }; char luo16S[]={ /* 以下是 '落' 的 16点阵宋体 字模,32 byte */ 0x04,0x40,0x04,0x40,0xFF,0xFE,0x04,0x40, 0x45,0x00,0x21,0xF8,0xA1,0x10,0x4A,0xA0, 0x48,0x40,0x10,0xA0,0x13,0x18,0xEF,0xF6, 0x22,0x10,0x22,0x10,0x23,0xF0,0x22,0x10, }; char sheng16S[]={ /* 以下是 '剩' 的 16点阵宋体 字模,32 byte */ 0x03,0x82,0x7C,0x02,0x04,0x02,0xFF,0xD2, 0x15,0x12,0x75,0x52,0x15,0x92,0x35,0x52, 0xD4,0xD2,0x0E,0x12,0x15,0x12,0x24,0xC2, 0x44,0x82,0x84,0x0A,0x04,0x04,0x00,0x00, }; char yu16S2[]={ /* 以下是 '余' 的 16点阵宋体 字模,32 byte */ 0x01,0x00,0x01,0x00,0x02,0x80,0x04,0x60, 0x08,0x10,0x3F,0xFE,0xC1,0x04,0x01,0x00, 0x3F,0xFC,0x01,0x00,0x11,0x40,0x19,0x30, 0x11,0x18,0x21,0x10,0x45,0x00,0x02,0x00, }; char gong16S2[]={ /* 以下是 '共' 的 16点阵宋体 字模,32 byte */ 0x00,0x00,0x04,0x20,0x04,0x20,0x04,0x20, 0x7F,0xFC,0x04,0x20,0x04,0x20,0x04,0x20, 0x04,0x20,0xFF,0xFE,0x04,0x40,0x06,0x20, 0x0C,0x10,0x08,0x18,0x10,0x0C,0x20,0x08, }; char yi16S1[]={ /* 以下是 '一' 的 16点阵宋体 字模,32 byte */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x04,0x7F,0xFE, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; char er16S[]={ /* 以下是 '二' 的 16点阵宋体 字模,32 byte */ 0x00,0x00,0x00,0x10,0x3F,0xF8,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04, 0x7F,0xFE,0x00,0x00,0x00,0x00,0x00,0x00, }; char san16S[]={ /* 以下是 '三' 的 16点阵宋体 字模,32 byte */ 0x00,0x00,0x00,0x00,0x7F,0xFC,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xF8, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x7F,0xFE,0x00,0x00,0x00,0x00, }; char wo16S[]={ /* 以下是 '我' 的 16点阵宋体 字模,32 byte */ 0x06,0x40,0x38,0x50,0x08,0x48,0x08,0x48, 0x08,0x40,0xFF,0xFE,0x08,0x40,0x08,0x48, 0x0E,0x28,0x38,0x30,0xC8,0x20,0x08,0x50, 0x09,0x92,0x08,0x0A,0x28,0x06,0x10,0x02, }; char fang16S[]={ /* 以下是 '方' 的 16点阵宋体 字模,32 byte */ 0x02,0x00,0x01,0x00,0x00,0x80,0xFF,0xFE, 0x02,0x00,0x02,0x00,0x03,0xF0,0x02,0x10, 0x04,0x10,0x04,0x10,0x08,0x10,0x08,0x10, 0x10,0x10,0x20,0x90,0xC0,0x60,0x00,0x00, }; char sun16S[]={ /* 以下是 '损' 的 16点阵宋体 字模,32 byte */ 0x11,0xFC,0x11,0x04,0x11,0x04,0xFD,0xFC, 0x10,0x00,0x15,0xFE,0x19,0x02,0x31,0x22, 0xD1,0x22,0x11,0x22,0x11,0x22,0x11,0x42, 0x10,0x50,0x10,0x88,0x51,0x06,0x22,0x02, }; char hao16S[]={ /* 以下是 '耗' 的 16点阵宋体 字模,32 byte */ 0x10,0x08,0x10,0x1C,0xFD,0xE0,0x10,0x20, 0x7C,0x3C,0x11,0xE0,0x10,0x20,0xFE,0x20, 0x10,0x3E,0x3B,0xE0,0x34,0x20,0x56,0x20, 0x54,0x22,0x90,0x22,0x10,0x1E,0x10,0x00, }; char zhe16S[]={ /* 以下是 '者' 的 16点阵宋体 字模,32 byte */ 0x01,0x00,0x01,0x08,0x3F,0xEC,0x01,0x10, 0x01,0x20,0x7F,0xFE,0x00,0x80,0x03,0x00, 0x07,0xF8,0x1C,0x08,0xE4,0x08,0x07,0xF8, 0x04,0x08,0x04,0x08,0x07,0xF8,0x04,0x08, }; char zhuan16S[]={ /* 以下是 '专' 的 16点阵宋体 字模,32 byte */ 0x01,0x00,0x01,0x00,0x3F,0xF8,0x02,0x00, 0x02,0x00,0xFF,0xFE,0x04,0x00,0x08,0x20, 0x0F,0xF0,0x00,0x20,0x00,0x40,0x02,0x80, 0x01,0x00,0x00,0x80,0x00,0x40,0x00,0x00, }; char ye16S[]={ /* 以下是 '业' 的 16点阵宋体 字模,32 byte */ 0x04,0x40,0x04,0x40,0x04,0x40,0x04,0x44, 0x44,0x46,0x24,0x4C,0x24,0x48,0x14,0x50, 0x1C,0x50,0x14,0x60,0x04,0x40,0x04,0x40, 0x04,0x44,0xFF,0xFE,0x00,0x00,0x00,0x00, }; /******************************************************************************* ** 函数名称:initgr ** 函数描述:BGI初始化 ** 输入参数:无 ** 输出参数:无 *******************************************************************************/ void initgr(void) { int gd = DETECT, gm = 0; /* 和gd = VGA,gm = VGAHI是同样效果 */ registerbgidriver(EGAVGA_driver);/* 注册BGI驱动后可以不需要.BGI文件的支持运行 */ initgraph(&gd, &gm, ""); } /******************************************************************************* ** 函数名称:start ** 函数描述:显示启动画面 ** 输入参数:无 ** 输出参数:无 *******************************************************************************/ void startpicture(void) { int i; setbkcolor(LIGHTBLUE); /*drawmat 参数 依次:字模指针、点阵大小、起始坐标(x,y)、颜色*/ /*地空对决*/ drawmat(di64H,64,162,50,6); drawmat(kong64H,64,246,50,11); drawmat(dui64H,64,330,50,14); drawmat(jue64H,64,414,50,12); /*作者:宋元瑞*/ drawmat(zuo16S,16,100,400,8); drawmat(zhe16S,16,116,400,8); drawmat(song16S,16,148,400,8); drawmat(yuan16S,16,164,400,8); drawmat(rui16S,16,180,400,8); /*指导:刘传耀*/ drawmat(zhi16S3,16,100,432,8); drawmat(dao16S,16,116,432,8); drawmat(liu16S,16,148,432,8); drawmat(chuan16S,16,164,432,8); drawmat(yao16S,16,180,432,8); /*江西理工大学*/ drawmat(jiang16S,16,320,400,8); drawmat(xi16S,16,336,400,8); drawmat(li16S,16,352,400,8); drawmat(gong16S,16,368,400,8); drawmat(da16S,16,384,400,8); drawmat(xue16S,16,400,400,8); /*电子信息科学与技术 专业*/ drawmat(dian16S,16,320,432,8); drawmat(zi16S,16,336,432,8); drawmat(xin16S,16,352,432,8); drawmat(xi16S2,16,368,432,8); drawmat(ke16S,16,384,432,8); drawmat(xue16S,16,400,432,8); drawmat(yu16S,16,416,432,8); drawmat(ji16S,16,432,432,8); drawmat(shu16S,16,448,432,8); drawmat(zhuan16S,16,472,432,8); drawmat(ye16S,16,486,432,8); /*画启动坦克*/ setfillstyle(1,4); bar(270,240,370,340); setfillstyle(1,14); bar(280,250,360,330); setfillstyle(1,GREEN); fillellipse(320,290,30,30); setfillstyle(1,8); fillellipse(320,290,20,20); setfillstyle(1,8); bar(310,180,330,300); /*声音*/ for(i=100;i<=500;i=i+100) { sound(i); sleep(1); nosound(); } } /******************************************************************************* ** 函数名称:bkground ** 函数描述:画天地环境 ** 输入参数:无 ** 输出参数:无 *******************************************************************************/ int bkground() { setfillstyle(1,1); /*draw sky*/ bar(50,0,640,130); setfillstyle(1,3); bar(50,130,640,320); setfillstyle(1,14); /*draw land*/ bar(50,320,640,480); } /******************************************************************************* ** 函数名称:grass ** 函数描述:画草地 ** 输入参数:x,y ** 输出参数:无 *******************************************************************************/ int grass(int x,int y) { setcolor(2); line(x,y,x-3,y-5); line(x,y,x+3,y-5); line(x,y,x,y-8); } /******************************************************************************* ** 函数名称:tree ** 函数描述:画树 ** 输入参数:x,y ** 输出参数:无 *******************************************************************************/ int tree(int x,int y) { setfillstyle(1,6); bar(x-5,y,x+5,y-50); setfillstyle(1,2); setcolor(2); fillellipse(x,y-65,30,20); fillellipse(x,y-85,18,25); } /******************************************************************************* ** 函数名称:tank ** 函数描述:画坦克 ** 输入参数:x,y ** 输出参数:无 *******************************************************************************/ int tank(int fx,int x,int y)/*fx是方向参数,1代表left,0代表right*/ { /*坦克length=50,height=70 */ int *earth; int sizee; if (tankstart==1) /*运行时地面环境处理*/ { if(fx==1) {putimage(x-15,y-45,earth,COPY_PUT);} /*还原空地,覆盖坦克*/ else if (fx==0) {putimage(x-35,y-45,earth,COPY_PUT);} free(earth); getimage(x-25,y-45,x+25,y+20,earth); /*更新存储地面环境 */ } if (tankstart==0) /*初始化坦克 */ {tankstart=1; sizee=imagesize(x-25,y-45,x+25,y+20) ; earth=malloc(sizee); getimage(x-25,y-45,x+25,y+20,earth); /*初次存储地面环境 */ } /*画坦克*/ setfillstyle(1,4); bar(x-25,y-20,x+25,y+20); setfillstyle(1,14); bar(x-21,y-16,x+21,y+16); setfillstyle(1,8); fillellipse(x,y,10,10); bar(x-4,y,x+4,y-45); } /******************************************************************************* ** 函数名称:plmid ** 函数描述:画中型飞机 ** 输入参数:x,y ** 输出参数:无 *******************************************************************************/ int plmid(int x,int y,int show) { /*飞机length=78,height=60 */ int *plmid; int sizep; if (show==1) { if (planstart==0) { sizep=imagesize(x,y-30,x+78,y+30); plmid=malloc(sizep); getimage(x,y-30,x+78,y+30,plmid);/*初次环境存图*/ planstart=1; } putimage(x+10,y-30,plmid,COPY_PUT); /*还原环境*/ free(plmid); /*画飞机*/ setcolor(LIGHTBLUE); line(x,y,x+10,y-5); /* 机头 */ line(x,y,x+10,y+5); /*bar(x+10,y-5,x+70,y+5);机身,闪烁 */ rectangle(x+10,y-5,x+70,y+5);/*机身*/ line(x+30,y-5,x+49,y-30);/* 上机翼 */ line(x+49,y-30,x+60,y-30); line(x+60,y-30,x+46,y-5); line(x+33,y+3,x+55,y+30);/* 下机翼 */ line(x+55,y+30,x+65,y+30); line(x+65,y+30,x+50,y+2); line(x+70,y+5,x+78,y+15);/* 尾翼 */ line(x+78,y+15,x+78,y-15); line(x+78,y-15,x+70,y-5); } } /******************************************************************************* ** 函数名称:plsml ** 函数描述:画小型飞机 ** 输入参数:x,y ** 输出参数:无 *******************************************************************************/ int plsmal(int x,int y,int show) { /*length=50,height=36*/ if (show==1) { setcolor(RED); {line(x,y,x+50,y);/*前机身*/ line(x,y,x+16,y-10); line(x+16,y-10,x+35,y); line(x+35,y,x+50,y-15);/*后机身*/ line(x+50,y-15,x+50,y); line(x+14,y-8,x+20,y-20);/*上机翼*/ line(x+20,y-20,x+28,y-20); line(x+28,y-20,x+22,y-6); line(x+12,y-3,x+20,y+16); /*下机翼*/ line(x+20,y+16,x+28,y+16); line(x+28,y+16,x+20,y-3); } } } /******************************************************************************* ** 函数名称:plsml ** 函数描述:画小型飞机 ** 输入参数:x,y ** 输出参数:无 *******************************************************************************/ int plbig(int x,int y,int show) { /*length=120,height=95*/ if (show==1) { setcolor(RED); ellipse(x,y,0,360,40,15);/*前机身*/ line(x+40,y,x+65,y-30);/*后机身*/ line(x+65,y-30,x+80,y-30); line(x+80,y-30,x+80,y); line(x+80,y,x+40,y); line(x-5,y,x+5,y+50);/*下机翼*/ line(x+5,y+50,x+20,y+50); line(x+20,y+50,x+10,y); line(x-3,y-15,x+3,y-45); /*上机翼*/ line(x+3,y-45,x+18,y-45); line(x+18,y-45,x+15,y-14); } } /******************************************************************************* ** 函数名称:shot ** 函数描述: ** 输入参数:x,y ** 输出参数:无 *******************************************************************************/ int shot(int x,int y) { int *buf; getimage(x-5,y-5,x+5,y+5,buf); setcolor(8);setfillstyle(1,8); fillellipse(x,y,4,5); delay(10000); putimage(x-5,y-5,buf,COPY_PUT); } /******************************************************************************* ** 函数名称:boom ** 函数描述:绘制飞机中弹后的爆炸效果 ** 输入参数:x,y ** 输出参数:无 *******************************************************************************/ int boom(int x,int y) {setcolor(RED); circle(x+40,y,20); pieslice(x+40,y,0,360,18); line(x,y,x+80,y); line(x+40,y-40,x+40,y+40); line(x+20,y-30,x+60,y+30); line(x+60,y-30,x+20,y+30); } /******************************************************************************* ** 函数名称:drawmouse ** 函数描述:画鼠标 ** 输入参数:x,y,fl ** 输出参数:无 *******************************************************************************/ void drawmouse(int x,int y,int fl) { /*fl表示先后顺序,即first/last,0表示先,1表示后*/ int *buf; int size; if(x>=630) {y=630;} if(y<10)/*防止鼠标到达屏幕上边界时候出错,以免程序异常退出*/ {x=10;} else { size=imagesize(x,y-5,x+15,y+15); buf=malloc(size); if (first==0) { if(fl==0) {delay(10000); putimage(x,y-5,buf,COPY_PUT); } } if(fl==1) { getimage(x,y-5,x+10,y+10,buf); setcolor(RED); setfillstyle(11,YELLOW); bar(x,y,x+10,y+10); line(x,y,x+5,y-5); line(x+5,y-5,x+10,y); line(x+5,y-5,x+5,y+7); free(buf); first=0; } } } /******************************************************************************* ** 函数名称:main ** 函数描述: ** 输入参数:无 ** 输出参数:无 *******************************************************************************/ main() /**/ { union REGS regs; /*必须放在第一行*/ int mx,my; int i,j; /*画草地 循环参数 */ int is=1; /*shot连射控制参数*/ int k=0; /*公共公用循环参数*/ int xt,yt; /*tank 的x,y坐标 */ int xp=620,yp=40; /*plane的x,y坐标 */ int xs[20],ys[20]; /*shot 的x,y坐标 */ int key; /*键盘按键参数 */ initgr(); /* BGI初始化 */ startpicture(); /* 启动界面 */ /*游戏程序主界面*/ bkground(); /*画天地环境*/ for (i=53;i<640;i=i+10) /*画草地 */ {for (j=330;j<=450;j=j+15) {grass(i,j);} } tree(100,440); /*画树 */ tree(450,450); tree(500,400); xt=200;yt=400; /*????????????????????曾经导致错误退出?????????????????????????*/ /*操作游戏*/ while(1) { regs.x.ax=3; /*鼠标*/ int86(0x33,®s,®s); drawmouse(mx,my,0); mx=regs.x.cx; my=regs.x.dx; xp=xp-10; /*控制plan飞行*/ plmid(xp,yp,1); if (xp<60) {xp=630;} if(kbhit()) /* keyboard-hit,当有键按下时,执行if内程序,没有就继续往下执行 */ { key=bioskey(0); if(ESC==key) {break; } /*退出程序*/ switch(key) { case LEFT: xt=xt-10; if(xt<30) {xt=30; } tank(1,xt,yt); break; case RIGHT: xt=xt+10; if(xt>610) {xt=610;} tank(0,xt,yt); break; case UP: if (is<20) /*判断炮弹已使用数目,实现连射*/ {is=is+1;} else {is=0;} xs[is]=xt; /*把炮弹放在坦克炮口处*/ ys[is]=yt-47; shot(xs[is],ys[is]); /*发射炮弹,shot*/ break; default:break; }/*switch(key) end*/ }/*if(kbhit()) end*/ ys[is]=ys[is]-20; /*控制炮弹shot飞行*/ for(k=0;k<20;k++) /*判断飞机是否中弹*/ {if ((xp-xs[is])<80&&(xp>xs[is])&&ys<70) {boom(xs[is],ys[is]);} }/*for(k) end*/ setbkcolor(LIGHTBLUE); /*鼠标*/ setcolor(BLUE); drawmouse(mx,my,1); delay(100000); }/*while(1) end*/ getch(); /* 暂停一下,看看前面绘图代码的运行结果 */ closegr(); /* 恢复TEXT屏幕模式 */ return 0; } 推箱子: # include "conio.h" # include "graphics.h" char map[12][19]={{'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'}, {'.','.','.','.','#','#','#','#','#','#','#','#','#','#','#','.','.','.','.'}, {'.','.','.','.','#',' ',' ',' ',' ','#',' ',' ',' ',' ','#','.','.','.','.'}, {'.','.','.','.','#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#','.','.','.','.'}, {'.','.','.','.','#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#','.','.','.','.'}, {'.','.','.','.','#','#','#','#','#',' ','#','#','#','#','#','.','.','.','.'}, {'.','.','.','.','.','.','.','#',' ',' ',' ','#','.','.','.','.','.','.','.'}, {'.','.','.','.','.','.','.','#',' ',' ',' ','#','.','.','.','.','.','.','.'}, {'.','.','.','.','.','.','.','#',' ',' ',' ','#','.','.','.','.','.','.','.'}, {'.','.','.','.','.','.','.','#',' ',' ',' ','#','.','.','.','.','.','.','.'}, {'.','.','.','.','.','.','.','#','#','#','#','#','.','.','.','.','.','.','.'}, {'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'} }; struct move_point { int x,y; }man; int num; int step=0; int xi=0,re=0; void draw() { gotoxy(man.x,man.y); printf("%c/b",2); } void clr() { gotoxy(man.x,man.y); printf(" /b"); } void drawmap() { int i,j; gotoxy(0,0); for(i=0;i<12;i++) {for(j=0;j<19;j++) printf("%c",map[i][j]); printf("/n"); } } int BI(int x,int y) { if(map[y-1][x-1]=='#'||map[y-1][x-1]==15) return 1; else return 0; } int XI_W(int x,int y) { if(map[y-1][x-1]==15&&BI(x,y-1)==0) {map[y-1][x-1]=' '; map[y-2][x-1]=15; xi=1; gotoxy(x,y-1); printf("%c",15); return 0; } if(map[y-1][x-1]==' ') {xi=2;return 0;} return 1; } int XI_A(int x,int y) { if(map[y-1][x-1]==15&&BI(x-1,y)==0) {map[y-1][x-1]=' '; map[y-1][x-2]=15; xi=1; gotoxy(x-1,y); printf("%c",15); return 0; } if(map[y-1][x-1]==' ') {xi=2;return 0;} return 1; } int XI_S(int x,int y) { if(map[y-1][x-1]==15&&BI(x,y+1)==0) {map[y-1][x-1]=' '; map[y][x-1]=15; xi=1; gotoxy(x,y+1); printf("%c",15); return 0; } if(map[y-1][x-1]==' ') {xi=2;return 0;} return 1; } int XI_D(int x,int y) { if(map[y-1][x-1]==15&&BI(x+1,y)==0) {map[y-1][x-1]=' '; map[y-1][x]=15; xi=1; gotoxy(x+1,y); printf("%c",15); return 0; } if(map[y-1][x-1]==' ') {xi=2;return 0;} return 1; } void draw_des() { num=6; if(map[6][10]==' ') gotoxy(11,7),printf("+");else num--; if(map[7][10]==' ') gotoxy(11,8),printf("+");else num--; if(map[8][10]==' ') gotoxy(11,9),printf("+");else num--; if(map[9][10]==' ') gotoxy(11,10),printf("+");else num--; if(map[8][8]==' ') gotoxy(9,9),printf("+");else num--; if(map[8][9]==' ') gotoxy(10,9),printf("+");else num--; if(num==0) gotoxy(23,12),printf("You are very clever!"),getch(),exit(0); } void draw_step() { gotoxy(38,6); printf("%d",step); } void draw_biaoge() { line(170,0,170,200); line(0,200,340,200); line(170,60,340,60); line(340,0,340,200); line(0,205,345,205); line(345,0,345,205); line(165,0,165,200); line(260,60,260,160); line(170,5,340,5); line(170,160,340,160); } void FAN() { switch(re) {case 1:clr();man.y++;draw();if(xi==1) {map[man.y-3][man.x-1]=' '; map[man.y-2][man.x-1]=15; gotoxy(man.x,man.y-2); printf(" "); gotoxy(man.x,man.y-1); printf("%c/b",15); } break; case 2:clr();man.x++;draw();if(xi==1) {map[man.y-1][man.x-3]=' '; map[man.y-1][man.x-2]=15; gotoxy(man.x-2,man.y); printf(" "); gotoxy(man.x-1,man.y); printf("%c/b",15); } break; case 3:clr();man.y--;draw();if(xi==1) {map[man.y+1][man.x-1]=' '; map[man.y][man.x-1]=15; gotoxy(man.x,man.y+2); printf(" "); gotoxy(man.x,man.y+1); printf("%c/b",15); } break; case 4:clr();man.x--;draw();if(xi==1) {map[man.y-1][man.x+1]=' '; map[man.y-1][man.x]=15; gotoxy(man.x+2,man.y); printf(" "); gotoxy(man.x+1,man.y); printf("%c/b",15); } break; } re=0; xi=0; } main() { int driver=DETECT,mode; char ch; man.x=12; man.y=4; map[3][6]=15; map[3][7]=15; map[3][8]=15; map[3][9]=15; map[3][10]=15; map[3][12]=15; clr(); registerbgidriver(EGAVGA_driver); initgraph(&driver,&mode,""); setbkcolor(GREEN); drawmap(); draw_des(); draw_step(); draw(); draw_biaoge(); gotoxy(25,5); printf("w:UP"); gotoxy(25,6); printf("a:LEFT"); gotoxy(25,7); printf("s:DOWN"); gotoxy(25,8); printf("d:RIGHT"); gotoxy(25,9); printf("r:QUIT"); gotoxy(25,10); printf("f:REGRET"); gotoxy(35,5); printf("step:"); gotoxy(27,3); printf("BAN YUN GONG"); for(;;) { if(kbhit()) { ch=getch(); if(ch=='r') break; switch(ch) { case 'w':if(XI_W(man.x,man.y-1)==1) break; clr(); step++; man.y--; re=1; draw_des(); draw_step(); draw(); break; case 'a':if(XI_A(man.x-1,man.y)==1) break; clr(); step++; man.x--; re=2; draw_des(); draw_step(); draw(); break; case 's':if(XI_S(man.x,man.y+1)==1) break; clr(); step++; man.y++; re=3; draw_des(); draw_step(); draw(); break; case 'd':if(XI_D(man.x+1,man.y)==1) break; clr(); step++; man.x++; re=4; draw_des(); draw_step(); draw(); break; case 'f':if(re==0) break; else FAN();break; default:break; } } } } 俄罗斯方块: /*学无止境*/ #include <stdlib.h> #include <stdio.h> #include <graphics.h> #define ESC 27 #define UP 328 #define DOWN 336 #define LEFT 331 #define RIGHT 333 #define BLANK 32 #define BOTTOM 2 #define CANNOT 1 #define CAN 0 #define MAX 30 #define F1 315 #define ADD 43 #define EQUAL 61 #define DEC 45 #define SOUNDs 115 #define SOUNDS 83 #define PAUSEP 80 #define PAUSEp 112 void Init(); void Down(); void GoOn(); void ksdown(); void Display(int color); void Give(); int Touch(int x,int y,int dx,int dy); int GeyKey(); void Select(); void DetectFill(); void GetScores(); void Fail(); void Help(); void Quit(); void DrawBox(int x,int y,int Color); void OutTextXY(int x,int y,char *String); void DispScore(int x,int y,char Ch); void DrawNext(int Color); int Heng=12,Shu=20; /*横竖*/ int Position[MAX][MAX]; int middle[MAX][MAX]; int ActH,ActS; int Act,Staus; int i,j,k; int Wid=10; int NoPass=CAN; float Delays=15000; int BeginH=250,BeginS=7; float Seconds=0; int Scores=0; int flag=1; int Sounds=CAN; int PreAct,NextAct; int a[8][4][4][4]={{{1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0}, {1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0}, {1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0}, {1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0}}, {{1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0}, {1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0}, {1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0}, {1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0}}, {{1,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0}, {0,1,0,0,1,1,0,0,0,1,0,0,0,0,0,0}, {0,1,0,0,1,1,1,0,0,0,0,0,0,0,0,0}, {1,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0}}, {{1,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0}, {0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0}, {1,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0}, {0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0}}, {{0,1,0,0,1,1,0,0,1,0,0,0,0,0,0,0}, {1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0}, {0,1,0,0,1,1,0,0,1,0,0,0,0,0,0,0}, {1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0}}, {{1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0}, {1,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0}, {1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0}, {0,1,0,0,0,1,0,0,1,1,0,0,0,0,0,0}}, {{0,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0}, {1,0,0,0,1,0,0,0,1,1,0,0,0,0,0,0}, {1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0}, {1,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0}}, {{1,1,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}, {1,1,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}}}; int b[4][4]; main(int argc,char *argv[]) { if (argc!=1) { if (argv[1]!="") Heng=atoi(argv[1]); if (argv[2]!="") Shu=atoi(argv[2]); } Init(); /*初始化界面*/ PreAct=random(8); /*取得当前的方块*/ for(;;) /*以下是游戏流程*/ { NextAct=random(8); /*取得下一个方块*/ DrawNext(1); /*画出下一个方块*/ Act=PreAct; if (Heng%2==0) ActH=Heng/2; else ActH=(Heng-1)/2; ActS=0; /*方块开始从游戏空间的中间下落*/ Staus=0; /*取开始的状态*/ NoPass=CAN; /*物体可以下落*/ Give(); /*取得当前的方块*/ Display(Act+1); /*显示当前的方块,每种方块的颜色不同*/ GoOn(); /*游戏的算法精髓所在*/ PreAct=NextAct; /*方块下落完毕,取得下一个方块*/ DrawNext(0); } } void Init() { int GraphDriver=DETECT,GraphMode; registerbgidriver(EGAVGA_driver); initgraph(&GraphDriver,&GraphMode,""); if (kbhit()) Sounds=CANNOT; setcolor(1); OutTextXY(10,10,"Tetris"); OutTextXY(30,30,"Version 2.0"); OutTextXY(10,120,"Help:"); OutTextXY(20,140,"+ :Faster"); OutTextXY(20,160,"- :Slower"); OutTextXY(20,180,"Esc :Quit"); OutTextXY(20,200,"F1 :Help"); OutTextXY(10,310,"Copyright(c) 1998.2.22"); OutTextXY(10,320,"By Mr. Unique"); outtextxy(10,250,"Score: 00000"); rectangle(BeginH-3,BeginS-3,BeginH+Heng*(Wid+2)+2,BeginS+Shu*(Wid+2)+2); rectangle(BeginH-5,BeginS-5,BeginH+Heng*(Wid+2)+4,BeginS+Shu*(Wid+2)+4); rectangle(BeginH+(Heng+4)*(Wid+2)-2,BeginS+10,BeginH+(Heng+8)*(Wid+2)+2,BeginS+12+4*(Wid+2)); for (i=0;i<MAX;i++) for (j=0;j<MAX;j++) {Position[i][j]=1; middle[i][j]=-1; } for (i=0;i<Heng;i++) for (j=0;j<Shu;j++) Position[i][j]=0; for (i=0;i<Heng;i++) for (j=0;j<Shu;j++) DrawBox(i,j,0); randomize(); } void GoOn() { for(;;) { Seconds+=0.2; /*控制方块的下落速度*/ if (Seconds>=Delays) { Down(); Seconds=0; if (NoPass==BOTTOM) { DetectFill(); middle[ActH][ActS]=Act; if (ActS==0) Fail(); return; } } if (kbhit()) Select(); } } void Down() /*方块下降*/ { Display(0); if (Touch(ActH,ActS,0,1)==CAN) ActS++; else middle[ActH][ActS]=Act; Display(Staus+1); } int Touch(int x,int y,int dx,int dy) { NoPass=CAN; for (i=0;i<4;i++) for (j=0;j<4;j++) Position[x+dx+i][y+dy+j]+=b[i][j]; for (i=0;i<MAX;i++) for (j=0;j<MAX;j++) if (Position[i][j]>1) NoPass=CANNOT; for (i=0;i<4;i++) for (j=0;j<4;j++) { Position[x+dx+i][y+dy+j]-=b[i][j]; middle[x+dx+i][y+dy+j]=Act; } if (NoPass==CANNOT && dx==0 && dy==1) { for (i=0;i<4;i++) for (j=0;j<4;j++) Position[x+i][y+j]+=b[i][j]; NoPass=BOTTOM; } return NoPass; } int GetKey(void) { int Ch,Low,Hig; Ch=bioskey(0); Low=Ch&0x00ff; Hig=(Ch&0xff00)>>8; return(Low==0?Hig+256:Low); } void Select() { int OldStaus,acts=ActS; switch(GetKey()) { case ESC :Quit();break; case DOWN :Seconds+=14500;break; case LEFT :Display(0); if (ActH>0 && Touch(ActH,ActS,-1,0)==CAN) { ActH--;} Display(Act+1);break; case RIGHT :Display(0); if (ActH<Heng && Touch(ActH,ActS,1,0)==CAN) { ActH++;} Display(Act+1);break; case BLANK : Display(0); ksdown(); Display(Act+1); break; case F1 :Help();break; case EQUAL : case ADD :if (Delays>300) Delays-=100;break; case DEC :if (Delays<3000) Delays+=100;break; case PAUSEP : case PAUSEp :getch();break; case SOUNDS : case SOUNDs :if (Sounds==CAN) Sounds=CANNOT; else Sounds=CAN;break; case UP :if(Act==7) { while(acts<Shu-1&&Position[ActH][acts]!=1) acts++; Position[ActH][acts]=0; DrawBox(ActH,acts,0); acts=ActS; break; } else { Display(0); OldStaus=Staus; switch(Act) { case 0: case 3: case 4:if (Staus==1) Staus=0;else Staus=1;break; case 1:break; case 2: case 5: case 6:if (Staus==3) Staus=0;else Staus++;break; } Give(); if (Touch(ActH,ActS,0,0)==CANNOT) { Staus=OldStaus; Give(); } Display(Act+1); break; } } } void ksdown() { while(flag){ if(Touch(ActH,ActS,0,0)==CAN){ActS++;} else { ActS--; flag=0; } } flag=1; } void Quit() { int ch,TopScore; FILE *fp; if ((fp=fopen("Russian.scr","r+"))!=NULL) { fscanf(fp,"%d",&TopScore); if (Scores>TopScore) { setcolor(1); outtextxy(470,80,"Hello !"); outtextxy(470,100,"In all the players,"); outtextxy(470,120,"You are the First !"); outtextxy(470,140,"And your score will"); outtextxy(470,160,"be the NEW RECORD !"); fseek(fp,0L,0); fprintf(fp,"%d",Scores); } fclose(fp); } setcolor(1); OutTextXY(470,220,"Are You Sure (Yes/no)?"); ch=getch(); if (ch=='y'||ch=='Y') { closegraph(); delay(20); exit(0); } setcolor(0); outtextxy(470,220,"Are You Sure (Yes/no)?"); } void OutTextXY(int x,int y,char *String) { int i=0; char a[2]; moveto(x,y); a[1]='/0'; while (*(String+i)!='/0') { a[0]=*(String+i); outtext(a); if (Sounds==CAN && a[0]!=' ') { sound(3000); delay(50); nosound(); } i++; } } void Help() { unsigned Save; void *Buf; Save=imagesize(160,120,500,360); Buf=malloc(Save); getimage(160,120,500,360,Buf); setfillstyle(1,1); bar(160,120,500,280); setcolor(0); OutTextXY(170,130," About & Help"); OutTextXY(170,150," # # # ########## # # # "); OutTextXY(170,160," # ## # # # # # # ###### ### "); OutTextXY(170,170," ########## ########## ## # # "); OutTextXY(170,180," # # # # # # # ## #### "); OutTextXY(170,190," # ## # #### ## # # # "); OutTextXY(170,200," # ## # # # # # ## # # # "); OutTextXY(170,210," # # # ## ## # ###### # # # "); OutTextXY(170,220," ## # ## # ## # # # # "); OutTextXY(170,230," # ## # #### # ## # "); OutTextXY(170,260," Good Luckly to You !!! "); getch(); putimage(160,120,Buf,0); free(Buf); } void GetScores() { int Sec10000,Sec1000,Sec100,Sec10,Sec1; setfillstyle(0,1); bar(60,250,109,260); Sec1=Scores%10; Sec10=(Scores%100-Scores%10)/10; Sec100=(Scores%1000-Scores%100)/100; Sec1000=(Scores%10000-Scores%1000)/1000; Sec10000=(Scores%100000-Scores%10000)/10000; DispScore(60,250,'0'+Sec10000); DispScore(70,250,'0'+Sec1000); DispScore(80,250,'0'+Sec100); DispScore(90,250,'0'+Sec10); DispScore(100,250,'0'+Sec1); DispScore(110,250,'0'); DispScore(120,250,'0'); } void DispScore(int x,int y,char Ch) { char a[2]; a[1]='/0'; a[0]=Ch; outtextxy(x,y,a); } void Give() { for (i=0;i<4;i++) for (j=0;j<4;j++) b[i][j]=a[Act][Staus][i][j]; } void Display(int color) { for (i=0;i<4;i++) for (j=0;j<4;j++) if (b[i][j]==1) DrawBox(ActH+i,ActS+j,color); } void DrawBox(int x,int y,int Color) { x=BeginH+x*(Wid+2); y=BeginS+y*(Wid+2); setfillstyle(1,Color); bar(x+2,y+2,x+Wid-1,y+Wid-1); if (Color==0) setcolor(9); else setcolor(Act+1); rectangle(x+4,y+4,x+Wid-4,y+Wid-4); } void DrawNext(int Color) { for (i=0;i<4;i++) for (j=0;j<4;j++) if (a[NextAct][0][i][j]==1) DrawBox(Heng+4+i,1+j,Color); } void DetectFill() { int Number,Fall,FallTime=0; for (i=Shu-1;i>=0;i--) { Number=0; for (j=0;j<Heng;j++) if (Position[j][i]==1) Number++; if (Number==Heng) { FallTime++; if (Sounds==CAN) { sound(500); delay(500); nosound(); } for (Fall=i;Fall>0;Fall--) for (j=0;j<Heng;j++) { Position[j][Fall]=Position[j][Fall-1]; middle[j][Fall]=middle[j][Fall-1]; if (Position[j][Fall]==0) DrawBox(j,Fall,0); else DrawBox(j,Fall,middle[j][Fall]+1); } i++; } } switch(FallTime) { case 0:break; case 1:Scores+=1;break; case 2:Scores+=3;break; case 3:Scores+=6;break; case 4:Scores+=10;break; } if (FallTime!=0) { GetScores(); if (Scores%100==0) Delays-=100; } } void Fail() { if (Sounds==CAN) { for (k=0;k<3;k++) { sound(300); delay(200); nosound(); } } setcolor(1); OutTextXY(440,200,"Game over!"); Quit(); closegraph(); exit(0); } 计算器: #include <stdlib.h> #include <math.h> #include <graphics.h> #include <stdio.h> #include <process.h> #define EXCAPE 27 #define ENTER 13 main(){ int press,i,x,y,x1,y1,ch_z=0; int dian=0; char ch='0'; /*input + - * / */ char emp[80],sum[80],*e,*s; double yuan=0.000000000000; void init(void); void clear_z(char *u); double strtoflt(char *p); int getkey(); int gd=DETECT, gm; initgraph(&gd, &gm, ""); e=emp; s=sum; init(); x = (getmaxx() / 2) - 120; y = (getmaxy() / 2) - 150; x1 = (getmaxx() / 2) + 120; y1 = (getmaxy() / 2) + 150; while(1){ press = getkey(); switch(press){ case EXCAPE: exit(0); case 47: bar (x + 10, y + 80 + 10, x + 60 - 10, y + 80 + 60 - 10); delay(8000); init(); if (ch!='0'){ switch(ch){ case '/': if (strtoflt(emp)==0.0){ ch='0'; ch_z=0; dian=0; emp[0]='/0'; sum[0]='/0'; e=emp; s=sum; outtextxy(x+30,y+40,"error!!!!!"); break; } yuan = strtoflt(sum) / strtoflt(emp); sprintf(sum,"%0.10f",yuan); clear_z(sum); outtextxy(x+30,y+40,sum); break; case '*': yuan = strtoflt(sum) * strtoflt(emp); sprintf(sum,"%0.10f",yuan); clear_z(sum); outtextxy(x+30,y+40,sum); break; case '+': yuan = strtoflt(sum) + strtoflt(emp); sprintf(sum,"%0.10f",yuan); clear_z(sum); outtextxy(x+30,y+40,sum); break; case '-': if (strtoflt(sum)>=strtoflt(emp)){ yuan = strtoflt(sum) - strtoflt(emp); sprintf(sum,"%0.10f",yuan); } else{ yuan=strtoflt(emp)-strtoflt(sum); sprintf(sum,"-%0.10f",yuan); } clear_z(sum); outtextxy(x+30,y+40,sum); emp[0]='/0'; } } else{ if (ch_z==0){ outtextxy(x+30,y+40,emp); stpcpy(sum,emp); } else{ outtextxy(x+30,y+40,sum); } } ch='/'; ch_z=0; emp[0]='/0'; e=emp; dian=0; break; case 42: bar (x + 60 + 10, y + 80 + 10, x + 60 * 2 - 10, y + 80 + 60 - 10); delay(8000); init(); if (ch!='0'){ switch(ch){ case '/': yuan = strtoflt(sum) / strtoflt(emp); sprintf(sum,"%0.10f",yuan); clear_z(sum); outtextxy(x+30,y+40,sum); emp[0]='/0'; e=emp; break; case '*': yuan = strtoflt(sum) * strtoflt(emp); sprintf(sum,"%0.10f",yuan); clear_z(sum); outtextxy(x+30,y+40,sum); emp[0]='/0'; e=emp; break; case '+': yuan = strtoflt(sum) + strtoflt(emp); sprintf(sum,"%0.10f",yuan); clear_z(sum); outtextxy(x+30,y+40,sum); emp[0]='/0'; e=emp; break; case '-': if (strtoflt(sum)>=strtoflt(emp)){ yuan = strtoflt(sum) - strtoflt(emp); sprintf(sum,"%0.10f",yuan); } else{ yuan=strtoflt(emp)-strtoflt(sum); sprintf(sum,"-%0.10f",yuan); } clear_z(sum); outtextxy(x+30,y+40,sum); emp[0]='/0'; e=emp; break; } } else{ if (ch_z==0){ outtextxy(x+30,y+40,emp); stpcpy(sum,emp); e=emp; } else outtextxy(x+30,y+40,sum); } ch='*'; ch_z=0; dian=0; break; case 45: bar (x + 60 * 2 + 10, y + 80 + 10, x + 60 * 3 - 10, y + 80 + 60 - 10); delay(8000); init(); if (ch!='0'){ switch(ch){ case '/': yuan = strtoflt(sum) / strtoflt(emp); sprintf(sum,"%0.10f",yuan); clear_z(sum); outtextxy(x+30,y+40,sum); emp[0]='/0'; e=emp; break; case '*': yuan = strtoflt(sum) * strtoflt(emp); sprintf(sum,"%0.10f",yuan); clear_z(sum); outtextxy(x+30,y+40,sum); emp[0]='/0'; e=emp; break; case '+': yuan = strtoflt(sum) + strtoflt(emp); sprintf(sum,"%0.10f",yuan); clear_z(sum); outtextxy(x+30,y+40,sum); emp[0]='/0'; e=emp; break; case '-': if (strtoflt(sum)>=strtoflt(emp)){ yuan = strtoflt(sum) - strtoflt(emp); sprintf(sum,"%0.10f",yuan); } else{ yuan=strtoflt(emp)-strtoflt(sum); sprintf(sum,"-%0.10f",yuan); } clear_z(sum); outtextxy(x+30,y+40,sum); emp[0]='/0'; e=emp; break; } } else{ if (ch_z==0){ outtextxy(x+30,y+40,emp); stpcpy(sum,emp); e=emp; } else outtextxy(x+30,y+40,sum); } ch='-'; ch_z=0; dian=0; break; case 43: bar (x + 60 * 3 + 10, y + 80 + 10, x + 60 * 4 - 10, y + 80 + 60 - 10); delay(8000); init(); if (ch!='0'){ switch(ch){ case '/': yuan = strtoflt(sum) / strtoflt(emp); sprintf(sum,"%0.10f",yuan); clear_z(sum); outtextxy(x+30,y+40,sum); emp[0]='/0'; e=emp; break; case '*': yuan = strtoflt(sum) * strtoflt(emp); sprintf(sum,"%0.10f",yuan); clear_z(sum); outtextxy(x+30,y+40,sum); emp[0]='/0'; e=emp; break; case '+': yuan = strtoflt(sum) + strtoflt(emp); sprintf(sum,"%0.10f",yuan); clear_z(sum); outtextxy(x+30,y+40,sum); emp[0]='/0'; e=emp; break; case '-': if (strtoflt(sum)>=strtoflt(emp)){ yuan = strtoflt(sum) - strtoflt(emp); sprintf(sum,"%0.10f",yuan); } else{ yuan=strtoflt(emp)-strtoflt(sum); sprintf(sum,"-%0.10f",yuan); } clear_z(sum); outtextxy(x+30,y+40,sum); emp[0]='/0'; e=emp; break; } } else{ if (ch_z==0){ outtextxy(x+30,y+40,emp); stpcpy(sum,emp); e=emp; } else outtextxy(x+30,y+40,sum); } ch='+'; ch_z=0; dian=0; break; case 49: bar (x + 10, y + 80 + 53 + 10, x + 60 - 10, y + 80 + 53 * 2 - 4); delay(8000); init(); for (i=0;i<=79;i++){ if (emp[i]=='/0') break; } if (ch_z==0){ *e='1';e++;*e='/0'; outtextxy(x+30,y+40,emp); } else{ outtextxy(x+30,y+40,sum); } break; case 50: bar (x + 60 + 10, y + 80 + 53 + 10, x + 60 * 2 - 10, y + 80 + 53 * 2 - 4); delay(8000); init(); for (i=0;i<=79;i++){ if (emp[i]=='/0') break; } if (ch_z==0){ *e='2';e++;*e='/0'; outtextxy(x+30,y+40,emp); } else{ outtextxy(x+30,y+40,sum); } break; case 51: bar (x + 60 * 2 + 10, y + 80 + 53 + 10, x + 60 * 3 - 10, y + 80 + 53 * 2 - 4); delay(8000); init(); for (i=0;i<=79;i++){ if (emp[i]=='/0') break; } if (ch_z==0){ *e='3';e++;*e='/0'; outtextxy(x+30,y+40,emp); } else{ outtextxy(x+30,y+40,sum); } break; case ENTER: bar (x + 60 * 3 + 10, y + 80 + 53 + 10, x + 60 * 4 - 10, y + 80 + 53 * 2 - 4); delay(8000); init(); if (ch!='0'){ switch(ch){ case '/': yuan = strtoflt(sum) / strtoflt(emp); sprintf(sum,"%0.10f",yuan); clear_z(sum); outtextxy(x+30,y+40,sum); emp[0]='/0'; e=emp; break; case '*': yuan = strtoflt(sum) * strtoflt(emp); sprintf(sum,"%0.10f",yuan); clear_z(sum); outtextxy(x+30,y+40,sum); emp[0]='/0'; e=emp; break; case '+': yuan = strtoflt(sum) + strtoflt(emp); sprintf(sum,"%0.10f",yuan); clear_z(sum); outtextxy(x+30,y+40,sum); emp[0]='/0'; e=emp; break; case '-': if (strtoflt(sum)>=strtoflt(emp)){ yuan = strtoflt(sum) - strtoflt(emp); sprintf(sum,"%0.10f",yuan); } else{ yuan=strtoflt(emp)-strtoflt(sum); sprintf(sum,"-%0.10f",yuan); } clear_z(sum); outtextxy(x+30,y+40,sum); emp[0]='/0'; e=emp; break; } } else{ if (ch_z==0){ outtextxy(x+30,y+40,emp); stpcpy(sum,emp); e=emp; } else{ outtextxy(x+30,y+40,sum); } } ch='0'; ch_z=1; dian=0; break; case 52: bar (x + 10, y + 80 + 53 * 2 + 10, x + 60 - 10, y + 80 + 53 * 3 - 4); delay(8000); init(); if (ch_z==0){ *e='4';e++;*e='/0'; outtextxy(x+30,y+40,emp); } else{ outtextxy(x+30,y+40,sum); } break; case 53: bar (x + 60 + 10, y + 80 + 53 * 2 + 10, x + 60 * 2 - 10, y + 80 + 53 * 3 - 4); delay(8000); init(); if (ch_z==0){ *e='5';e++;*e='/0'; outtextxy(x+30,y+40,emp); } else{ outtextxy(x+30,y+40,sum); } break; case 54: bar (x + 60 * 2 +10, y + 80 + 53 * 2 + 10, x + 60 * 3 - 10, y + 80 + 53 * 3 - 4); delay(8000); init(); if (ch_z==0){ *e='6';e++;*e='/0'; outtextxy(x+30,y+40,emp); } else{ outtextxy(x+30,y+40,sum); } break; case 46: bar (x + 60 * 3 + 10, y + 80 + 53 * 2 + 10, x + 60 * 4 - 10, y + 80 + 53 * 3 - 4); delay(8000); init(); if (dian==0){ if (ch_z==0){ *e='.';e++;*e='/0'; outtextxy(x+30,y+40,emp); } else{ outtextxy(x+30,y+40,sum); } } else{ if (ch_z==0) outtextxy(x+30,y+40,emp); else outtextxy(x+30,y+40,sum); } dian=1; break; case 55: bar (x + 10, y + 80 + 53 * 3 + 10, x + 60 - 10, y + 80 + 53 * 4 - 4); delay(8000); init(); if (ch_z==0){ *e='7';e++;*e='/0'; outtextxy(x+30,y+40,emp); } else{ outtextxy(x+30,y+40,sum); } break; case 56: bar (x + 60 + 10, y + 80 + 53 * 3 + 10, x + 60 * 2 -10, y + 80 + 53 * 4 - 4); delay(8000); init(); if (ch_z==0){ *e='8';e++;*e='/0'; outtextxy(x+30,y+40,emp); } else{ outtextxy(x+30,y+40,sum); } break; case 57: bar (x + 60 * 2 + 10, y + 80 + 53 * 3 + 10, x + 60 * 3 - 10, y + 80 + 53 * 4 - 4); delay(8000); init(); if (ch_z==0){ *e='9';e++;*e='/0'; outtextxy(x+30,y+40,emp); } else{ outtextxy(x+30,y+40,sum); } break; case 48: bar (x + 60 * 3 + 10, y + 80 + 53 * 3 + 10, x + 60 * 4 - 10, y + 80 + 53 * 4 - 4); delay(8000); init(); if (ch_z==0){ *e='0';e++;*e='/0'; outtextxy(x+30,y+40,emp); } else{ outtextxy(x+30,y+40,sum); } break; case 32: emp[0]='/0'; sum[0]='/0'; e=emp; s=sum; ch='0'; ch_z=0; dian=0; init(); break; case 8: delay(8000); for(i=0;i<=79;i++){ if (emp[i]=='/0') break; } if (i==0) break; if (i!=79&&i!=0){ i--; emp[i]='/0'; e=&emp[i]; } init(); outtextxy(x+30,y+40,emp); break; } } } /*---------------------------------------------------------------------*/ void init(void){ int x, y, x1, y1, i, j; char emp; x = (getmaxx() / 2) - 120; y = (getmaxy() / 2) - 150; x1 = (getmaxx() / 2) + 120; y1 = (getmaxy() / 2) + 150; cleardevice(); setbkcolor(3); setfillstyle(1, 15); setcolor(15); settextstyle(1,0,1); rectangle (x, y, x1, y1); rectangle (x - 7, y - 7, x1 + 7, y1 + 7); rectangle (x + 10, y + 10, x1 - 10, y + 80 - 10); line (x, y + 80, x1, y + 80); y = y + 80; for (j = 1; j <= 4; j++){ x = (getmaxx() / 2) - 120; for (i = 1; i <= 4; i++){ /* bar (x + 10, y + 10, x + 60 - 10, y + 60 - 10);*/ rectangle(x + 10, y + 10, x + 60 - 10, y + 60 - 10); if (j == 1){ if (i == 1) outtextxy(x + 20, y + 20, "/"); if (i == 2) outtextxy(x + 25, y + 20, "*"); if (i == 3) outtextxy(x + 27, y + 20, "-"); if (i == 4) outtextxy(x + 25, y + 20, "+"); } if (j == 2){ if (i == 1) outtextxy(x + 25, y + 20, "1"); if (i == 2) outtextxy(x + 25, y + 20, "2"); if (i == 3) outtextxy(x + 25, y + 20, "3"); if (i == 4) outtextxy(x + 25, y + 20, "="); } if (j == 3){ if (i == 1) outtextxy(x + 25, y + 20, "4"); if (i == 2) outtextxy(x + 25, y + 20, "5"); if (i == 3) outtextxy(x + 25, y + 20, "6"); if (i == 4) outtextxy(x + 25, y + 20, "."); } if (j == 4){ if (i == 1) outtextxy(x + 25, y + 20, "7"); if (i == 2) outtextxy(x + 25, y + 20, "8"); if (i == 3) outtextxy(x + 25, y + 20, "9"); if (i == 4) outtextxy(x + 25, y + 20, "0"); } x = x + 60; } y = y + 53; } } /*---------------------------------------------------------------------*/ int getkey(){ char lowbyte; int press; while(bioskey(1)==0); press = bioskey(0); press = press&0xff? press&0xff: press>>8; return(press); } double strtoflt(char *p) { double rtl=0.000000000000; double pnt=0.000000000000; double t = 10; int ispoint = 0; while (*p!='/0'||*p!='.'){ if(*p<'0'||*p>'9') break; rtl*=10; rtl+=*p-'0'; p++; } if (*p=='.'){ ispoint=1; p++; } while(ispoint&&*p!='/0'){ pnt+=(double)(*p-'0')/t; t*=10; p++; } rtl+=pnt; return (rtl); } /*-----------------------------------------------------------------------*/ void clear_z(char u[]){ int i; for(i=strlen(u)-1;i>=0;i--){ if (u[i]!='0') break; } if (u[i]=='.'){ u[i]='/0'; } else{ i++; u[i]='/0'; } } 扫雷: /* 模拟扫雷游戏 */ #include <graphics.h> #include <math.h> #include <stdio.h> #include <dos.h> #include <stdlib.h> #include <conio.h> #include <alloc.h> union REGS regs; int size=15;/*用于表示每个方块的大小(正方形的边长)*/ int pix,piy=50;/*pix,piy是矩阵的偏移量*/ char b[2]="1";/*用于显示方格周围的雷的个数*/ int pan[30][16];/*用于记录盘面的情况:0:没有、9:有雷、1~8:周围雷的个数*/ int pan1[30][16];/*pan1[][]纪录当前的挖雷情况,0:没有操作、1:打开了、2:标记了*/ int tt;/*纪录时间参数*/ int Eflags;/*用于标记鼠标按钮的有效性,0:有效,1:无效,2:这是鼠标的任意键等于重新开始*/ int Msinit(); void Draw(int x,int y,int sizex,int sizey); void Facedraw(int x,int y,int sizel,int k); void Dead(int sizel,int x,int y); void Setmouse(int xmax,int ymax,int x,int y); int Msread(int *xp,int *yp,int *bup,struct time t1,int k); void Draw1(int x,int y); int Open(int x,int y); float Random(); void Have(int sum,int x,int y,int xx,int yy); void Help(); void Coread(); void Ddraw2(int x,int y); /*下面是主函数*/ main() { int mode=VGAHI,devices=VGA;/*图形模式初始化的变量*/ char ams; /*鼠标操作中的标志变量*/ int xms,yms,bms; /*鼠标的状态变量*/ int i,j,k,k1=0; /*i,j,k是循环变量*/ int x=9,y=9,flags=0; /*x,y矩阵的大小*/ int sum=10; /*sum 盘面的雷的总数目,是个x,y的函数*/ int x1=0,y1=0; /*用于记录光标当前的位置*/ int x11=0,y11=0; /*暂时保存鼠标位置的值*/ int sizel=10; /*脸的大小*/ int cflags=1; /*这是菜单操作标志变量,没有弹出1,弹出0*/ struct time t1={0,0,0,0}; /*时间结构体,头文件已定义*/ int co[3]; /*暂时纪录历史纪录*/ void far *Map; /*用于保存鼠标图片*/ char name[3][20]; /*名字字符串,用于记录名字*/ FILE * p; /*文件指针用于文件操作*/ Msinit(); /*鼠标初始化*/ /*registerbgidriver(EGAVGA_driver);*/ initgraph(&devices,&mode,"C://tc"); /*图形模式初始化*/ /*为图片指针分配内存*/ if((Map=farmalloc(imagesize(0,0,20,20)))==NULL)/*图片的大小是20*20*/ { printf("Memory ererr!/n"); printf("Press any key to out!/n"); exit(1); } /*用于检验文件是否完整*/ while((p = fopen("score.dat", "r")) == NULL) /*如果不能打开就新建一个*/ { if((p = fopen("score.dat", "w")) == NULL)/*如果不能新建就提示错误并推出*/ { printf("The file cannot open!/n"); printf("Presss any key to exit!/n"); getch(); exit(1); } /*写入初始内容*/ fprintf(p,"%d %d %d,%s/n%s/n%s/n",999,999,999,"xiajia","xiajia","xiajia"); fclose(p); } /*暂时读出历史纪录。并用co[3]纪录*/ fscanf(p,"%d %d %d,",&co[0],&co[1],&co[2]); for(i=0;i<3;i++) fscanf(p,"%s/n",name[i]); fclose(p); Setmouse(1,1,615,460); /*设置鼠标的活动范围*/ pix=250-x*size/2; /*计算地雷按钮矩阵的左边*/ bss: b[0]='1'; /*游戏开始和重来的切入点*/ flags=0; /*测试中这个变量好像没有作用,但是为了逻辑的完整性暂时保留*/ k=0; Eflags=0; tt=0; cleardevice();/*清屏*/ setbkcolor(LIGHTCYAN); for(i=0;i<30;i++) /*盘面初始化*/ for(j=0;j<16;j++) { pan[i][j]=0; pan1[i][j]=0; } for(;;) /*用于生成雷的盘面情况*/ { i=(int)(x*Random()); j=(int)(y*Random()); if(pan[i][j]==0) { pan[i][j]=9; k=k+1; } if(k==sum) break; } for(i=0;i<x;i++)/*用于统计各点的周边情况*/ for(j=0;j<y;j++) { if(pan[i][j]==0)/*只有没有雷的才需要处理*/ { if(i-1>=0 && j-1>=0 && pan[i-1][j-1]==9) pan[i][j]++; if(j-1>=0 && pan[i][j-1]==9) pan[i][j]++; if(i+1<x && j-1>=0 && pan[i+1][j-1]==9) pan[i][j]++; if(i-1>=0 && pan[i-1][j]==9) pan[i][j]++; if(i+1<x && pan[i+1][j]==9) pan[i][j]++; if(i-1>=0 && j+1<y && pan[i-1][j+1]==9) pan[i][j]++; if(j+1<y && pan[i][j+1]==9) pan[i][j]++; if(i+1<x && j+1<y && pan[i+1][j+1]==9) pan[i][j]++; } } if(sum==10)/*画底座*/ { Draw(170,1,162,200); setcolor(1); outtextxy(175,5,"Game( )"); setcolor(4); outtextxy(175,5," G"); }/*小*/ else if(sum==40) { Draw(115,1,272,307); setcolor(1); outtextxy(120,5,"Game(G)"); setcolor(4); outtextxy(120,5," G"); }/*中*/ else if(sum==99) { Draw(40,1,470,307); setcolor(1); outtextxy(45,5,"Game(G)"); setcolor(4); outtextxy(45,5," G"); }/*大*/ setcolor(1);/*显示提示信息*/ outtextxy(100,350," : Help."); setcolor(4); outtextxy(100,350,"H"); setcolor(1); outtextxy(200,350," / : exit."); setcolor(4); outtextxy(200,350,"Q"); outtextxy(220,350,"ESC"); setcolor(1); outtextxy(330,350," : cores."); setcolor(4); outtextxy(330,350,"R"); Facedraw(250,30,sizel,2);/*显示控制按钮,脸型*/ for(i=0;i<x;i++)/*这一段用于描绘盘面*/ for(j=0;j<y;j++) { Draw(i*size+pix,j*size+piy,size,size); } Have(sum,pix+20,30,x,y);/*各项的初始显示*/ k=0; setfillstyle(1, 0); bar(460-pix,25,490-pix,40); setcolor(4); outtextxy(465-pix,30,"000"); /*下面这一段用于接收用户的控制,并做出反应*/ for(;;) { ams=Msread(&xms,&yms,&bms,t1,k);/*读取鼠标状态*/ /*下面一段用于保存并记录鼠标图片*/ if(flags!=0) { putimage(x11,y11,Map,COPY_PUT); } x11=xms; y11=yms; flags=1; /*这里插入菜单操作*/ if((xms>=pix-10 && xms<=pix+26 && yms>=2 && yms<=14 && bms==1) || ams=='g' || ams=='G')/*点中菜单的判断*/ { Draw(pix-10,14,100,88); /*画菜单*/ cflags=0; setcolor(1);/*下面显示菜单项*/ outtextxy(pix-4,19,"Restar(R)"); setcolor(4); outtextxy(pix-4,19," R"); setcolor(1);/*下面显示菜单项*/ outtextxy(pix-4,30,"Easy(E)"); setcolor(4); outtextxy(pix-4,30," E"); setcolor(1);/*下面显示菜单项*/ outtextxy(pix-4,41,"Nomall(N)"); setcolor(4); outtextxy(pix-4,41," N"); setcolor(1);/*下面显示菜单项*/ outtextxy(pix-4,52,"Hard(H)"); setcolor(4); outtextxy(pix-4,52," H"); setcolor(1);/*下面显示菜单项*/ outtextxy(pix-4,63,"Corse(C)"); setcolor(4); outtextxy(pix-4,63," C"); setcolor(1);/*下面显示菜单项*/ outtextxy(pix-4,74,"Help(L)"); setcolor(4); outtextxy(pix-4,74," L"); setcolor(1);/*下面显示菜单项*/ outtextxy(pix-4,85,"Quit(Q)"); setcolor(4); outtextxy(pix-4,85," Q"); bms=0; }/*完成菜单的描绘*/ /*这里是为了完全实现鼠标控制才加入的内容*/ if(Eflags==2 && (bms!=0 || ams!=-1)) { goto bss; } /*下面实现菜单的功能,每一项响应一个菜单项*/ if(cflags==0) { if((xms>=pix-6 && xms<=pix+85 && yms>=17 && yms<=28 && bms==1)|| (ams=='r' || ams=='R'))/*下面依次响应菜单中各项*/ { cflags=1; goto bss; } else if((xms>=pix-6 && xms<=pix+85 && yms>=28 && yms<=39 && bms==1) || ams=='e' || ams=='E') { cflags=1; x=9; y=9; sum=10; pix=250-x*size/2; goto bss; } else if((xms>=pix-6 && xms<=pix+85 && yms>=39 && yms<=50 && bms==1) || ams=='n' || ams=='N') { cflags=1; x=16; y=16; sum=40; pix=250-x*size/2; goto bss; } else if((xms>=pix-6 && xms<=pix+85 && yms>=50 && yms<=61 && bms==1) || ams=='h' || ams=='H') { cflags=1; x=30; y=16; sum=99; pix=250-x*size/2+25; goto bss; } else if((xms>=pix-6 && xms<=pix+85 && yms>=61 && yms<=72 && bms==1) || ams=='c' || ams=='C') { cflags=1; Coread(); } else if((xms>=pix-6 && xms<=pix+85 && yms>=72 && yms<=83 && bms==1) || ams=='l' || ams=='L') { cflags=1; Help(); } else if((xms>=pix-6 && xms<=pix+85 && yms>=83 && yms<=94 && bms==1) || ams=='q' || ams=='Q' || ams==27) { cflags=1; fclose(p); closegraph(); farfree(Map); exit(1); } else if(bms!=0) { cflags=1; goto bss; } }/*结束菜单功能的实现*/ /*在笑脸按钮处单击时重新开始*/ if(cflags!=0 && xms >=250-sizel-2 && yms >= 30-sizel-2 && xms<=250+sizel+2 && yms<=30+sizel+2 && bms==1 ) { goto bss; } if(Eflags==0 && cflags!=0 && xms-pix>=0 && yms-piy >=0 && xms<pix+x*size && yms<piy+y*size )/*111判断*/ { x1=(int)((xms-pix)/size);/*计算鼠标目前的按钮位置*/ y1=(int)((yms-piy)/size); if(ams==-1 && bms==1 && pan1[x1][y1]==0)/*单击鼠标左键*/ { if(k==0)/*k这里判断是否是第一次按下.0:不计时,1:开始计时*/ { gettime(&t1); k=1; } if(pan[x1][y1]!=9) { Draw1(x1,y1); Open(x,y); } else { Dead(sizel,x,y); k=0; } } if(ams==-1 && bms==2 && pan1[x1][y1]==0)/*单击鼠标右键*/ { delay(100); setcolor(10); circle(x1*size+pix+7,y1*size+piy+7,4); pan1[x1][y1]=2; Have(sum,pix+20,30,x,y); } else if(ams==-1 && bms==2 && pan1[x1][y1]==2)/*单击鼠标右键*/ { delay(100); Draw(x1*size+pix,y1*size+piy,size,size); pan1[x1][y1]=0; Have(sum,pix+20,30,x,y); }/*相当于鼠标右击*/ if(ams==-1 && bms==3 && pan1[x1][y1]==1) {/*相当于鼠标双击,有效性判断*/ i=0; if(x1-1>=0 && y1-1>=0 && pan1[x1-1][y1-1]==2) i++; if(y1-1>=0 && pan1[x1][y1-1]==2)i++; if(x1+1<x && y1-1>=0 && pan1[x1+1][y1-1]==2) i++; if(x1-1>=0 && pan1[x1-1][y1]==2) i++; if(x1+1<x && pan1[x1+1][y1]==2) i++; if(x1-1>=0 && y1+1<y && pan1[x1-1][y1+1]==2) i++; if(y1+1<y && pan1[x1][y1+1]==2) i++; if(x1+1<x && y1+1<y && pan1[x1+1][y1+1]==2) i++; if(i==pan[x1][y1]) /*有效*/ { if(x1-1>=0 && y1-1>=0 && pan1[x1-1][y1-1]!=2) { if(pan[x1-1][y1-1]!=9) Draw1(x1-1,y1-1); else { Dead(sizel,x,y); k=0; } } if(y1-1>=0 && pan1[x1][y1-1]!=2) { if(pan[x1][y1-1]!=9) Draw1(x1,y1-1); else { Dead(sizel,x,y); k=0; } } if(x1+1<x && y1-1>=0 && pan1[x1+1][y1-1]!=2) { if(pan[x1+1][y1-1]!=9) Draw1(x1+1,y1-1); else { Dead(sizel,x,y); k=0; } } if(x1-1>=0 && pan1[x1-1][y1]!=2) { if(pan[x1-1][y1]!=9) Draw1(x1-1,y1); else { Dead(sizel,x,y); k=0; } } if(x1+1<x && pan1[x1+1][y1]!=2) { if(pan[x1+1][y1]!=9) Draw1(x1+1,y1); else { Dead(sizel,x,y); k=0; } } if(x1-1>=0 && y1+1<y && pan1[x1-1][y1+1]!=2) { if(pan[x1-1][y1+1]!=9) Draw1(x1-1,y1+1); else { Dead(sizel,x,y); k=0; } } if(y1+1<y && pan1[x1][y1+1]!=2) { if(pan[x1][y1+1]!=9) Draw1(x1,y1+1); else { Dead(sizel,x,y); k=0; } } if(x1+1<x && y1+1<y &&pan1[x1+1][y1+1]!=2) { if(pan[x1+1][y1+1]!=9) Draw1(x1+1,y1+1); else { Dead(sizel,x,y); k=0; } } Open(x,y); } } /*胜利条件*/ k1=0; for(i=0;i<x;i++) for(j=0;j<y;j++) if(pan1[i][j]!=1) k1++; if(k1==sum) { for(i=0;i<x;i++) for(j=0;j<y;j++) if(pan1[i][j]==0) { setcolor(10);circle(i*size+pix+7,j*size+piy+7,4); } Facedraw(250,30,sizel,3); if(x==9 && tt<co[0]) {j=0;co[0]=tt;i=0;} if(x==16 && tt<co[1]) {j=1;co[1]=tt;i=0;} if(x==30 && tt<co[2]) {j=2;co[2]=tt;i=0;} if(i==0) { Draw(10,10,300,55); setcolor(4); outtextxy(20,15,"You break the corse!"); outtextxy(20,25,"Please input your name(0 - 19):"); setfillstyle(1, 14); bar(20,35,200,50); for(i=0;i<19;i++) { name[j][i]=getch(); if(name[j][i]==8) i=i-2; if(name[j][i]==13) {name[j][i]='/0';break;} name[j][i+1]='/0'; setfillstyle(1, 14); bar(20,35,200,50); setcolor(1); outtextxy(20,40,name[j]); } if((p = fopen("score.dat", "w")) == NULL) { printf("The file cannot open!/n"); exit(1); } fprintf(p,"%d %d %d,",co[0],co[1],co[2]); for(i=0;i<3;i++) fprintf(p,"%s/n",name[i]); fclose(p); Coread(); } getch(); goto bss; } }/*结束111的判断*/ /*下面是一些快捷功能键的定义*/ if(ams=='q'||ams=='Q'|| ams==27 ) {fclose(p);closegraph();farfree(Map);exit(1);} /*退出主程序的唯一出口*/ if(ams=='c'||ams=='C') goto bss; /*重来*/ if(ams=='h'||ams=='H') {Help();k=0;} /*帮助文档*/ if(ams=='r'||ams=='R') {Coread();k=0;} /*察看成绩*/ getimage(xms,yms,xms+20,yms+20,Map); Ddraw2(xms,yms); delay(10); }/*结束鼠标循环读取的死循环*/ } /*++++++++主函数结束++++++++*/ /*这个函数用于实现鼠标的初始化*/ int Msinit() { int recored; regs.x.ax=0; int86 (0x33, & regs, & regs); recored=regs.x.ax; if(recored==0) { printf("Mouse not found or Mouse driver not installed./n"); return 0; } else return recored; } /*下面这个子程序是完成描绘一个按钮*/ void Draw(int x,int y,int sizex,int sizey)/* x, y为左上角坐标sizex,sizey为长和宽*/ { int sizx=sizex-1; int sizy=sizey-1; setcolor(15);/*这里最好用白色*/ line(x,y,x+sizx-1,y); line(x,y+1,x+sizx-2,y+1); line(x,y,x,y+sizy-1); line(x+1,y,x+1,y+sizy-2); setcolor(8);/*这里最好用深灰色*/ line(x+1,y+sizy,x+sizx,y+sizy); line(x+2,y+sizy-1,x+sizx,y+sizy-1); line(x+sizx-1,y+1,x+sizx-1,y+sizy); line(x+sizx,y+2,x+sizx,y+sizy); setcolor(7);/*这里最好用灰色*/ putpixel(x,y+sizy,3); putpixel(x+1,y+sizy-1,3); putpixel(x+sizx,y,3); putpixel(x+sizx-1,y+1,3); setfillstyle(1, 7);/*这里最好用灰色,设置填充模式*/ bar(x+2,y+2,x+sizx-2,y+sizy-2); } /*下面是一些画图程序*/ /*形参x,y笑脸的中心坐标,sizel脸的大小(半径), k为要描述的脸型,1:哭、2:平常、3:笑*/ void Facedraw(int x,int y,int sizel,int k) {Draw(x-sizel-3,y-sizel-3,2*(sizel+4),2*(sizel+4));/*画一个按钮*/ setcolor(14); setfillstyle(1, 14); pieslice(x, y, 0, 360, sizel);/*画一个黄色的圆面*/ setfillstyle(1, 0); setcolor(0); if(k==1)/*失败*/ { line(x-sizel*7/20,y-sizel*7/20,x-sizel*3/20,y-sizel*3/20);/*画两个差表示眼睛*/ line(x-sizel*7/20,y-sizel*3/20,x-sizel*3/20,y-sizel*7/20); line(x+sizel*3/20,y-sizel*7/20,x+sizel*7/20,y-sizel*3/20); line(x+sizel*3/20,y-sizel*3/20,x+sizel*7/20,y-sizel*7/20); arc(x,y+sizel,20,160, sizel/2); } if(k==2)/*平常*/ { bar(x-sizel*7/20,y-sizel*7/20,x-sizel*3/20,y-sizel*3/20); bar(x+sizel*3/20,y-sizel*7/20,x+sizel*7/20,y-sizel*3/20); arc(x,y,200,340, sizel*3/4); } if(k==3)/*成功*/ { bar(x-sizel/2,y-sizel/2,x-sizel*3/20,y-sizel*3/20); bar(x+sizel*3/20,y-sizel/2,x+sizel/2,y-sizel*3/20); line(x-sizel*3/20,y-sizel/2,x+sizel*3/20,y-sizel/2); line(x-sizel/2,y-sizel*5/20,x-sizel,y); line(x+sizel/2,y-sizel*5/20,x+sizel,y); arc(x,y,200,340, sizel*3/4); /*嘴巴*/ } } /*死亡后的处理程序*/ /*x,y要判断的点的坐标,sizel为脸的大小*/ void Dead(int sizel,int x,int y) { int i,j;/*循环变量*/ setcolor(4); for(i=0;i<x;i++) for(j=0;j<y;j++) if(pan[i][j]==9) { circle(i*size+pix+7,j*size+piy+7,4); }/*用红色的圆圈标记有雷的方块*/ Facedraw(250,30,sizel,1); Eflags=1; } /*下面的函数用于实现设置鼠标的移动范围*/ /*xmax,ymax为左上角的坐标x,y矩阵的大小*/ void Setmouse(int xmax,int ymax,int x,int y) { int left,right,top,buttom;/*这四个变量用于确定移动的左上角和右下角*/ left=xmax; right=x; top=ymax; buttom=y; regs.x.ax=7; regs.x.cx=left; regs.x.dx=right; int86(0x33,& regs,& regs); regs.x.ax=8; regs.x.cx=top; regs.x.dx=buttom; int86(0x33,& regs,& regs); } /*下面这个函数用于实现鼠标的读取*/ /*xp,yp,bup分别为鼠标的位置和按键情况,t1,k是时间现实参数,t1为开始时间,k为开始标记*/ int Msread(int *xp,int *yp,int *bup,struct time t1,int k) { int x0=*xp,y0=*yp,bu0=*bup; int xnew,ynew,ch; int tt1=0;/*用于记录时间差*/ struct time t2; char ttt[4]="000"; do { if(kbhit()) return getch(); regs.x.ax=3; int86(0x33,& regs,& regs); xnew=regs.x.cx; ynew=regs.x.dx; *bup=regs.x.bx; /*下面用于显示时间*/ if(k==1)/*如果已经开始就计算时间差*/ { gettime(&t2); tt1=(t2.ti_hour- t1.ti_hour)*3600 + (t2.ti_min- t1.ti_min)*60 + t2.ti_sec - t1.ti_sec;/*有待改进*/ if(tt1<=999 && tt!=tt1)/*当时间差有改变时,才显示*/ { tt=tt1; ttt[0]=(tt-tt%100)/100+48; ttt[1]=(tt%100-tt%10)/10 +48; ttt[2]=tt%10+48; setfillstyle(1, 0); bar(460-pix,25,490-pix,40); setcolor(4); outtextxy(465-pix,30,ttt); } } } while(xnew==x0&&ynew==y0&&*bup==bu0); *xp=xnew; *yp=ynew; return -1;/*键盘无输入时返回-1,其次返回键盘值*/ } void Draw1(int x,int y)/*这个函数用于在x,y的位置描绘开后的情况*/ { setfillstyle(1, 7); bar(x*size+pix,y*size+piy,x*size+size+pix-1,y*size+size+piy-1); /*在四个角上画上点标记*/ /*putpixel(x*size+pix,y*size+piy,8); putpixel(x*size+size+pix-1,y*size+size+piy-1,8); putpixel(x*size+pix,y*size+size+piy-1,8); putpixel(x*size+size+pix-1,y*size+piy,8);*/ setcolor(8); setlinestyle(1, 0, 1); rectangle(x*size+pix,y*size+piy,x*size+size+pix-1,y*size+size+piy-1); setlinestyle(0, 0, 1); if(pan[x][y]!=0)/*没有雷的话不做显示*/ { b[0]=pan[x][y]+48; if(pan[x][y]!=7)/*防止字的颜色和背景颜色相同*/ setcolor(pan[x][y]); else setcolor(9); outtextxy (x*size+pix+3,y*size+piy+3,b); } pan1[x][y]=1;/*在pan1[][]中标记这一点的挖雷情况*/ } /*自开函数*/ int Open(int x,int y)/*函数中引入pan2[][]的目的是为了增加自开的效率,但是还是有不足之处*/ { int i,j,k; int pan2[30][16]={0};/*pan2[][],临时纪录盘面的自开情况,0没有自开过,1:已经自开过(30 这里有危险的技术性问题!!!)*/ for(;;) { k=0;/*是一个标记变量*/ for(i=0;i<x;i++) for(j=0;j<y;j++) { if (pan[i][j]==0 && pan1[i][j]==1 && pan2[i][j]==0)/*如果满足下面条件,没有雷,已经打开,没有自开过就继续*/ { pan2[i][j]=1;/*标记自开过*/ k=k+1; /*开周围的点*/ if(i-1>=0 && j-1>=0 && pan1[i-1][j-1]==0) Draw1(i-1,j-1); /*左上方*/ if(j-1>=0 && pan1[i][j-1]==0) Draw1(i,j-1); /*上方*/ if(i+1<x && j-1>=0 && pan1[i+1][j-1]==0) Draw1(i+1,j-1); /*右上方*/ if(i-1>=0 && pan1[i-1][j]==0) Draw1(i-1,j); /*左方*/ if(i+1<x && pan1[i+1][j]==0) Draw1(i+1,j); /*右方*/ if(i-1>=0 && j+1<y && pan1[i-1][j+1]==0) Draw1(i-1,j+1); /*左下方*/ if(j+1<y && pan1[i][j+1]==0) Draw1(i,j+1); /*下方*/ if(i+1<x && j+1<y && pan1[i+1][j+1]==0) Draw1(i+1,j+1); /*右下方*/ } } if(k==0) return 0;/*没有新的自开点时退出*/ } } float Random()/*随即数生成函数,加入了时间变量目的在于加强它的随机性*/ {float aa; int i,j; struct time t; gettime(&t); i=t.ti_min+t.ti_hour+t.ti_sec+t.ti_hund; for(j=0;j<i;j++) rand(); aa=rand()/32767.0; return aa;/*返回产生的随机数(0-1)*/ } /*下面是一个显示剩余雷数目的函数*/ void Have(int sum,int x,int y,int xx,int yy)/*游戏中雷的总数目不能多余99颗,sum 为雷的总数目,x,y为显示的地点*/ { int i,j,k=0; char a[3]="1"; for(i=0;i<xx;i++) for(j=0;j<yy;j++) {if (pan1[i][j]==2) k++;}/*统计一共标记了多少*/ k=sum-k;/*剩下了多少*/ if(k<0) k=0; a[0]=(k-(k%10))/10+48;/*字符转换*/ a[1]=k%10+48; setfillstyle(1, 0); bar(x-5,y-5,x+20,y+10);/*在原点涂黑*/ setcolor(4); outtextxy(x,y,a);/*显示数目*/ } /*下面是帮助函数*/ void Help() { Draw(40,1,560,160); setcolor(1); outtextxy(300,10,"Help"); setcolor(4); outtextxy(50,30,"Welcome to play this game. The mouse is supplied."); outtextxy(50,40,"Please press left button of the mouse where there is no boom."); outtextxy(50,50,"If you think there is a boom please press right button."); outtextxy(50,60,"You can choose the size of the game with press the right buttons."); outtextxy(50,70,"'Big' means 99 booms,'Normal' means 40 booms,'Small' means 10 booms."); outtextxy(50,80,"You can press the laugh-face-button or press C to play again."); outtextxy(50,90,"When you fail or success you can press any key to play again. "); outtextxy(50,100,"Whenever you want to quit this game please press Q. "); outtextxy(50,110,"If you find out all booms then you are winning. "); setcolor(9); outtextxy(50,140,"Press any key to play again."); Eflags=2; } void Coread()/*这个函数用于读取纪录并显示*/ { int co[3],i; char name[3][20]; char cco[3][4]; FILE * p; for(i=0;i<3;i++) cco[i][3]='/0'; if((p = fopen("score.dat", "rb")) == NULL) { printf("The file cannot open!/n"); exit(1); } fscanf(p,"%d %d %d,",&co[0],&co[1],&co[2]); for(i=0;i<3;i++) fscanf(p,"%s/n",name[i]); fclose(p); Draw(10,20,320,90); setcolor(1); outtextxy(140,30,"HighCore"); setcolor(2); outtextxy(20,50,"Easy"); outtextxy(20,60,"Normal"); outtextxy(20,70,"Hard"); for(i=0;i<3;i++) { cco[i][0]=(co[i]-co[i]%100)/100+48; cco[i][1]=(co[i]%100-co[i]%10)/10 +48; cco[i][2]=co[i]%10+48; } setcolor(3); outtextxy(100,50,cco[0]); outtextxy(100,60,cco[1]); outtextxy(100,70,cco[2]); setcolor(5); outtextxy(150,50,name[0]); outtextxy(150,60,name[1]); outtextxy(150,70,name[2]); setcolor(9); outtextxy(30,85,"Press any key to play again."); Eflags=2; } /*这个函数用来画鼠标光标,x,y,为左上角坐标,大小为20*20*/ void Ddraw2(int x,int y) { /*这个地方暂时使用简易光标,程序成熟以后使用复杂的*/ setcolor(1); line(x,y,x,y+18); line(x+1,y,x+1,y+18); line(x,y,x+12,y+12); line(x+1,y,x+13,y+12); line(x,y+18,x+4,y+14); line(x,y+17,x+4,y+13); line(x+4,y+14,x+6,y+20); line(x+4,y+13,x+6,y+19); line(x+6,y+20,x+10,y+18); line(x+6,y+19,x+10,y+17); line(x+10,y+18,x+8,y+12); line(x+10,y+17,x+8,y+11); line(x+8,y+12,x+12,y+12); line(x+8,y+11,x+12,y+11); } /*直接编译运行*/ 贪吃蛇: #define N 200 #include <graphics.h> #include <stdlib.h> #include <dos.h> #define LEFT 0x4b00 #define RIGHT 0x4d00 #define DOWN 0x5000 #define UP 0x4800 #define ESC 0x011b int i,key; int score=0;/*得分*/ int gamespeed=50000;/*游戏速度自己调整*/ struct Food { int x;/*食物的横坐标*/ int y;/*食物的纵坐标*/ int yes;/*判断是否要出现食物的变量*/ }food;/*食物的结构体*/ struct Snake { int x[N]; int y[N]; int node;/*蛇的节数*/ int direction;/*蛇移动方向*/ int life;/* 蛇的生命,0活着,1死亡*/ }snake; void Init(void);/*图形驱动*/ void Close(void);/*图形结束*/ void DrawK(void);/*开始画面*/ void GameOver(void);/*结束游戏*/ void GamePlay(void);/*玩游戏具体过程*/ void PrScore(void);/*输出成绩*/ /*主函数*/ void main(void) { Init();/*图形驱动*/ DrawK();/*开始画面*/ GamePlay();/*玩游戏具体过程*/ Close();/*图形结束*/ } /*图形驱动*/ void Init(void) { int gd=DETECT,gm; initgraph(&gd,&gm,"c://tc"); cleardevice(); } /*开始画面,左上角坐标为(50,40),右下角坐标为(610,460)的围墙*/ void DrawK(void) { /*setbkcolor(LIGHTGREEN);*/ setcolor(11); setlinestyle(SOLID_LINE,0,THICK_WIDTH);/*设置线型*/ for(i=50;i<=600;i+=10)/*画围墙*/ { rectangle(i,40,i+10,49); /*上边*/ rectangle(i,451,i+10,460);/*下边*/ } for(i=40;i<=450;i+=10) { rectangle(50,i,59,i+10); /*左边*/ rectangle(601,i,610,i+10);/*右边*/ } } /*玩游戏具体过程*/ void GamePlay(void) { randomize();/*随机数发生器*/ food.yes=1;/*1表示需要出现新食物,0表示已经存在食物*/ snake.life=0;/*活着*/ snake.direction=1;/*方向往右*/ snake.x[0]=100;snake.y[0]=100;/*蛇头*/ snake.x[1]=110;snake.y[1]=100; snake.node=2;/*节数*/ PrScore();/*输出得分*/ while(1)/*可以重复玩游戏,压ESC键结束*/ { while(!kbhit())/*在没有按键的情况下,蛇自己移动身体*/ { if(food.yes==1)/*需要出现新食物*/ { food.x=rand()%400+60; food.y=rand()%350+60; while(food.x%10!=0)/*食物随机出现后必须让食物能够在整格内,这样才可以让蛇吃到*/ food.x++; while(food.y%10!=0) food.y++; food.yes=0;/*画面上有食物了*/ } if(food.yes==0)/*画面上有食物了就要显示*/ { setcolor(GREEN); rectangle(food.x,food.y,food.x+10,food.y-10); } for(i=snake.node-1;i>0;i--)/*蛇的每个环节往前移动,也就是贪吃蛇的关键算法*/ { snake.x[i]=snake.x[i-1]; snake.y[i]=snake.y[i-1]; } /*1,2,3,4表示右,左,上,下四个方向,通过这个判断来移动蛇头*/ switch(snake.direction) { case 1:snake.x[0]+=10;break; case 2: snake.x[0]-=10;break; case 3: snake.y[0]-=10;break; case 4: snake.y[0]+=10;break; } for(i=3;i<snake.node;i++)/*从蛇的第四节开始判断是否撞到自己了,因为蛇头为两节,第三节不可能拐过来*/ { if(snake.x[i]==snake.x[0]&&snake.y[i]==snake.y[0]) { GameOver();/*显示失败*/ snake.life=1; break; } } if(snake.x[0]<55||snake.x[0]>595||snake.y[0]<55|| snake.y[0]>455)/*蛇是否撞到墙壁*/ { GameOver();/*本次游戏结束*/ snake.life=1; /*蛇死*/ } if(snake.life==1)/*以上两种判断以后,如果蛇死就跳出内循环,重新开始*/ break; if(snake.x[0]==food.x&&snake.y[0]==food.y)/*吃到食物以后*/ { setcolor(0);/*把画面上的食物东西去掉*/ rectangle(food.x,food.y,food.x+10,food.y-10); snake.x[snake.node]=-20;snake.y[snake.node]=-20; /*新的一节先放在看不见的位置,下次循环就取前一节的位置*/ snake.node++;/*蛇的身体长一节*/ food.yes=1;/*画面上需要出现新的食物*/ score+=10; PrScore();/*输出新得分*/ } setcolor(4);/*画出蛇*/ for(i=0;i<snake.node;i++) rectangle(snake.x[i],snake.y[i],snake.x[i]+10, snake.y[i]-10); delay(gamespeed); setcolor(0);/*用黑色去除蛇的的最后一节*/ rectangle(snake.x[snake.node-1],snake.y[snake.node-1], snake.x[snake.node-1]+10,snake.y[snake.node-1]-10); } /*endwhile(!kbhit)*/ if(snake.life==1)/*如果蛇死就跳出循环*/ break; key=bioskey(0);/*接收按键*/ if(key==ESC)/*按ESC键退出*/ break; else if(key==UP&&snake.direction!=4) /*判断是否往相反的方向移动*/ snake.direction=3; else if(key==RIGHT&&snake.direction!=2) snake.direction=1; else if(key==LEFT&&snake.direction!=1) snake.direction=2; else if(key==DOWN&&snake.direction!=3) snake.direction=4; }/*endwhile(1)*/ } /*游戏结束*/ void GameOver(void) { cleardevice(); PrScore(); setcolor(RED); settextstyle(0,0,4); outtextxy(200,200,"GAME OVER"); getch(); } /*输出成绩*/ void PrScore(void) { char str[10]; setfillstyle(SOLID_FILL,YELLOW); bar(50,15,220,35); setcolor(6); settextstyle(0,0,2); sprintf(str,"score:%d",score); outtextxy(55,20,str); } /*图形结束*/ void Close(void) { getch(); closegraph(); } 五子棋: #include <stdio.h> #include <bios.h> #include <ctype.h> #include <conio.h> #include <dos.h> #define CROSSRU 0xbf /*右上角点*/ #define CROSSLU 0xda /*左上角点*/ #define CROSSLD 0xc0 /*左下角点*/ #define CROSSRD 0xd9 /*右下角点*/ #define CROSSL 0xc3 /*左边*/ #define CROSSR 0xb4 /*右边*/ #define CROSSU 0xc2 /*上边*/ #define CROSSD 0xc1 /*下边*/ #define CROSS 0xc5 /*十字交叉点*/ /*定义棋盘左上角点在屏幕上的位置*/ #define MAPXOFT 5 #define MAPYOFT 2 /*定义1号玩家的操作键键码*/ #define PLAY1UP 0x1157/*上移--'W'*/ #define PLAY1DOWN 0x1f53/*下移--'S'*/ #define PLAY1LEFT 0x1e41/*左移--'A'*/ #define PLAY1RIGHT 0x2044/*右移--'D'*/ #define PLAY1DO 0x3920/*落子--空格键*/ /*定义2号玩家的操作键键码*/ #define PLAY2UP 0x4800/*上移--方向键up*/ #define PLAY2DOWN 0x5000/*下移--方向键down*/ #define PLAY2LEFT 0x4b00/*左移--方向键left*/ #define PLAY2RIGHT 0x4d00/*右移--方向键right*/ #define PLAY2DO 0x1c0d/*落子--回车键Enter*/ /*若想在游戏中途退出, 可按 Esc 键*/ #define ESCAPE 0x011b /*定义棋盘上交叉点的状态, 即该点有无棋子 */ /*若有棋子, 还应能指出是哪个玩家的棋子 */ #define CHESSNULL 0 /*没有棋子*/ #define CHESS1 'O'/*一号玩家的棋子*/ #define CHESS2 'X'/*二号玩家的棋子*/ /*定义按键类别*/ #define KEYEXIT 0/*退出键*/ #define KEYFALLCHESS 1/*落子键*/ #define KEYMOVECURSOR 2/*光标移动键*/ #define KEYINVALID 3/*无效键*/ /*定义符号常量: 真, 假 --- 真为1, 假为0 */ #define TRUE 1 #define FALSE 0 /**********************************************************/ /* 定义数据结构 */ /*棋盘交叉点坐标的数据结构*/ struct point { int x,y; }; /**********************************************************/ /*自定义函数原型说明 */ void Init(void); int GetKey(void); int CheckKey(int press); int ChangeOrder(void); int ChessGo(int Order,struct point Cursor); void DoError(void); void DoOK(void); void DoWin(int Order); void MoveCursor(int Order,int press); void DrawCross(int x,int y); void DrawMap(void); int JudgeWin(int Order,struct point Cursor); int JudgeWinLine(int Order,struct point Cursor,int direction); void ShowOrderMsg(int Order); void EndGame(void); /**********************************************************/ /**********************************************************/ /* 定义全局变量 */ int gPlayOrder; /*指示当前行棋方 */ struct point gCursor; /*光标在棋盘上的位置 */ char gChessBoard[19][19];/*用于记录棋盘上各点的状态*/ /**********************************************************/ /**********************************************************/ /*主函数*/ void main() { int press; int bOutWhile=FALSE;/*退出循环标志*/ printf("Welcome www.schoolhacker.com"); Init();/*初始化图象,数据*/ while(1) { press=GetKey();/*获取用户的按键值*/ switch(CheckKey(press))/*判断按键类别*/ { /*是退出键*/ case KEYEXIT: clrscr();/*清屏*/ bOutWhile = TRUE; break; /*是落子键*/ case KEYFALLCHESS: if(ChessGo(gPlayOrder,gCursor)==FALSE)/*走棋*/ DoError();/*落子错误*/ else { DoOK();/*落子正确*/ /*如果当前行棋方赢棋*/ if(JudgeWin(gPlayOrder,gCursor)==TRUE) { DoWin(gPlayOrder); bOutWhile = TRUE;/*退出循环标志置为真*/ } /*否则*/ else /*交换行棋方*/ ChangeOrder(); ShowOrderMsg(gPlayOrder); } break; /*是光标移动键*/ case KEYMOVECURSOR: MoveCursor(gPlayOrder,press); break; /*是无效键*/ case KEYINVALID: break; } if(bOutWhile==TRUE) break; } /*游戏结束*/ EndGame(); } /**********************************************************/ /*界面初始化,数据初始化*/ void Init(void) { int i,j; char *Msg[]= { "Player1 key:", " UP----w", " DOWN--s", " LEFT--a", " RIGHT-d", " DO----space", "", "Player2 key:", " UP----up", " DOWN--down", " LEFT--left", " RIGHT-right", " DO----ENTER", "", "exit game:", " ESC", NULL, }; /* 先手方为1号玩家 */ gPlayOrder = CHESS1; /* 棋盘数据清零, 即棋盘上各点开始的时候都没有棋子 */ for(i=0;i<19;i++) for(j=0;j<19;j++) gChessBoard[i][j]=CHESSNULL; /*光标初始位置*/ gCursor.x=gCursor.y=0; /*画棋盘*/ textmode(C40); DrawMap(); /*显示操作键说明*/ i=0; textcolor(BROWN); while(Msg[i]!=NULL) { gotoxy(25,3+i); cputs(Msg[i]); i++; } /*显示当前行棋方*/ ShowOrderMsg(gPlayOrder); /*光标移至棋盘的左上角点处*/ gotoxy(gCursor.x+MAPXOFT,gCursor.y+MAPYOFT); } /*画棋盘*/ void DrawMap(void) { int i,j; clrscr(); for(i=0;i<19;i++) for(j=0;j<19;j++) DrawCross(i,j); } /*画棋盘上的交叉点*/ void DrawCross(int x,int y) { gotoxy(x+MAPXOFT,y+MAPYOFT); /*交叉点上是一号玩家的棋子*/ if(gChessBoard[x][y]==CHESS1) { textcolor(LIGHTBLUE); putch(CHESS1); return; } /*交叉点上是二号玩家的棋子*/ if(gChessBoard[x][y]==CHESS2) { textcolor(LIGHTBLUE); putch(CHESS2); return; } textcolor(GREEN); /*左上角交叉点*/ if(x==0&&y==0) { putch(CROSSLU); return; } /*左下角交叉点*/ if(x==0&&y==18) { putch(CROSSLD); return; } /*右上角交叉点*/ if(x==18&&y==0) { putch(CROSSRU); return; } /*右下角交叉点*/ if(x==18&&y==18) { putch(CROSSRD); return; } /*左边界交叉点*/ if(x==0) { putch(CROSSL); return; } /*右边界交叉点*/ if(x==18) { putch(CROSSR); return; } /*上边界交叉点*/ if(y==0) { putch(CROSSU); return; } /*下边界交叉点*/ if(y==18) { putch(CROSSD); return; } /*棋盘中间的交叉点*/ putch(CROSS); } /*交换行棋方*/ int ChangeOrder(void) { if(gPlayOrder==CHESS1) gPlayOrder=CHESS2; else gPlayOrder=CHESS1; return(gPlayOrder); } /*获取按键值*/ int GetKey(void) { char lowbyte; int press; while (bioskey(1) == 0) ;/*如果用户没有按键,空循环*/ press=bioskey(0); lowbyte=press&0xff; press=press&0xff00 + toupper(lowbyte); return(press); } /*落子错误处理*/ void DoError(void) { sound(1200); delay(50); nosound(); } /*赢棋处理*/ void DoWin(int Order) { sound(1500);delay(100); sound(0); delay(50); sound(800); delay(100); sound(0); delay(50); sound(1500);delay(100); sound(0); delay(50); sound(800); delay(100); sound(0); delay(50); nosound(); textcolor(RED+BLINK); gotoxy(25,20); if(Order==CHESS1) cputs("PLAYER1 WIN!"); else cputs("PLAYER2 WIN!"); gotoxy(25,21); cputs(" //<^+^>/"); getch(); } /*走棋*/ int ChessGo(int Order,struct point Cursor) { /*判断交叉点上有无棋子*/ if(gChessBoard[Cursor.x][Cursor.y]==CHESSNULL) { /*若没有棋子, 则可以落子*/ gotoxy(Cursor.x+MAPXOFT,Cursor.y+MAPYOFT); textcolor(LIGHTBLUE); putch(Order); gotoxy(Cursor.x+MAPXOFT,Cursor.y+MAPYOFT); gChessBoard[Cursor.x][Cursor.y]=Order; return TRUE; } else return FALSE; } /*判断当前行棋方落子后是否赢棋*/ int JudgeWin(int Order,struct point Cursor) { int i; for(i=0;i<4;i++) /*判断在指定方向上是否有连续5个行棋方的棋子*/ if(JudgeWinLine(Order,Cursor,i)) return TRUE; return FALSE; } /*判断在指定方向上是否有连续5个行棋方的棋子*/ int JudgeWinLine(int Order,struct point Cursor,int direction) { int i; struct point pos,dpos; const int testnum = 5; int count; switch(direction) { case 0:/*在水平方向*/ pos.x=Cursor.x-(testnum-1); pos.y=Cursor.y; dpos.x=1; dpos.y=0; break; case 1:/*在垂直方向*/ pos.x=Cursor.x; pos.y=Cursor.y-(testnum-1); dpos.x=0; dpos.y=1; break; case 2:/*在左下至右上的斜方向*/ pos.x=Cursor.x-(testnum-1); pos.y=Cursor.y+(testnum-1); dpos.x=1; dpos.y=-1; break; case 3:/*在左上至右下的斜方向*/ pos.x=Cursor.x-(testnum-1); pos.y=Cursor.y-(testnum-1); dpos.x=1; dpos.y=1; break; } count=0; for(i=0;i<testnum*2+1;i++)/*????????i<testnum*2-1*/ { if(pos.x>=0&&pos.x<=18&&pos.y>=0&&pos.y<=18) { if(gChessBoard[pos.x][pos.y]==Order) { count++; if(count>=testnum) return TRUE; } else count=0; } pos.x+=dpos.x; pos.y+=dpos.y; } return FALSE; } /*移动光标*/ void MoveCursor(int Order,int press) { switch(press) { case PLAY1UP: if(Order==CHESS1&&gCursor.y>0) gCursor.y--; break; case PLAY1DOWN: if(Order==CHESS1&&gCursor.y<18) gCursor.y++; break; case PLAY1LEFT: if(Order==CHESS1&&gCursor.x>0) gCursor.x--; break; case PLAY1RIGHT: if(Order==CHESS1&&gCursor.x<18) gCursor.x++; break; case PLAY2UP: if(Order==CHESS2&&gCursor.y>0) gCursor.y--; break; case PLAY2DOWN: if(Order==CHESS2&&gCursor.y<18) gCursor.y++; break; case PLAY2LEFT: if(Order==CHESS2&&gCursor.x>0) gCursor.x--; break; case PLAY2RIGHT: if(Order==CHESS2&&gCursor.x<18) gCursor.x++; break; } gotoxy(gCursor.x+MAPXOFT,gCursor.y+MAPYOFT); } /*游戏结束处理*/ void EndGame(void) { textmode(C80); } /*显示当前行棋方*/ void ShowOrderMsg(int Order) { gotoxy(6,MAPYOFT+20); textcolor(LIGHTRED); if(Order==CHESS1) cputs("Player1 go!"); else cputs("Player2 go!"); gotoxy(gCursor.x+MAPXOFT,gCursor.y+MAPYOFT); } /*落子正确处理*/ void DoOK(void) { sound(500); delay(70); sound(600); delay(50); sound(1000); delay(100); nosound(); } /*检查用户的按键类别*/ int CheckKey(int press) { if(press==ESCAPE) return KEYEXIT;/*是退出键*/ else if ( ( press==PLAY1DO && gPlayOrder==CHESS1) || ( press==PLAY2DO && gPlayOrder==CHESS2) ) return KEYFALLCHESS;/*是落子键*/ else if ( press==PLAY1UP || press==PLAY1DOWN || press==PLAY1LEFT || press==PLAY1RIGHT || press==PLAY2UP || press==PLAY2DOWN || press==PLAY2LEFT || press==PLAY2RIGHT ) return KEYMOVECURSOR;/*是光标移动键*/ else return KEYINVALID;/*按键无效*/ }