コード例 #1
0
        /// <summary>
        /// 随机布种
        /// </summary>
        public static void RandomSeed()
        {
            Random rnd = new Random();

            byte[] values = new byte[Constant.GRID_COUNT * Constant.GRID_COUNT];
            rnd.NextBytes(values);

            for (int i = 0; i < Constant.GRID_COUNT; i++)
            {
                for (int j = 0; j < Constant.GRID_COUNT; j++)
                {
                    if (values[i * Constant.GRID_COUNT + j] < Constant.CREAT_LIFE)
                    {
                        FormMain.form.LiveCount[Constant.GRASS - 1]++;
                        Biz.World[i, j].colorKind = Constant.GRASS;
                    }
                    else
                    {
                        Biz.World[i, j].colorKind = Constant.NOLIFE;
                    }
                }
            }
            HiddenWorld = World;
            Biz.DrawAllLife();
        }
コード例 #2
0
        /// <summary>
        /// 计算下一代
        /// </summary>
        public static void NextGeneration()
        {
            FormMain.form.LiveCount = new int[5];
            for (int i = 0; i < Constant.GRID_COUNT; i++)
            {
                for (int j = 0; j < Constant.GRID_COUNT; j++)
                {
                    if (Biz.World[i, j].colorKind != Constant.BOSS)
                    {
                        Rule.FourthJudeg(i, j);
                        Rule.EigthJudeg(i, j);
                        Rule.FifthJudeg(i, j);
                        Rule.SenventhJudeg(i, j);
                        Rule.FirstJudeg(i, j);
                        Rule.SecondJudeg(i, j);
                        Rule.ThirdJudeg(i, j);
                        Rule.SixthJudeg(i, j);

                        if (Biz.World[i, j].colorKind != Constant.NOLIFE)
                        {
                            Biz.HiddenWorld[i, j].lifeCount++;
                            FormMain.form.LiveCount[Biz.World[i, j].colorKind - 1]++;
                        }
                    }
                    else
                    {
                        Rule.bossJudeg(i, j);
                    }
                }
            }

            if (FormMain.form.isChange)
            {
                int n = rnd.Next(100);
                if (n > 98)
                {
                    int    x   = rnd.Next(Constant.GRID_COUNT);
                    int    y   = rnd.Next(Constant.GRID_COUNT);
                    string res = "(" + x + "," + y + ")处出现百年一遇的极其凶残的霸王物种";
                    FormMain.form.addItem(res);
                    Biz.HiddenWorld[x, y].colorKind = Constant.BOSS;
                }
            }
            if (FormMain.form.isPlace)
            {
                Rule.eleventhJudeg();
            }
            if (FormMain.form.PlaceRand)
            {
                Rule.tenthJudeg();
            }
            Node[,] tmp     = Biz.HiddenWorld;
            Biz.HiddenWorld = Biz.World;
            Biz.World       = tmp;
            //绘制
            Biz.DrawAllLife();
        }