C语言——生命游戏(初始
生活随笔
收集整理的這篇文章主要介紹了
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语言——生命游戏(初始的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数据库课程设计(实训)
- 下一篇: Qt 有层级关系的qss样式,使用id定