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(); } }
/// <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(); }
private void FormMain_Load(object sender, EventArgs e) { Biz.InitGrid(); Biz.GetAllLife(); }