生命游戏C++代码initgraph窗口版(有功能未开放) 由于作者实力较弱代码可能产生漏洞请原谅#includebits/stdc.h#includegraphics.h#includeconio.h#includethread#includemutex#includechrono#includecstdio#includevector#includequeue#includewindows.hconstintROWS55;constintCOLS112;usingnamespacestd;intd1;//初始化生命的第几代boolrunningfalse;structCell{intx,y;intf0;}sum[ROWS][COLS],sum2[ROWS][COLS];boolISMouse_Up(intmouseX,intmouseY,intx1,inty1,intx2,inty2){return(mouseXx1mouseXx2mouseYy1mouseYy2);}inlinevoidhua_mian(intdaishu){chardaishu_[101];sprintf(daishu_,%d,daishu);outtextxy(50,25,第 代);outtextxy(73,25,daishu_);for(inti1;iCOLS;i)line(i*10,60,i*10,600);for(inti1;iROWS;i)line(0,50i*10,1110,50i*10);rectangle(180,10,300,50);outtextxy(215,25,下一代);rectangle(315,10,395,50);outtextxy(340,25,清空);rectangle(430,10,500,50);outtextxy(450,25,开始);rectangle(505,10,575,50);outtextxy(525.5,25,结束);}voidchu_shi_hua(){for(inti0;iROWS;i)for(intj0;jCOLS;j){sum[i][j].xj*10-10;sum[i][j].y50i*10;}}voidqin_kong(){d1;cleardevice();hua_mian(d);for(inti1;iROWS;i){for(intj1;jCOLS;j){sum[i][j].f0;}}}voidupdate(){for(inti1;iROWS;i)for(intj1;jCOLS;j)sum[i][j].fsum2[i][j].f;cleardevice();hua_mian(d);for(inti1;iROWS;i)for(intj1;jCOLS;j)if(sum[i][j].f)bar(sum[i][j].x,sum[i][j].y,sum[i][j].x10,sum[i][j].y10);}voidbegin(){}voidend(){}voidgo(){for(inti1;iROWS;i)for(intj1;jCOLS;j)sum2[i][j].f0;for(inti1;iROWS;i){for(intj1;jCOLS;j){intlive_neighbors0;for(intk-1;k1;k){for(intm-1;m1;m){if(k0m0)continue;intrik;intcjm;if(r0rROWSc0cCOLS)live_neighborssum[r][c].f;}}if(sum[i][j].f){sum2[i][j].f(live_neighbors2||live_neighbors3)?1:0;}else{sum2[i][j].f(live_neighbors3)?1:0;}}}d;return;}voidmain_(){MOUSEMSG mouse;for(;;){mouseGetMouseMsg();if(mouse.uMsgWM_LBUTTONDOWN){if(ISMouse_Up(mouse.x,mouse.y,180,10,300,50)){go();update();}elseif(ISMouse_Up(mouse.x,mouse.y,315,10,395,50)){qin_kong();}elseif(ISMouse_Up(mouse.x,mouse.y,430,10,500,50)){begin();}elseif(ISMouse_Up(mouse.x,mouse.y,505,10,575,50)){end();}else{for(inti1;iROWS;i)for(intj1;jCOLS;j)if(ISMouse_Up(mouse.x,mouse.y,sum[i][j].x,sum[i][j].y,sum[i][j].x10,sum[i][j].y10)){COLORREF colorgetpixel(sum[i][j].x5,sum[i][j].y5);if(GetRValue(color)255GetGValue(color)255GetBValue(color)255){setfillcolor(RGB(0,0,0));setcolor(RGB(0,0,0));bar(sum[i][j].x1,sum[i][j].y1,sum[i][j].x10,sum[i][j].y10);sum[i][j].f0;setfillcolor(RGB(255,255,255));setcolor(RGB(255,255,255));}else{bar(sum[i][j].x,sum[i][j].y,sum[i][j].x10,sum[i][j].y10);sum[i][j].f1;}break;}}}}}intmain(){initgraph(1110,600,2);//建立一个1110*600的窗口cleardevice();//初始化窗口setfillcolor(RGB(255,255,255));//定义书写颜色setcolor(RGB(255,255,255));//定义窗口颜色chu_shi_hua();//初始化数据hua_mian(d);main_();getchar();}//版权归zzxjason所有请勿转载发帖

相关新闻

最新新闻

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现 【免费下载链接】serenity The Serenity Operating System 🐞 项目地址: https://gitcode.com/GitHub_Trending/se/serenity 导读 本文以 getopt(3) 手册 为核心&a…

2026/10/5 3:18:56
轻量服务器还是ECS?大促云服务器选购与避坑实战指南

轻量服务器还是ECS?大促云服务器选购与避坑实战指南

每年大促节点,群里永远有人在问同一个问题:“38元的轻量服务器到底怎么抢?为什么我每次点进去都是已售罄?68元直购和99元的ECS我到底选哪个?”作为一个常年帮团队和自己采购云服务器的老用户,我太清楚这种纠…

2026/10/5 3:42:18
为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南

为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南

为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南 【免费下载链接】agents Multi-harness agentic plugin marketplace for Claude Code, Codex, Cursor, OpenCode, GitHub Copilot, and Google Antigravity 项目地址:…

2026/10/5 19:39:38
PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署

PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署

PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署 【免费下载链接】PaddleOCR Turn any PDF or image document into structured data for your AI. A powerful, lightweight OCR toolkit that bridges the gap between i…

2026/10/5 16:06:34
Spring源码解析:构造器注入的类型转换与候选匹配机制

Spring源码解析:构造器注入的类型转换与候选匹配机制

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/5 5:51:09
openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由

openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由

openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由 【免费下载链接】openai-agents-python A lightweight, powerful framework for multi-agent workflows 项目地址: https://gitcode.com/GitHub_Trending/op/openai-agents-pyth…

2026/10/5 5:40:36

日新闻

周新闻

月新闻