日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

C语言——生命游戏(初始

發布時間:2023/12/10 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C语言——生命游戏(初始 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#include<stdio.h> #include<stdlib.h> #include<conio.h> #include<windows.h> #include<time.h>#define High 25 #define Width 50 //游戲畫面的尺寸int cells[High][Width]; //所有位置細胞生為1,死亡為0void gotoxy(int x,int y) //將光標移到(x,y)位置 {HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);COORD pos;pos.X = x;pos.Y = y;SetConsoleCursorPosition(handle,pos); }void startup() //數據的初始化 {int i,j;for(i = 0; i < High; i++)for(j = 0; j < Width; j++){cells[i][j] = rand()%2;} }void show() //顯示畫面 {gotoxy(0,0); //光標移動到原點位置,以下重畫清屏int i,j;for(i = 0; i <= High; i++){for(j = 0; j <= Width; j++){if(cells[i][j] == 1)printf("*"); //輸出活細胞elseprintf(" "); //輸出死細胞 }printf("\n");}Sleep(50); }void updateWithoutInput() //與用戶輸入無關的更新 {}void updateWithInput() //與用戶輸入有關的更新 {}int main() {startup();while(1){show();updateWithoutInput();updateWithInput();}return 0; } #include<stdio.h> #include<stdlib.h> #include<conio.h> #include<windows.h> #include<time.h>#define High 25 #define Width 50 //游戲畫面的尺寸int cells[High][Width]; //所有位置細胞生為1,死亡為0void gotoxy(int x,int y) //將光標移到(x,y)位置 {HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);COORD pos;pos.X = x;pos.Y = y;SetConsoleCursorPosition(handle,pos); }void startup() //數據的初始化 {int i,j;for(i = 0; i < High; i++)for(j = 0; j < Width; j++){cells[i][j] = rand()%2;} }void show() //顯示畫面 {gotoxy(0,0); //光標移動到原點位置,以下重畫清屏int i,j;for(i = 0; i <= High; i++){for(j = 0; j <= Width; j++){if(cells[i][j] == 1)printf("*"); //輸出活細胞elseprintf(" "); //輸出死細胞 }printf("\n");}Sleep(50); }void updateWithoutInput() //與用戶輸入無關的更新 {}void updateWithInput() //與用戶輸入有關的更新 {}int main() {startup();while(1){show();updateWithoutInput();updateWithInput();}return 0; }

?

轉載于:https://www.cnblogs.com/JAYPARK/p/10267094.html

總結

以上是生活随笔為你收集整理的C语言——生命游戏(初始的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。