?? main.cpp
字號:
/*Simulation of Conway's game of life on a bounded grid
Pre: The user must supply an initial configuration of living cells.
Post: The programme prints a sequence of maps showing the changes in the configuration ofliving
cells according to the rules for the game of life.
uses:function Initialize,Writemap,NeighborCount,and UserSaysYes */
#include "common.h" /*common.h include filesand definitions*/
#include "life.h" /*life's defines,typedefs,and prototypes*/
#include "functions.h" /*functions.h include functions will be used*/
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]=newmap[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 denerations");
}while(UserSaysYes());
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -