📄 tlife.c
字号:
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
#define MAXROW 18
#define MAXCOL 60
int map[MAXROW+2][MAXCOL+2];
int newmap[MAXROW+2][MAXCOL+2];
int count=0;
void windowbg(int starty,int endy,int cl){
/*---------将本窗口背景颜色初始化--------*/
int i;
textbackground(cl);
for(i=0;i<=endy-starty;i++)insline();
}
initsys(){
/*全屏显示处理开始*/
int i;
int j;
int ch;
window(1,1,80,25);
clrscr();
textbackground(1);/*全屏背景设计为蓝色*/
for(i=0;i<25;i++)insline();
textcolor(15);
window(1,1,80,25);
clrscr();
gotoxy(18,8);
cprintf("03级计算机课程设计系列之----生态模拟系统");
gotoxy(20,11-1);
cprintf("欢迎你光临本生态模拟逼真系统!");
gotoxy(18,13-1);
cprintf("这里你将感受到最精彩的生态虚拟世界!");
gotoxy(24,15);
cprintf("学生:陈欢");
gotoxy(24,16);
cprintf("班级:03级计算机6班");
gotoxy(24,18);
cprintf("请按<回车>键进入欣赏");
while(1){
ch=bioskey(0)>>8;
count++;
if(count>1000)count=1;
if(ch==28)break;
if(ch==1)exit(0);
}
/*全屏显示处理结束*/
}
initme(){
int row,col,t1=0;
long n;
n=time(NULL);
srand((unsigned) n);
for(row=0;row<MAXROW+2;row++)
for(col=0;col<MAXCOL+2;col++){
map[row][col]=-1;
}
for(row=1;row<MAXROW+1;row++)
for(col=1;col<MAXCOL+1;col++){
for(;;){
t1=rand()%2;
if(t1==1||t1==0)break;
}
map[row][col]=t1;
}
}
wmap(){
int row,col;
clrscr();
window(3,2,79,23);
for(row=0;row<MAXROW+2;row++)
for(col=0;col<MAXCOL+2;col++){
if(map[row][col]==1){
gotoxy(col+3,row+1);
textcolor(14);
cprintf("%c",1);
textcolor(15);
}
if(map[row][col]==0){
gotoxy(col+3,row+1);
textcolor(4);
cprintf("%c",127);
textcolor(15);
}
if(map[row][col]==-1){
gotoxy(col+3,row+1);
cprintf("*");
}
}
}
int nbc(int row,int col){
int cnt=0;
if(map[row][col+1]==1)cnt++;
if(map[row][col-1]==1)cnt++;
if(map[row+1][col]==1)cnt++;
if(map[row-1][col]==1)cnt++;
if(map[row+1][col+1]==1)cnt++;
if(map[row-1][col-1]==1)cnt++;
if(map[row+1][col-1]==1)cnt++;
if(map[row-1][col+1]==1)cnt++;
return cnt;
}
cpymap(){
int row,col;
for(row=1;row<MAXROW+1;row++)
for(col=1;col<MAXCOL+1;col++){
map[row][col]=newmap[row][col];
}
}
main(){
char ch;
int row,col;
initsys();/*程序初始化*/
initme();/*初始化当代*/
wmap();/*输出当代信息*/
window(1,22,75,25);
gotoxy(8,1);
cprintf("怎么样,感受到了本系统给您带来的逼真虚拟世界了吧!");
gotoxy(25,2);
cprintf("[Y]继续演示 [N]退出");
gotoxy(10,3);
cprintf("学生:陈欢 班级:03级计算机6班 类型:课程设计 ");
for(;;){
ch=getch();
count++;
if(count>1000)count=0;
if(ch=='Y'||ch=='y')break;
if(ch=='n'||ch=='N')exit(0);
}
do{
count++;
for(row=1;row<MAXROW+1;row++)
for(col=1;col<MAXCOL+1;col++){
/*计算每一格子的有生邻居*/
switch(nbc(row,col)){
case 0: case 1:
/*不好意思,下一代此时孤独而死*/
newmap[row][col]=0;break;
case 2:
newmap[row][col]=map[row][col];break;
case 3:
newmap[row][col]=1;break;
case 4: case 5: case 6: case 7:
case 8:
newmap[row][col]=0;break;
}
}
cpymap();/*将newmap复制为map*/
wmap();/*打印map*/
window(1,22,75,25);
gotoxy(8,1);
cprintf("怎么样,感受到了本系统给您带来的逼真虚拟世界了吧!");
gotoxy(25,2);
cprintf("[Y]继续演示 [N]退出");
gotoxy(10,3);
cprintf("学生:陈欢 班级:03级计算机6班 类型:课程设计 ");
for(;;){
ch=getch();
if(ch=='Y'||ch=='y')break;
if(ch=='n'||ch=='N')exit(0);
}
}while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -