life game
2026-06-18 10:47:22
发布于:浙江
/*Carrot*/
#include<bits/stdc++.h>
#include<Windows.h>
using namespace std;
const int n=30,m=100;
int a[m][n];
int main(){
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cursorInfo;
GetConsoleCursorInfo(console, &cursorInfo);
cursorInfo.bVisible = false;
SetConsoleCursorInfo(console, &cursorInfo);
cout.tie(0);
//自主填写↓
a[15][15]=a[15][16]=a[15][14]=a[16][15]=a[14][15]=1;
//自主填写↑
while(1){
Sleep(0.5);
system("cls");
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i][j])cout<<"■";
else cout<<' ';
}
cout<<'\n';
}
Sleep(0.5);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
int cnt=0;
if(a[i-1][j])cnt++;
if(a[i][j-1])cnt++;
if(a[i+1][j])cnt++;
if(a[i][j+1])cnt++;
if(a[i-1][j-1])cnt++;
if(a[i-1][j+1])cnt++;
if(a[i+1][j-1])cnt++;
if(a[i+1][j+1])cnt++;
//自主填写↓
if(cnt>=2 && cnt<=3)a[i][j]=1;
//自主填写↑
else a[i][j]=0;
}
}
}
}
这里空空如也























有帮助,赞一个