求助如何将一个c++源文件变成多文件结构
以下是一个推箱子小程序的源代码(没附加图片)
#include<graphics.h>
#include
#include<conio.h>
#include<stdio.h>
int map[3][7][8] =
{
1, 1, 1, 1, 1, 1, 1, 1,
1, 3, 4, 0, 0, 4, 3, 1,
1, 3, 4, 0, 0, 0, 0, 1,
1, 0, 1, 0, 1, 1, 0, 1,
1, 0, 0, 5, 0, 0, 0, 1,
1, 3, 4, 0, 0, 4, 3, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 3, 4, 0, 0, 4, 3, 1,
1, 0, 0, 0, 0, 4, 3, 1,
1, 0, 1, 0, 1, 1, 0, 1,
1, 3, 4, 5, 0, 0, 0, 1,
1, 3, 4, 0, 0, 4, 3, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 3, 4, 0, 0, 4, 3, 1,
1, 0, 3, 4, 0, 0, 0, 1,
1, 0, 1, 0, 1, 1, 0, 1,
1, 3, 4, 5, 0, 0, 0, 1,
1, 3, 4, 0, 0, 4, 3, 1,
1, 1, 1, 1, 1, 1, 1, 1
};
IMAGE img[6];
int imgIndex[6] = { 0,1,3,4,5,7 };
int z =0;
void loadResource()
{
for (int i=0;i<6;i++)
{
char filename[20] = “”;
sprintf(filename,"%d.jpg.jpg",imgIndex[i]);
loadimage(img+i,filename,64,64);
}
}
void drawmap()
{
int x,y;
for(int i=0;i<7;i++)
{
for(int j=0;j<8;j++)
{
x=64j;
y=64i;
switch(map[z][i][j])
{
case 0:
putimage(x,y,img +0);
break;
case 1:
putimage(x,y,img +1);
break;
case 3:
putimage(x,y,img +2);
break;
case 4:
putimage(x,y,img +3);
break;
case 5:
case 8:
putimage(x,y,img +4);
break;
case 7:
putimage(x,y,img +5);
break;
}
}
}
}
void keyDown()
{
int i,j;
for(i=0;i<7;i++)
{
for(j=0;j<8;j++)
{
if(map[z][i][j]==5||map[z][i][j]==8)
break;
}
if(map[z][i][j]==5||map[z][i][j]==8)
break;
}
char userKey = _getch();
switch(userKey)
{
case ‘w’:
case ‘W’:
case 72:
if(map[z][i-1][j]==0||map[z][i-1][j]==3)
{
map[z][i][j] -= 5;
map[z][i-1][j] +=5;
}
else if(map[z][i-1][j]==4||map[z][i-1][j]==7)
{
if(map[z][i-2][j]==0||map[z][i-2][j]==3)
{
map[z][i][j] -= 5;
map[z][i-1][j] +=1;
map[z][i-2][j] +=4;
}
}
break;
case ‘s’:
case ‘S’:
case 80:
if(map[z][i+1][j]==0||map[z][i+1][j]==3)
{
map[z][i][j] -= 5;
map[z][i+1][j] +=5;
}
else if(map[z][i+1][j]==4||map[z][i][j+1]==7)
{
if(map[z][i+2][j]==0||map[z][i][j+2]==3)
{
map[z][i][j] -= 5;
map[z][i+1][j] +=1;
map[z][i+2][j] +=4;
}
}
break;
case ‘a’:
case ‘A’:
case 75:
if(map[z][i][j-1]==0||map[z][i][j-1]==3)
{
map[z][i][j] -= 5;
map[z][i][j-1] +=5;
}
else if(map[z][i][j-1]==4||map[z][i][j-1]==7)
{
if(map[z][i][j-2]==0||map[z][i][j-2]==3)
{
map[z][i][j] -= 5;
map[z][i][j-1] +=1;
map[z][i][j-2] +=4;
}
}
break;
case ‘d’:
case ‘D’:
case 77:
if(map[z][i][j+1]==0||map[z][i][j+1]==3)
{
map[z][i][j] -= 5;
map[z][i][j+1] +=5;
}
else if(map[z][i][j+1]==4||map[z][i][j+1]==7)
{
if(map[z][i][j+2]==0||map[z][i][j+2]==3)
{
map[z][i][j] -= 5;
map[z][i][j+1] +=1;
map[z][i][j+2] +=4;
}
}
break;
}
}
int gameOver()
{
int count =1;
for(int i=0;i<7;i++)
{
for(int j=0;j<8;j++)
{
if(map[z][i][j] == 4)
{
count = 0;
return count;
}
}
}
return count;
}
void gameOverLayout()
{
IMAGE gameover;
loadimage(&gameover,“gameover.jpg”,648,649);
putimage(0,0,&gameover);
getchar();
closegraph();
}
int main()
{
initgraph(648,647);
loadResource();
while(1)
{
drawmap();
keyDown();
if(gameOver())
{
z++;
if(z==3)
break;
}
}
gameOverLayout();
closegraph();
return 0;
}