Esempio n. 1
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();
        }
Esempio n. 2
0
 private void btnClear_Click(object sender, EventArgs e)
 {
     tmrTime.Stop();
     btnStartStop.Text = Constant.START;
     isOK = false;
     Biz.InitGrid();
     Biz.GetAllLife();
     for (int i = 0; i < 5; i++)
     {
         FileStream   fs = new FileStream("res" + (i + 1) + ".txt", FileMode.Create, FileAccess.Write);
         StreamWriter sw = new StreamWriter(fs);
         sw.Close();
         fs.Close();
     }
 }
Esempio n. 3
0
 private void btnChangePoint_Click(object sender, EventArgs e)
 {
     try
     {
         int x = Convert.ToInt32(txtChangeX.Text.ToString());
         int y = Convert.ToInt32(txtChangeY.Text.ToString());
         if (x < 1 || x > 150 || y < 1 || y > 150)
         {
             MessageBox.Show("坐标范围:1~150");
             return;
         }
         Biz.giveChange(x, y);
     }
     catch
     {
         MessageBox.Show("输入不合法");
     }
 }
Esempio n. 4
0
 private void tmrTime_Tick(object sender, EventArgs e)
 {
     if (Biz.TimerCount > 0)
     {
         Biz.TimerCount--;
     }
     else if (Biz.TimerCount == 0)
     {
         tmrTime.Stop();
         Biz.TimerCount--;
         picCanvas.Enabled = true;
         trbSpeed_Scroll(null, null);
     }
     else
     {
         Biz.NextGeneration();
     }
 }
Esempio n. 5
0
 private void btnStartStop_Click(object sender, EventArgs e)
 {
     if (btnStartStop.Text == Constant.START)
     {
         if (!isOK)
         {
             Biz.RandomSeed();
             isOK = true;
         }
         Biz.GetAllLife();
         tmrTime.Start();
         btnStartStop.Text = Constant.STOP;
     }
     else
     {
         btnStartStop.Text = Constant.START;
         tmrTime.Stop();
     }
 }
Esempio n. 6
0
        /// <summary>
        /// 绘制所有生命
        /// </summary>
        public static void DrawAllLife()
        {
            FormMain.form.setCount();
            Random     rnd         = new Random();
            Graphics   g           = Biz.InitGrid();
            SolidBrush blackBrush  = new SolidBrush(Color.Red);
            SolidBrush whiteBrush  = new SolidBrush(Color.White);
            SolidBrush blueBrush   = new SolidBrush(Color.Blue);
            SolidBrush greenBrush  = new SolidBrush(Color.Green);
            SolidBrush redBrush    = new SolidBrush(Color.Purple);
            SolidBrush yellowBrush = new SolidBrush(Color.Yellow);
            SolidBrush purpleBrush = new SolidBrush(Color.Black);

            for (int i = 0; i < Constant.GRID_COUNT; i++)
            {
                for (int j = 0; j < Constant.GRID_COUNT; j++)
                {
                    int x = j * Constant.GRID_WIDTH + 1;
                    int y = i * Constant.GRID_WIDTH + 1;
                    switch (Biz.World[i, j].colorKind)
                    {
                    case Constant.NOLIFE: g.FillRectangle(whiteBrush, x, y, Constant.LIFE_WIDTH, Constant.LIFE_WIDTH); break;

                    case Constant.GRASS: g.FillRectangle(greenBrush, x, y, Constant.LIFE_WIDTH, Constant.LIFE_WIDTH); break;

                    case Constant.GRASS_ANIMAL: g.FillRectangle(blueBrush, x, y, Constant.LIFE_WIDTH, Constant.LIFE_WIDTH); break;

                    case Constant.LOW_ANIMAL: g.FillRectangle(yellowBrush, x, y, Constant.LIFE_WIDTH, Constant.LIFE_WIDTH); break;

                    case Constant.HIGH_ANIMAL: g.FillRectangle(redBrush, x, y, Constant.LIFE_WIDTH, Constant.LIFE_WIDTH); break;

                    case Constant.PEOPLE_ANIMAL: g.FillRectangle(blackBrush, x, y, Constant.LIFE_WIDTH, Constant.LIFE_WIDTH); break;

                    case Constant.BOSS: g.FillRectangle(purpleBrush, x, y, Constant.LIFE_WIDTH, Constant.LIFE_WIDTH); break;
                    }
                }
            }
            Biz.Canvas.Refresh();
        }
Esempio n. 7
0
 private void btnSaveState_Click(object sender, EventArgs e)
 {
     try
     {
         int x_min = Convert.ToInt32(txtDisXmin.Text.ToString());
         int x_max = Convert.ToInt32(txtDisXmax.Text.ToString());
         int y_min = Convert.ToInt32(txtDisYmin.Text.ToString());
         int y_max = Convert.ToInt32(txtDisYmax.Text.ToString());
         if (x_min < 1 || x_max > 150 || y_min < 1 || y_max > 150)
         {
             MessageBox.Show("坐标范围:1~150");
             return;
         }
         if (x_min < x_max && y_min < y_max)
         {
             Biz.giveDisaster(x_min - 1, x_max - 1, y_min - 1, y_max - 1);
         }
     }
     catch
     {
         MessageBox.Show("输入不合法");
     }
 }
Esempio n. 8
0
 private void FormMain_Load(object sender, EventArgs e)
 {
     Biz.InitGrid();
     Biz.GetAllLife();
 }
Esempio n. 9
0
 private void btnRndSeed_Click(object sender, EventArgs e)
 {
     Biz.RandomSeed();
     isOK = true;
 }