life 游戏问题
/* Simulation of Conway's game of Lif on a bounded gridPre: The user must supply an initial configuration of living cells.
Post: The program prints a sequence of maps showing the changes in the configuration of living cells according to the rules for the game of Life.
Uses: functions Initialize,WriteMap,NeighborCount,and UserSaysYes */
#include"common.h" /* common include files and definitions */
#include"life.h" /* Life's defines,typedefs,and prototypes */
void main(void)
{
int row,col;
Grid map; /*current generation */
Grid newmap; /*next generation */
Initialize(map)
WriteMap(map);
printf("This is the initial configuration you have chosen.\n"
"Press<Enter>to continue.\n");
while(getchar()!='\n')
;
do{
for(row=1;row<=MAXROW;row++)
for(col=1;col<=MAXCOL;col++)
switch(NeighborCount(map,row,col)){
case 0:
case 1:
newmap[row][col]=DEAD;
break;
case 2:
newmap[row][col]=map[row][col]
break;
case 3:
newmap[row][col]=ALIVE;
break;
case 4:
case 5:
case 6:
case 7:
case 8:
newmap[row][col]=DEAD;
break;
}
CopyMap(map,newmap);
WriteMap(map);
printf("Do you wish to continue viewing the new generations");
}while(UserSaysYes());
}
问一下前面两行
#include"common.h" /* common include files and definitions */
#include"life.h" /* Life's defines,typedefs,and prototypes */
这个文件从哪来,怎么用上去?
----------------解决方案--------------------------------------------------------
“引用头文件”这个说法楼主听说过吗?若果楼主知道引用头文件,还这样问的话,那应该是问得更深层的了。我想
我应该能理解楼主所问的问题,但是"common.h"和"life.h" 我没用过,更不用说回答你的问题了,呵呵,帮不上忙了。
这里说了这些,也只是希望往下来你这做客的朋友不会误会你的问题。还会关注
----------------解决方案--------------------------------------------------------
``````额`厉害``我还不会`得学学下`
----------------解决方案--------------------------------------------------------
学习中!
----------------解决方案--------------------------------------------------------
common.h文件主要包括如下内容:
#include<stdio.h>
#include<stdib.h>
typedef enum Boolean{FALSE,TRUE}Boolean;
void Error(char*);
void Warning(char*);
life.h:
......
......
只是想知道如何使用这两个文件!!在主程开头写这些程序??
----------------解决方案--------------------------------------------------------
生命游戏,我以前用VB做过,挺有趣的
头文件就是引用进来的,
#include"common.h" /* common include files and definitions */
#include"life.h" /* Life's defines,typedefs,and prototypes */
写了这两句,这两个文件的所有内容就自动加到了这个文件里面,可以直接调用这两个文件里面的函数
----------------解决方案--------------------------------------------------------