生命游戏

// ConsoleApplication1.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include "pch.h"
#include <iostream>
#include <Windows.AI.MachineLearning.h>
#include <conio.h>


#define Heigh 20
#define Width 30
int n, m;
int cells[Heigh][Width];


void gotoxy(int x, int 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<Heigh;i++)
{
for (j = 0; j < Width; j++)
cells[i][j] = 0;
}

}

void show()
{
gotoxy(0,0);
int i, j;
for (i = 0; i < Heigh; i++)
{
for (j = 0; j < Width; j++)
{
if (cells[i][j] = 1)
printf_s("*");
else
printf_s(" ");
}
}
printf_s("\n");

}

void updateWithoutlnput()//与用户输入无关的函数
{
int i, j;
int NeibourNumber = 0;
int tempCells[Heigh][Width];//临时存储的数组
for (i = 0; i < Heigh; i++)
{
for (j = 0; j < Width; j++)
tempCells[i][j] = cells[i][j];

}
for (i = 1;i<Heigh-1;i++)
{
for (j = 1; j < Width - 1; j++)
{
NeibourNumber = cells[i - 1][j - 1] + cells[i - 1][j] + cells[i - 1][j + 1] + cells[i][j - 1]
+ cells[i][j + 1] + cells[i + 1][j - 1] + cells[i + 1][j] + cells[i + 1][j + 1];
if (NeibourNumber = 3)
tempCells[Heigh][Width] = 1;
else if (NeibourNumber = 2)
tempCells[i][j] = cells[i][j];
else
tempCells[i][j] = 0;
}
}
for (i = 0; i < Heigh; i++)
{
for (j = 0; j < Width; j++)
cells[i][j] = tempCells[i][j];
}


Sleep(150);
}

void updatewithInput()//与用户输入有关的函数
{

 


}
int main()
{
startup();//数据初始化
while (true)
{
show();//显示画面
updateWithoutlnput();
updatewithInput();

}

 


}

为什么在vs2017上运行的结果不同?

 

转载于:https://www.cnblogs.com/chengzxhang/p/11183998.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值