共有回帖数  0  个 
	 
	
	
	
     
          
          
               
				
			 
				
					 
 
            
				   - 
						
						
							 
									/* 把此文件保存为mazeMain.c 
 * 描述   : 超级迷宫 (Super Maze) 
 * 作者   : 文曦畅 Wen Xichang   2004-11-10 
 */ 
#define UP 0x4800 
#define DOWN 0x5000 
#define LEFT 0x4b00 
#define RIGHT 0x4d00 
#define KEY_W 0x1157 
#define KEY_w 0x1177 
#define KEY_S 0x1f53 
#define KEY_s 0x1f73 
#define KEY_A 0x1e41 
#define KEY_a 0x1e61 
#define KEY_D 0x2044 
#define KEY_d 0x2064 
#define ENTER 0x1c0d 
#define SPACE 0x3920 
#define F1 0x3b00 
#define ESC 0x11b 
#include stdio.h 
#include graphics.h 
#include stdlib.h 
#include bios.h 
#include "crtMaze.c" 
#include "menu.c" 
#include "logo.c" 
#include "music.c" 
int playerNum = 1; 
int gameLevel = 0; 
char reachIdx[75][97]; 
void	initMaze	(int flag); 
void	initGrphErrExit	(void); 
void	playGame	(void); 
void	updateThe	(Index idx); 
void	updateRect	(Index idx, int len); 
void	mazeUpdateEx	(Index p1, Index p2); 
void initMaze(int flag){ 
int i,j; 
for(i = 0; i  maxIdxY; i++){ 
for(j = 0; j  maxIdxX; j++){ 
maze[j] = 0; 
if(gameLevel == 0) reachIdx[j] = 1; 
else reachIdx[j] = 0; 
if((i == 0) || (j == 0) || (i == maxIdxY - 1) || (j == maxIdxX - 1)){ 
maze[j] = 1; 
} 
else if((i % 2 == 0) && (j % 2 == 0)){ 
maze[j] = 1; 
} 
} 
} 
if (flag == 0) 
randomize(); 
} 
void initGrphErrExit (void){ 
int gd = VGA, gm = VGAHI, errorcode; 
/*registerbgidriver(EGAVGA_driver);*/ 
initgraph(&gd, &gm, ""); 
errorcode = graphresult(); 
if (errorcode != grOk) 
{ 
printf("nGraphics error: %sn", grapherrormsg(errorcode)); 
printf("nI am sorry that an error occurred.nn"); 
printf("ttPress any key to exit..."); 
getch(); 
exit(0); 
} 
}
void playGame(void){ 
Index bgIdx = {1, 1}; 
Index edIdx; 
Index player1 = bgIdx,  
 player2; 
Index tmp; 
int key = 0; 
int i,j; 
int musIdx = 0; 
initMusic(); 
playerNum = inMenu(MENU_MAIN); 
edIdx.x = maxIdxX - 2; 
edIdx.y = maxIdxY - 2; 
player2 = edIdx; 
initMaze(1); 
createMaze(bgIdx, edIdx); 
maze[player1.y][player1.x] = 6; 
if (playerNum  1) 
maze[player2.y][player2.x] = 7; 
logo(2); 
mazeUpdateEx(player1,player2); 
for(;;){ 
if (bioskey(1)) 
key=bioskey(0); 
else 
key=0; 
switch(key){ 
case UP: 
if(maze[player1.y - 1][player1.x] != 1){ 
maze[player1.y][player1.x] = 2; 
updateThe(player1); 
player1.y--; 
maze[player1.y][player1.x] = 6; 
updateThe(player1); 
} 
if (gameLevel != 0) mazeUpdateEx(player1,player2); 
break; 
case DOWN: 
if(maze[player1.y + 1][player1.x] != 1){ 
maze[player1.y][player1.x] = 2; 
updateThe(player1); 
player1.y++; 
maze[player1.y][player1.x] = 6; 
updateThe(player1); 
} 
if (gameLevel != 0) mazeUpdateEx(player1,player2); 
break; 
case LEFT: 
if(maze[player1.y][player1.x - 1] != 1){ 
maze[player1.y][player1.x] = 2; 
updateThe(player1); 
player1.x--; 
maze[player1.y][player1.x] = 6; 
updateThe(player1); 
} 
if (gameLevel != 0) mazeUpdateEx(player1,player2); 
break; 
case RIGHT: 
if(maze[player1.y][player1.x + 1] != 1){ 
maze[player1.y][player1.x] = 2; 
updateThe(player1); 
player1.x++; 
maze[player1.y][player1.x] = 6; 
updateThe(player1); 
} 
if (gameLevel != 0) mazeUpdateEx(player1,player2); 
break; 
case KEY_W: 
case KEY_w: 
if(playerNum  1){ 
if(maze[player2.y - 1][player2.x] != 1){ 
maze[player2.y][player2.x] = 2; 
updateThe(player2); 
player2.y--; 
maze[player2.y][player2.x] = 7; 
updateThe(player2); 
} 
} 
if (gameLevel != 0) mazeUpdateEx(player1,player2); 
break; 
case KEY_S: 
case KEY_s: 
if(playerNum  1){ 
if(maze[player2.y + 1][player2.x] != 1){ 
maze[player2.y][player2.x] = 2; 
updateThe(player2); 
player2.y++; 
maze[player2.y][player2.x] = 7; 
updateThe(player2); 
} 
} 
if (gameLevel != 0) mazeUpdateEx(player1,player2); 
break; 
case KEY_A: 
case KEY_a: 
if(playerNum  1){ 
if(maze[player2.y][player2.x - 1] != 1){ 
maze[player2.y][player2.x] = 2; 
updateThe(player2); 
player2.x--; 
maze[player2.y][player2.x] = 7; 
updateThe(player2); 
} 
} 
if (gameLevel != 0) mazeUpdateEx(player1,player2); 
break; 
case KEY_D: 
case KEY_d: 
if(playerNum  1){ 
if(maze[player2.y][player2.x + 1] != 1){ 
maze[player2.y][player2.x] = 2; 
updateThe(player2); 
player2.x++; 
maze[player2.y][player2.x] = 7; 
updateThe(player2); 
} 
} 
if (gameLevel != 0) mazeUpdateEx(player1,player2); 
break; 
case ENTER: 
inMenu(MENU_PAUSE); 
logo(2); 
setcolor(WHITE); 
if (gameLevel != 3){ 
for(i = 0; i  maxIdxY; i++){ 
for(j = 0; j  maxIdxX; j++){ 
if(reachIdx[j] == 1){ 
tmp.x = j; 
tmp.y = i; 
updateThe(tmp); 
} 
} 
} 
} 
else 
mazeUpdateEx(player1,player2); 
break; 
case ESC: 
switch(inMenu(MENU_GAMING)){ 
case 1: 
case 0: 
logo(2); 
setcolor(WHITE); 
if (gameLevel != 3){ 
for(i = 0; i  maxIdxY; i++){ 
for(j = 0; j  maxIdxX; j++){ 
if(reachIdx[j] == 1){ 
tmp.x = j; 
tmp.y = i; 
updateThe(tmp); 
} 
} 
} 
} 
else 
mazeUpdateEx(player1,player2); 
break; 
case 2:	
initMaze(1); 
edIdx.x = maxIdxX - 2; 
edIdx.y = maxIdxY - 2; 
player1 = bgIdx; 
player2 = edIdx; 
createMaze(bgIdx, edIdx); 
maze[player1.y][player1.x] = 6; 
if (playerNum  1) 
maze[player2.y][player2.x] = 7; 
logo(2); 
setfillstyle(SOLID_FILL,0); 
bar(50,50,MWIDTH+60,MHEIGHT+40); 
mazeUpdateEx(player1,player2); 
break; 
case 3:	
playerNum = inMenu(MENU_MAIN); 
initMaze(1); 
edIdx.x = maxIdxX - 2; 
edIdx.y = maxIdxY - 2; 
player1 = bgIdx; 
player2 = edIdx; 
createMaze(bgIdx, edIdx); 
maze[player1.y][player1.x] = 6; 
if (playerNum  1) 
maze[player2.y][player2.x] = 7; 
logo(2); 
mazeUpdateEx(player1,player2); 
break; 
case 4:	
closegraph(); 
exit(1); 
} 
} 
if ((player1.x == edIdx.x && player1.y == edIdx.y) || (player2.x == bgIdx.x && player2.y == bgIdx.y)){ 
inMenu(MENU_SUCCESS); 
initMaze(1); 
edIdx.x = maxIdxX - 2; 
edIdx.y = maxIdxY - 2; 
player1 = bgIdx; 
player2 = edIdx; 
createMaze(bgIdx, edIdx); 
maze[player1.y][player1.x] = 6; 
if (playerNum  1) 
maze[player2.y][player2.x] = 7; 
logo(2); 
setfillstyle(SOLID_FILL,0); 
bar(50,50,MWIDTH+60,MHEIGHT+40); 
mazeUpdateEx(player1,player2); 
musIdx = (musIdx = 3 ? 0 : (musIdx + 1));	
} 
playMusic(musIdx, 1); 
} 
}
void updateThe(Index idx){ 
int width; 
int height; 
width = MWIDTH / maxIdxX; 
height = MHEIGHT / maxIdxY; 
if(showMode == 0) { 
if(maze[idx.y][idx.x] == 1){ 
if(idx.y  0) 
if(maze[idx.y - 1][idx.x] == 1) 
line((50+width*idx.x), (60+height*idx.y), (50+width*idx.x), (60+height*idx.y) - (height / 2));	
if(idx.y  maxIdxY - 1) 
if(maze[idx.y + 1][idx.x] == 1) 
line((50+width*idx.x), (60+height*idx.y), (50+width*idx.x), (60+height*idx.y) + (height / 2)); 
if(idx.x  0) 
if(maze[idx.y][idx.x - 1] == 1) 
line((50+width*idx.x), (60+height*idx.y), (50+width*idx.x) - (width / 2), (60+height*idx.y)); 
if(idx.x  maxIdxX - 1) 
if(maze[idx.y][idx.x + 1] == 1) 
line((50+width*idx.x), (60+height*idx.y), (50+width*idx.x) + (width / 2), (60+height*idx.y)); 
} 
else if (maze[idx.y][idx.x] == 6 || maze[idx.y][idx.x] == 7){ 
setfillstyle(SOLID_FILL,maze[idx.y][idx.x]); 
bar((50+width*idx.x) - (width / 2), (60+height*idx.y) - (height / 2), (50+width*idx.x) + (width / 2), (60+height*idx.y) + (height / 2)); 
} 
else { 
setfillstyle(SOLID_FILL,0);  
  bar((50+width*idx.x) - (width / 2), (60+height*idx.y) - (height / 2), (50+width*idx.x) + (width / 2), (60+height*idx.y) + (height / 2)); 
 	} 
} 
else{ 
if(maze[idx.y][idx.x] == 2){ 
setfillstyle(SOLID_FILL,15); 
bar((50+width*idx.x), (60+height*idx.y), (50+width*idx.x) + width, (60+height*idx.y) + height); 
} 
else{ 
setfillstyle(SOLID_FILL,maze[idx.y][idx.x]); 
bar((50+width*idx.x), (60+height*idx.y), (50+width*idx.x) + width, (60+height*idx.y) + height); 
} 
} 
} 
void updateRect(Index idx, int len){ 
Index bg,ed,tmp; 
int i,j; 
bg.x = (idx.x - len  0 ? 0 : idx.x - len); 
bg.y = (idx.y - len  0 ? 0 : idx.y - len); 
ed.x = (idx.x + len  maxIdxX - 1 ? maxIdxX - 1 : idx.x + len); 
ed.y = (idx.y + len  maxIdxY - 1 ? maxIdxY - 1 : idx.y + len); 
for(i = bg.y; i = ed.y; i++){ 
for(j = bg.x; j = ed.x; j++){ 
if(reachIdx[j] != 1){ 
tmp.x = j; 
tmp.y = i; 
updateThe(tmp); 
if(gameLevel != 3) 
reachIdx[j] = 1; 
} 
} 
} 
updateThe(idx); 
} 
void mazeUpdateEx(Index p1, Index p2){ 
static Index PP1 = {0, 0},PP2 = {0, 0}; 
int width; 
int height; 
setcolor(WHITE); 
switch(gameLevel){ 
case 0: 
mazeUpdate(); 
break; 
case 1:	
updateRect(p1, 8); 
updateRect(p2, 8); 
break; 
case 2: 
updateRect(p1, 4); 
updateRect(p2, 4); 
break; 
case 3:	
width = MWIDTH / maxIdxX; 
height = MHEIGHT / maxIdxY; 
setfillstyle(SOLID_FILL, BLACK); 
if (PP1.x  p1.x) bar((50+width*p1.x) + 4 * width, (60+height*p1.y) - 4 * height, (50+width*p1.x) + 5 * width, (60+height*p1.y) + 4 * height); 
else if (PP1.x  p1.x) bar((50+width*p1.x) - 5 * width, (60+height*p1.y) - 4 * height, (50+width*p1.x) - 2 * width, (60+height*p1.y) + 4 * height); 
if (PP1.y  p1.y) bar((50+width*p1.x) - 4 * width, (60+height*p1.y) + 2 * height, (50+width*p1.x) + 4 * width, (60+height*p1.y) + 5 * height); 
else if (PP1.y  p1.y) bar((50+width*p1.x) - 4 * width, (60+height*p1.y) - 5 * height, (50+width*p1.x) + 4 * width, (60+height*p1.y) - 2 * height); 
if (PP2.x  p2.x) bar((50+width*p2.x) + 4 * width, (60+height*p2.y) - 4 * height, (50+width*p2.x) + 5 * width, (60+height*p2.y) + 4 * height); 
else if (PP2.x  p2.x) bar((50+width*p2.x) - 5 * width, (60+height*p2.y) - 4 * height, (50+width*p2.x) - 2 * width, (60+height*p2.y) + 4 * height); 
if (PP2.y  p2.y) bar((50+width*p2.x) - 4 * width, (60+height*p2.y) + 2 * height, (50+width*p2.x) + 4 * width, (60+height*p2.y) + 5 * height); 
else if (PP2.y  p2.y) bar((50+width*p2.x) - 4 * width, (60+height*p2.y) - 5 * height, (50+width*p2.x) + 4 * width, (60+height*p2.y) - 2 * height); 
PP1 = p1; 
PP2 = p2; 
setcolor(WHITE); 
updateRect(p1, 3); 
updateRect(p2, 3); 
break; 
} 
} 
int main(){ 
int i,j; 
initGrphErrExit(); 
initMaze(0); 
playGame(); 
getch(); 
} 
/*mazeMain 结束*/
/*把此文件保存为crtMaze.c*/ #define MWIDTH 480 #define MHEIGHT 350 #define BEND_LEVEL 35 
#include stdio.h #include graphics.h #include stdlib.h 
typedef struct { int x; int y; }Index; 
typedef unsigned char Status; 
Status maze[75][97]; int showMode = 0; int maxIdxX = 61; int maxIdxY = 47; 
voidcreateMaze(Index bgIdx, Index edIdx); voidmazeUpdate(void); intcanReach(Index idx1, Index idx2); intstackFind2(Index idx1, Index idx2); intdirRand(int dirIn); intcreateMainPath(Index idx1, Index idx2, int num, int flag);intrandTrue(int pst); intcreatePath(Index idx1, int len, int num, int flag);intgetOutCount(void); void beautifyMaze(Index start); voidwaterFlood(Index start); void crPhLT(void); void crPhRB(void); void createMaze(Index bgIdx, Index edIdx){ int k,l; createMainPath(bgIdx, edIdx, 1000, 1); while(getOutCount() != 0){ crPhLT(); crPhRB(); } beautifyMaze(bgIdx); } void crPhLT(void){ Index tmp; int i,j; for(i = 1; i  maxIdxY - 1; i++){ for(j = 1; j  maxIdxX - 1; j++){ if (maze[j] == 12){ tmp.y = i; tmp.x = j; if(createPath(tmp, 50, 100, 1)) return; } } } } 
void crPhRB(void){ Index tmp; int i,j; for(i = maxIdxY - 2; i  0; i--){ for(j = maxIdxX - 2; j  0; j--){ if (maze[j] == 12){ tmp.y = i; tmp.x = j; if(createPath(tmp, 50, 100, 1)) return; } } } } 
void mazeUpdate(void){ int i,j; int width; int height; 
width = MWIDTH / maxIdxX; height = MHEIGHT / maxIdxY; 
if (showMode == 0) { setfillstyle(SOLID_FILL,0); bar(50,50,MWIDTH+60,MHEIGHT+40); setcolor(WHITE); } 
for(i = 0; i  maxIdxY; i++){ for(j = 0; j  maxIdxX; j++){ if(showMode == 0) { if(maze[j] == 1){ 
if(i  0) if(maze[i - 1][j] == 1) line((50 + width * j), (60 + height * i), (50 + width * j), (60 + height * i) - (height / 2));if(i  maxIdxY - 1) if(maze[i + 1][j] == 1) line((50 + width * j), (60 + height * i), (50 + width * j), (60 + height * i) + (height / 2)); if(j  0) if(maze[j - 1] == 1) line((50 + width * j), (60 + height * i), (50 + width * j) - (width / 2), (60 + height * i)); if(j  maxIdxX - 1) if(maze[j + 1] == 1) line((50 + width * j), (60 + height * i), (50 + width * j) + (width / 2), (60 + height * i)); } else if (maze[j] == 6 || maze[j] == 7){ setfillstyle(SOLID_FILL,maze[j]); bar((50 + width * j) - (width / 2), (60 + height * i) - (height / 2), (50 + width * j) + (width / 2), (60 + height * i) + (height / 2)); } else { setfillstyle(SOLID_FILL,0);    bar((50 + width * j) - (width / 2), (60 + height * i) - (height / 2), (50 + width * j) + (width / 2), (60 + height * i) + (height / 2));  } } else{ if(maze[j] == 2){ setfillstyle(SOLID_FILL,15); bar((50 + width * j), (60 + height * i), (50 + width * j) + width, (60 + height * i) + height); } else{ 
setfillstyle(SOLID_FILL,maze[j]); 
bar((50 + width * j), (60 + height * i), (50 + width * j) + width, (60 + height * i) + height); 
} 
} 
} 
} 
} 
int canReach(Index idx1, Index idx2){ 
int ret; 
int tmpST[75][97]; 
int i,j; 
if ((maze[idx1.y][idx1.x] == 1) || (maze[idx2.y][idx2.x] == 1)) return 0; 
for(i = 0; i  maxIdxY; i++) 
for(j = 0; j  maxIdxX; j++) 
tmpST[j] = maze[j]; 
ret = stackFind2(idx1, idx2); 
for(i = 0; i  maxIdxY; i++) 
for(j = 0; j  maxIdxX; j++) 
maze[j] = tmpST[j]; 
return ret; 
} 
int stackFind2(Index idx1, Index idx2){ 
register int i, j, count = 0; 
maze[idx1.y][idx1.x] = 11; 
for(;;){ 
count = 0; 
for(i = 1; i  maxIdxY - 1; i++){ 
for(j = 1; j  maxIdxX - 1; j++){ 
if(maze[j] == 11){ 
if(maze[i + 1][j] == 0){ 
maze[i + 1][j] = 11; 
count++; 
} 
if(maze[j + 1] == 0){ 
maze[j + 1] = 11; 
count++; 
} 
if(maze[i - 1][j] == 0){ 
maze[i - 1][j] = 11; 
count++; 
} 
if(maze[j - 1] == 0){ 
maze[j - 1] = 11; 
count++; 
} 
} 
if(maze[idx2.y][idx2.x] == 11) return 1; 
} 
} 
if(count == 0) 
return ((maze[idx2.y][idx2.x] == 11) ? 1 : 0); 
} 
} 
int dirRand(int dirIn){ 
int dir[4] = {0, 0, 0, 0}; 
int ind = 0; 
int ret; 
int tmp; 
static int lstDir; 
if((dirIn == 0) || (dirIn == 1) || (dirIn == 2) || (dirIn == 4) || (dirIn == 8)) 
return dirIn;	
else{	
if(dirIn = 8){ 
dirIn -= 8; 
dir[ind] = 8; 
ind++; 
} 
if(dirIn = 4){ 
dirIn -= 4; 
dir[ind] = 4; 
ind++; 
} 
if(dirIn = 2){ 
dirIn -= 2; 
dir[ind] = 2; 
ind++; 
} 
if(dirIn){ 
dir[ind] = 1; 
ind++; 
} 
tmp = random(100); 
if (tmp  BEND_LEVEL) 
if ((dir[0] == lstDir || dir[1] == lstDir || dir[2] == lstDir || dir[3] == lstDir) && (lstDir != 0)) 
return lstDir; 
else 
ret = (random(100)) % ind; 
else 
ret = (random(100)) % ind; 
lstDir = dir[ret]; 
return lstDir; 
} 
} 
int createMainPath (Index idx1, Index idx2, int num, int flag){ 
Index crIdx = idx1; 
Index tmp; 
int dirCh = 0; 
int tmpDir = 0;	
int qDir = 0; 
int outCnt = 0; 
if(!canReach(idx1, idx2)) return 0; 
while(crIdx.x != idx2.x || crIdx.y != idx2.y){ 
maze[crIdx.y][crIdx.x] = 2; 
dirCh = 0;tmpDir = 0;qDir = 0; 
tmp.y = crIdx.y - 1; 
tmp.x = crIdx.x; 
if (maze[tmp.y][tmp.x] == 0) 
if (canReach(tmp, idx2)) 
dirCh += 8; 
else maze[tmp.y][tmp.x] = 1; 
tmp.y = crIdx.y + 1; 
tmp.x = crIdx.x; 
if (maze[tmp.y][tmp.x] == 0)  
if (canReach(tmp, idx2)) 
dirCh += 2; 
else maze[tmp.y][tmp.x] = 1; 
tmp.y = crIdx.y; 
tmp.x = crIdx.x + 1; 
if (maze[tmp.y][tmp.x] == 0) 
if (canReach(tmp, idx2)) 
dirCh += 1; 
else maze[tmp.y][tmp.x] = 1; 
tmp.y = crIdx.y; 
tmp.x = crIdx.x - 1; 
if (maze[tmp.y][tmp.x] == 0) 
if (canReach(tmp, idx2)) 
dirCh += 4; 
else maze[tmp.y][tmp.x] = 1; 
tmpDir = dirRand(dirCh); 
qDir = dirCh - tmpDir; 
if (qDir = 8){ 
qDir -= 8; 
if(flag == 1 && outCnt  num){ 
if(randTrue(15)){ 
maze[crIdx.y - 1][crIdx.x] = 12; 
outCnt++; 
} 
else 
maze[crIdx.y - 1][crIdx.x] = 1; 
} 
else 
maze[crIdx.y - 1][crIdx.x] = 1; 
} 
if (qDir = 4){ 
qDir -= 4; 
if(flag == 1 && outCnt  num){ 
if(randTrue(15)){ 
maze[crIdx.y][crIdx.x - 1] = 12; 
outCnt++; 
} 
else 
maze[crIdx.y][crIdx.x - 1] = 1; 
} 
else 
maze[crIdx.y][crIdx.x - 1] = 1; 
} 
if (qDir = 2){ 
qDir -= 2; 
if(flag == 1 && outCnt  num){ 
if(randTrue(15)){ 
maze[crIdx.y + 1][crIdx.x] = 12; 
outCnt++; 
} 
else 
maze[crIdx.y + 1][crIdx.x] = 1; 
} 
else 
maze[crIdx.y + 1][crIdx.x] = 1; 
} 
if (qDir == 1){ 
if(flag == 1 && outCnt  num){ 
if(randTrue(15)){ 
maze[crIdx.y][crIdx.x + 1] = 12; 
outCnt++; 
} 
else 
maze[crIdx.y][crIdx.x + 1] = 1; 
} 
else 
maze[crIdx.y][crIdx.x + 1] = 1; 
} 
switch(tmpDir){	
case 8: 
crIdx.y--; 
break; 
case 2: 
crIdx.y++; 
break; 
case 1: 
crIdx.x++; 
break; 
case 4: 
crIdx.x--; 
break; 
default: 
printf("Maybe there're some BUG in Creating Path!n"); 
mazeUpdate(); 
getch(); 
exit(0); 
} 
} 
maze[idx2.y][idx2.x] = 2; 
if(maze[idx2.y + 1][idx2.x] == 0) maze[idx2.y + 1][idx2.x] = 1; 
if(maze[idx2.y][idx2.x + 1] == 0) maze[idx2.y][idx2.x + 1] = 1; 
if(maze[idx2.y][idx2.x - 1] == 0) maze[idx2.y][idx2.x - 1] = 1; 
if(maze[idx2.y - 1][idx2.x] == 0) maze[idx2.y - 1][idx2.x] = 1; 
if(maze[idx2.y + 1][idx2.x + 1] == 0) maze[idx2.y + 1][idx2.x + 1] = 1; 
if(maze[idx2.y - 1][idx2.x + 1] == 0) maze[idx2.y - 1][idx2.x + 1] = 1; 
if(maze[idx2.y + 1][idx2.x - 1] == 0) maze[idx2.y + 1][idx2.x - 1] = 1; 
if(maze[idx2.y - 1][idx2.x - 1] == 0) maze[idx2.y - 1][idx2.x - 1] = 1; 
return 1; 
} 
int randTrue (int pst){ 
if (pst  100) pst = 100; 
if (pst  0) pst = 0; 
if (random(100)  pst) return 1; 
else return 0; 
} 
int createPath (Index idx1, int len, int num, int flag){ 
Index crIdx = idx1; 
Index tmp; 
int dirCh = 0; 
int tmpDir = 0;	
int qDir = 0; 
int outCnt = 0;	
int lngth = 0; 
if ((maze[crIdx.y + 1][crIdx.x] != 0) &&  
 (maze[crIdx.y - 1][crIdx.x] != 0) &&  
 (maze[crIdx.y][crIdx.x + 1] != 0) &&  
 (maze[crIdx.y][crIdx.x - 1] != 0)){ 
maze[crIdx.y][crIdx.x] = 1; 
 	return 0; 
} 
while(1){ 
maze[crIdx.y][crIdx.x] = 2; 
lngth++; 
if (lngth = len) break; 
dirCh = 0;tmpDir = 0;qDir = 0; 
tmp.y = crIdx.y - 1; 
tmp.x = crIdx.x; 
if (maze[tmp.y][tmp.x] == 0) 
dirCh += 8; 
tmp.y = crIdx.y + 1; 
tmp.x = crIdx.x; 
if (maze[tmp.y][tmp.x] == 0) 
dirCh += 2; 
tmp.y = crIdx.y; 
tmp.x = crIdx.x + 1; 
if (maze[tmp.y][tmp.x] == 0) 
dirCh += 1; 
tmp.y = crIdx.y; 
tmp.x = crIdx.x - 1; 
if (maze[tmp.y][tmp.x] == 0) 
dirCh += 4; 
if (dirCh == 0) break; 
tmpDir = dirRand(dirCh); 
qDir = dirCh - tmpDir;	
if (qDir = 8){ 
qDir -= 8; 
if(flag == 1 && outCnt  num){ 
if(randTrue(30)){ 
maze[crIdx.y - 1][crIdx.x] = 12; 
outCnt++; 
} 
else 
maze[crIdx.y - 1][crIdx.x] = 1; 
} 
else 
maze[crIdx.y - 1][crIdx.x] = 1; 
} 
if (qDir = 4){ 
qDir -= 4; 
if(flag == 1 && outCnt  num){ 
if(randTrue(30)){ 
maze[crIdx.y][crIdx.x - 1] = 12; 
outCnt++; 
} 
else 
maze[crIdx.y][crIdx.x - 1] = 1; 
} 
else 
maze[crIdx.y][crIdx.x - 1] = 1; 
} 
if (qDir = 2){ 
qDir -= 2; 
if(flag == 1 && outCnt  num){ 
if(randTrue(30)){ 
maze[crIdx.y + 1][crIdx.x] = 12; 
outCnt++; 
} 
else 
maze[crIdx.y + 1][crIdx.x] = 1; 
} 
else 
maze[crIdx.y + 1][crIdx.x] = 1; 
} 
if (qDir == 1){ 
if(flag == 1 && outCnt  num){ 
if(randTrue(30)){ 
maze[crIdx.y][crIdx.x + 1] = 12; 
outCnt++; 
} 
else 
maze[crIdx.y][crIdx.x + 1] = 1; 
} 
else 
maze[crIdx.y][crIdx.x + 1] = 1; 
} 
switch(tmpDir){	
case 8: 
crIdx.y--; 
break; 
case 2: 
crIdx.y++; 
break; 
case 1: 
crIdx.x++; 
break; 
case 4: 
crIdx.x--; 
break; 
default: 
printf("Maybe there're some BUG in Creating Path!n"); 
mazeUpdate(); 
getch(); 
exit(0); 
} 
} 
if(maze[crIdx.y + 1][crIdx.x] == 0) maze[crIdx.y + 1][crIdx.x] = 1; 
if(maze[crIdx.y][crIdx.x + 1] == 0) maze[crIdx.y][crIdx.x + 1] = 1; 
if(maze[crIdx.y][crIdx.x - 1] == 0) maze[crIdx.y][crIdx.x - 1] = 1; 
if(maze[crIdx.y - 1][crIdx.x] == 0) maze[crIdx.y - 1][crIdx.x] = 1; 
if(maze[crIdx.y + 1][crIdx.x + 1] == 0) maze[crIdx.y + 1][crIdx.x + 1] = 1; 
if(maze[crIdx.y - 1][crIdx.x + 1] == 0) maze[crIdx.y - 1][crIdx.x + 1] = 1; 
if(maze[crIdx.y + 1][crIdx.x - 1] == 0) maze[crIdx.y + 1][crIdx.x - 1] = 1; 
if(maze[crIdx.y - 1][crIdx.x - 1] == 0) maze[crIdx.y - 1][crIdx.x - 1] = 1; 
return 1; 
} 
int getOutCount(void){ 
int c = 0; 
int i,j; 
for(i = 1; i  maxIdxY - 1; i++) 
for(j = 1; j  maxIdxX - 1; j++) 
if (maze[j] == 12) c++; 
return c; 
} 
void beautifyMaze (Index start){ 
int i, j; 
Index tmp; 
for(i = 1; i  maxIdxY - 1; i++){ 
for(j = 1; j  maxIdxX - 1; j++){ 
if (maze[j] == 0){ 
maze[j] = 12; 
tmp.y = i; 
tmp.x = j; 
createPath(tmp, 100, 0, 0); 
} 
} 
} 
for(i = 1; i  maxIdxY - 1; i++){ 
for(j = 1; j  maxIdxX - 1; j++){ 
if ((maze[i + 1][j] == 1) &&  
 	 (maze[i - 1][j] == 1) &&  
 	 (maze[j + 1] == 1) &&  
 	 (maze[j - 1] == 1) &&  
 	 (maze[i + 1][j - 1] == 1) &&  
 	 (maze[i - 1][j + 1] == 1) &&  
 	 (maze[i + 1][j + 1] == 1) &&  
 	 (maze[i - 1][j - 1] == 1)){ 
maze[j] = 2; 
if(j  maxIdxX/2) maze[j - 1] = 2; 
else maze[j + 1] = 2; 
} 
} 
} 
waterFlood(start); 
for(i = 1; i  maxIdxY - 1; i++){	
for(j = 1; j  maxIdxX - 1; j++){ 
if (maze[j] == 2){ 
if (i == 1 && j == 1) continue; 
else if (i == 1){ 
maze[j - 1] = 2; 
waterFlood(start); 
} 
else { 
maze[i - 1][j] = 2; 
waterFlood(start); 
} 
} 
} 
} 
for(i = 1; i  maxIdxY - 1; i++){ 
for(j = 1; j  maxIdxX - 1; j++){ 
if (maze[j] == 5) maze[j] = 2; 
} 
} 
} 
void waterFlood (Index start){ 
register int i, j, count = 0; 
maze[start.y][start.x] = 5; 
for(;;){ 
count = 0; 
for(i = 1; i  maxIdxY - 1; i++){ 
for(j = 1; j  maxIdxX - 1; j++){ 
if(maze[j] == 5 ){ 
if(maze[i + 1][j] == 2){ 
maze[i + 1][j] = 5; 
count++; 
} 
if(maze[j + 1] == 2){ 
maze[j + 1] = 5; 
count++; 
} 
if(maze[i - 1][j] == 2){ 
maze[i - 1][j] = 5; 
count++; 
} 
if(maze[j - 1] == 2){ 
maze[j - 1] = 5; 
count++; 
} 
} 
} 
} 
if(count == 0) 
return; 
} 
} 
/*crtMaze.c 结束*/
struct Note soundNotes[4][4] = {{{C,P1},{E,P1},{G,P1},{C1,P1}}, 
{{C1,P4_1},{G,P4_1},{C1,P4_1},{G,P4_1}}, 
{{C0,P4_1}}, 
{{E0,P4_1},{G0,P4_1}} 
 }; 
struct { 
int interval; 
int lastTime; 
} musicTimer; 
int musicOn = 1; 
int songLen[4] = {106,75,76,64}; 
int soundLen[4] = {3,3,0,1}; 
int 	getMemTime	(void); 
void 	initMusic	(void); 
void	playMusic	(int musIdx, int loop); 
void 	playSound	(int musIdx, int key); 
int getMemTime(){ 
int ret; 
ret = peek(0x0,0x46e); 
ret = 8; 
ret += peek(0x0,0x46c); 
return (ret); 
} 
void initMusic(void){ 
musicTimer.lastTime = getMemTime(); 
musicTimer.interval = 0; 
} 
void playMusic(int musIdx, int loop){ 
static tmpIdx = 0; 
static tmploop = 0; 
static current = 0; 
int vTime; 
if(musIdx != tmpIdx || loop != tmploop){ 
current = 0; 
tmpIdx = musIdx; 
tmploop = loop; 
} 
if(musicOn){ 
vTime=getMemTime() - musicTimer.lastTime; 
if(vTime = musicTimer.interval){ 
if(current  songLen[musIdx] - 1){ 
if (loop != 0){ 
current = 0; 
sound(musicNotes[musIdx][current].s); 
musicTimer.interval = musicNotes[musIdx][current].len; 
musicTimer.lastTime = getMemTime(); 
current++; 
} 
else 
nosound(); 
return; 
} 
else{ 
sound(musicNotes[musIdx][current].s); 
musicTimer.interval = musicNotes[musIdx][current].len; 
musicTimer.lastTime = getMemTime(); 
current++; 
} 
} 
} 
} 
void playSound(int musIdx, int key){ 
static tmpIdx = 0; 
static tmpKey = 0; 
static current = 0; 
int vTime; 
if(musIdx != tmpIdx || key != tmpKey){ 
current = 0; 
tmpIdx = musIdx; 
tmpKey = key; 
} 
if(musicOn){ 
vTime=getMemTime() - musicTimer.lastTime; 
if(vTime = musicTimer.interval){ 
if(current  soundLen[musIdx]){ 
nosound(); 
return; 
} 
else{ 
sound(soundNotes[musIdx][current].s); 
musicTimer.interval = soundNotes[musIdx][current].len; 
musicTimer.lastTime = getMemTime(); 
current++; 
} 
} 
} 
} 
/*music.c 结束*/
/*把此文件保存为logo.c*/ 
void	logo	(int lgIndex); 
void	logo	(int lgIndex){ 
switch(lgIndex){ 
case 0:	
settextstyle(0, 0, 5); 
setcolor(RED); 
outtextxy(175, 41, "S"); 
setcolor(YELLOW); 
outtextxy(210, 41, "U"); 
setcolor(BLUE); 
outtextxy(250, 41, "P"); 
setcolor(CYAN); 
outtextxy(290, 41, "E"); 
setcolor(MAGENTA); 
outtextxy(330, 41, "R"); 
settextstyle(0, 0, 7); 
setcolor(LIGHTBLUE); 
outtextxy(310, 100, "M"); 
setcolor(RED); 
outtextxy(360, 100, "A"); 
setcolor(YELLOW); 
outtextxy(410, 100, "Z"); 
setcolor(BLUE); 
outtextxy(460, 100, "E"); 
setcolor(MAGENTA); 
rectangle(167,84,380,90); 
setcolor(GREEN); 
rectangle(288,159,524,165); 
setcolor(RED); 
rectangle(170,104,279,153); 
setcolor(YELLOW); 
rectangle(156,122,254,186); 
setcolor(BLUE); 
rectangle(226,129,264,198); 
setcolor(CYAN); 
rectangle(115,145,187,209); 
setcolor(MAGENTA); 
rectangle(376,48,422,71); 
setcolor(GREEN); 
rectangle(399,63,458,80); 
setcolor(LIGHTBLUE); 
rectangle(446,35,588,93); 
setcolor(MAGENTA); 
settextstyle(0, 0, 0); 
outtextxy(475, 46, "PROGRAMMER"); 
outtextxy(470, 68, "WEN XICHANG"); 
settextstyle(0, 0, 0); 
break;	
case 1: 
setcolor(WHITE); 
outtextxy(155, 103, "SUPER MAZE"); 
setcolor(LIGHTBLUE); 
outtextxy(155, 131, "VER 1.1"); 
setcolor(RED); 
outtextxy(155, 155, "PROGRAMMER"); 
outtextxy(155, 175, "WEN XICHANG"); 
outtextxy(155, 191, "GDUFS"); 
setcolor(LIGHTBLUE); 
outtextxy(385, 317, "2005.2.7"); 
setcolor(YELLOW); 
rectangle(444,138,468,164); 
setcolor(LIGHTBLUE); 
rectangle(411,150,453,182); 
setcolor(GREEN); 
rectangle(393,170,438,240); 
setcolor(MAGENTA); 
rectangle(380,198,428,264); 
setcolor(GREEN); 
rectangle(295,257,471,273); 
setcolor(BLUE); 
rectangle(155,285,361,316); 
setcolor(CYAN); 
rectangle(318,240,329,321); 
setcolor(YELLOW); 
outtextxy(160, 290, "QQ:375020128"); 
break;
case 2: 
setcolor(GREEN); 
rectangle(457,12,579,35); 
setcolor(WHITE); 
outtextxy(478, 19, "SUPER MAZE"); 
setcolor(LIGHTBLUE); 
rectangle(589,185,602,433); 
setcolor(RED); 
rectangle(573,360,596,424); 
setcolor(GREEN); 
rectangle(548,395,612,446); 
setcolor(BLUE); 
rectangle(438,429,569,456); 
setcolor(YELLOW); 
rectangle(349,434,498,446); 
setcolor(MAGENTA); 
rectangle(141,437,375,440); 
setcolor(WHITE); 
setfillstyle(SOLID_FILL, WHITE); 
bar(271,413,530,426); 
setcolor(BLACK); 
outtextxy(276, 416, "WENXICHANG@STUDENT.GDUFS.EDU.CN"); 
break; 
case 3: 
setcolor(GREEN); 
rectangle(249,215,305,237); 
setcolor(MAGENTA); 
rectangle(277,233,321,248); 
setcolor(YELLOW); 
rectangle(301,244,370,257); 
setcolor(BLUE); 
rectangle(367,215,381,266); 
setcolor(LIGHTBLUE); 
rectangle(239,253,319,278); 
setcolor(RED); 
outtextxy(247, 261, "OPTIONS"); 
break; 
case 4: 
setcolor(GREEN); 
rectangle(240,162,325,188); 
setcolor(LIGHTBLUE); 
rectangle(277,155,305,166); 
setcolor(CYAN); 
rectangle(313,177,357,207); 
setcolor(BLUE); 
rectangle(348,162,370,185); 
setcolor(YELLOW); 
rectangle(362,172,426,195); 
setcolor(YELLOW); 
outtextxy(250, 171, "MAZE..."); 
break; 
case 5: 
settextstyle(0, 0, 3); 
setcolor(YELLOW); 
outtextxy(255, 215, "PAUSE!"); 
settextstyle(0, 0, 0); 
break; 
case 6: 
settextstyle(0, 0, 2); 
setcolor(GREEN); 
rectangle(245,183,253,204); 
setcolor(MAGENTA); 
rectangle(251,179,269,191); 
setcolor(RED); 
rectangle(263,185,381,196); 
setcolor(LIGHTBLUE); 
rectangle(257,263,289,300); 
setcolor(YELLOW); 
rectangle(278,270,387,277); 
setcolor(CYAN); 
rectangle(378,266,395,286); 
setcolor(BLUE); 
rectangle(387,254,398,276); 
setcolor(YELLOW); 
outtextxy(245, 215, "WELL DONE!"); 
settextstyle(0, 0, 0); 
} 
} 
/*logo.c 结束*/
/*把此文件保存为menu.c*/ 
 #define MENU_MAIN 0 
 #define MENU_OPTIONS 1 
 #define MENU_ABOUT 2 
 #define MENU_SIZE_SELECT 3 
 #define MENU_GAMING 4 
 #define MENU_PAUSE 5 
 #define MENU_SUCCESS 6 
 #define MENU_LEVEL 7 
  
char *strMain[6] = {" ", "1 PLAYER", "2 PLAYERS", "OPTIONS...", "ABOUT", "QUIT"}; 
char *strOptions[6] = {" ", "SOUND: ", "MAZE SIZE...", "DRAW MODE: ", "GAME LEVEL...", "EXIT"}; 
char *strSize[5] = {" ", "HUGE", "LARGE", "NORMAL", "SMALL"}; 
char *strGaming[5] = {" ", "CONTINUE", "NEW GAME", "RETURN TO MAIN MENU...", "QUIT"}; 
char *strLevel[5] = {" ", "EASY", "NORMAL", "HARD", "UNBELIEVABLE"}; 
extern int musicOn; 
extern int playerNum; 
extern int gameLevel; 
int 	inMenu	(int mnIndex); 
void	updateMenu	(char *str[], int num, int crnt, int x, int y); 
void	outMenu	(int mnIndex);	/* x, y 起始位置, style 风格 */ 
void	dBorder	(int x1, int y1, int x2, int y2, int color); 
void	initMaze	(int flag); 
void	logo	(int lgIndex); 
void 	playSound	(int musIdx, int key); 
int inMenu(int mnIndex){ 
int current = 1; 
int key; 
int tmp; 
static int muDelta = 3; 
int sdIdx = 3; 
muDelta++; 
switch(mnIndex){ 
case MENU_MAIN: 
cleardevice();
updateMenu(strMain, 6, current, 290, 240); 
logo(0); 
dBorder(260, 220, 380 ,390, LIGHTBLUE); 
for(;;){ 
if (bioskey(1)) 
key=bioskey(0); 
else 
key=0; 
switch(key){ 
case UP: 
current = (current = 1 ? 1 : current - 1); 
updateMenu(strMain, 6, current, 290, 240); 
sdIdx = 2; 
muDelta++; 
break; 
case DOWN: 
current = (current = 5 ? 5 : current + 1); 
updateMenu(strMain, 6, current, 290, 240); 
sdIdx = 2; 
muDelta++; 
break; 
case ENTER: 
if (current = 2){ 
outMenu(MENU_MAIN); 
return current; 
} 
else if (current == 3) inMenu(MENU_OPTIONS); 
else if (current == 4) inMenu(MENU_ABOUT); 
else if (current == 5) { 
closegraph(); 
exit(1); 
} 
logo(0); 
updateMenu(strMain, 6, current, 290, 240); 
dBorder(260, 220, 380 ,390, LIGHTBLUE); 
break; 
} 
playSound(sdIdx, muDelta); 
} 
case MENU_OPTIONS: 
setfillstyle(SOLID_FILL,0); 
bar(220, 80, 420, 300); 
dBorder(220, 80, 420, 300,LIGHTBLUE); 
logo(3); 
updateMenu(strOptions, 6, current, 250, 100); 
bar(320,120,360,135); 
if (musicOn) outtextxy(320 ,120, "ON"); 
else outtextxy(320 ,120, "OFF"); 
bar(360, 160, 409, 200); 
if (showMode) outtextxy(360, 160, "PUZZLE"); 
else outtextxy(360, 160, "LINE"); 
for(;;){ 
if (bioskey(1)) 
key=bioskey(0); 
else 
key=0; 
switch(key){ 
case UP:  
current = (current = 1 ? 1 : current - 1); 
updateMenu(strOptions, 6, current, 250, 100); 
sdIdx = 2; 
muDelta++; 
break; 
case DOWN:  
current = (current = 5 ? 5 : current + 1); 
updateMenu(strOptions, 6, current, 250, 100); 
sdIdx = 2; 
muDelta++; 
break;
							 
							 
							 
							  
							  
							  楼主 2016-03-16 17:48 回复
						 
						 
           
          
          
         
   
         
      
 
   
             
                  
                  
 
 
 
     
	 
  
	Copyright © 2010~2015 直线网 版权所有,All Rights Reserved.沪ICP备10039589号
	
	意见反馈 | 
	关于直线 | 
	版权声明 | 
	会员须知