#include<bits/stdc++.h>
#include<stdlib.h>
#include<windows.h>
#include<conio.h>
#include <time.h>
#include <dos.h>
#define Speed 4
#define LL 50
#define Bar 30 //障碍数
using namespace std;
int high,width;
int speed;
int iskill;
int bao[LL][LL];
void gotoxy(int x, int y) //光标移动到x,y位置
{
COORD pos = {x,y};
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);// 获取标准输出设备句柄
SetConsoleCursorPosition(hOut, pos); //两个参数分别是指定哪个窗体,具体位置
}
void HideCursor() // 用于隐藏光标
{
CONSOLE_CURSOR_INFO cursor_info = {1, 0}; // 第二个值为0表示隐藏光标
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);//函数和结构体都在windows.h中定义。
}
void startup()
{
srand(time(NULL));
HideCursor();
//high=27;
//width=100;
for(int i=0;i<LL;i++)
{
for(int x=0;x<LL;x++)
{
bao[i][x]=1;
}
}
speed=0;
iskill=0;
}
void show()
{
gotoxy(0,0);
for(int i=0;i<LL;i++)
{
for(int j=0;j<LL;j++)
{
if(bao[i][j]==1) printf("*");
else printf(" ");
}
printf("\n");
}
}
int islive(int i,int x)
{
int is=0;
for(int ii=i-1;ii<=i+1;ii++)
{
for(int xx=x-1;xx<=x+1;xx++)
{
if(i==ii&&x==xx) continue;
if(bao[ii][xx]==1) is++;
}
}
return is;
}
void updateWithoutInput()
{
for(int i=0;i<LL;i++)
{
for(int x=0;x<LL;x++)
{
if(islive(i,x)==3) bao[i][x]=1;
else if(islive(i,x)==2) continue;
else bao[i][x]=0;
}
}
Sleep(100);
}
void updateWithInput()
{
}
int main()
{
startup(); //数据初始化
while(1) //游戏循环执行
{
show(); //游戏画面
updateWithoutInput(); //与输入无关更新
updateWithInput(); //与输入有关更新
}
return 0;
}