using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApp1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Boolean stan = false; private int ROZM; private int[,] Plansza; int[,] temp_plansza; int lvl; public int ile_sasiadow(int x, int y) { int suma; suma = Plansza[x - 1, y - 1] + Plansza[x, y - 1] + Plansza[x + 1, y - 1] + Plansza[x - 1, y] + Plansza[x + 1, y] + Plansza[x - 1, y + 1] + Plansza[x, y + 1] + Plansza[x + 1, y + 1]; return suma; } private void panel1_Paint(object sender, PaintEventArgs e) { ROZM = Decimal.ToInt32(numericUpDown1.Value); Graphics g = e.Graphics; int pole = 600/ROZM; if (stan) { for (int i = 0; i < ROZM; i++) { for (int j = 0; j < ROZM; j++) { if (Plansza[i, j] == 0) g.FillRectangle(Brushes.Red, i * pole, j * pole, pole - 1, pole - 1); else g.FillRectangle(Brushes.Green, i * pole, j * pole, pole - 1, pole - 1); } } } } private void panel2_Paint(object sender, PaintEventArgs e) { label1.Text = "Krok " + lvl; } private void numericUpDown1_ValueChanged(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { ROZM = Decimal.ToInt32(numericUpDown1.Value); Plansza = new int[ROZM, ROZM]; for (int i = 0; i < ROZM; i++) { for (int j = 0; j < ROZM; j++) { Plansza[i, j] = 0; } } Plansza[ROZM / 2, ROZM / 2] = 1; Plansza[ROZM / 2 - 1, ROZM / 2] = 1; Plansza[ROZM / 2 + 1, ROZM / 2] = 1; Plansza[ROZM / 2 + 1, ROZM / 2 - 1] = 1; Plansza[ROZM / 2 - 1, ROZM / 2 - 1] = 1; Plansza[ROZM / 2 - 1, ROZM / 2 + 1] = 1; Plansza[ROZM / 2 + 1, ROZM / 2 + 1] = 1; Plansza[ROZM / 2, ROZM / 2 + 1] = 1; stan = true; lvl = 0; panel1.Refresh(); } private void button2_Click(object sender, EventArgs e) { lvl++; ROZM = Decimal.ToInt32(numericUpDown1.Value); int stana; int il_sasiad; temp_plansza = new int[ROZM, ROZM]; int w1 = Decimal.ToInt32(numericUpDown2.Value); int w2 = Decimal.ToInt32(numericUpDown3.Value); int w3 = Decimal.ToInt32(numericUpDown4.Value); int w4 = Decimal.ToInt32(numericUpDown5.Value); for (int x = 1; x < ROZM - 1; ++x) { for (int y = 1; y < ROZM - 1; ++y) { stana = Plansza[x, y]; il_sasiad = ile_sasiadow(x, y); if (stana == 1) { if (il_sasiad < w1 || il_sasiad > w2) stana = 0; } else { if (il_sasiad <= w3 && il_sasiad >= w4) stana = 1; } temp_plansza[x, y] = stana; } } for (int x = 1; x < ROZM - 1; ++x) { for (int y = 1; y < ROZM - 1; ++y) { Plansza[x, y] = temp_plansza[x, y]; } } Refresh(); } private void button3_Click(object sender, EventArgs e) { int skok = Decimal.ToInt32(numericUpDown6.Value); for(int i=0; i< skok; i++) { lvl++; ROZM = Decimal.ToInt32(numericUpDown1.Value); int stana; int il_sasiad; temp_plansza = new int[ROZM, ROZM]; int w1 = Decimal.ToInt32(numericUpDown2.Value); int w2 = Decimal.ToInt32(numericUpDown3.Value); int w3 = Decimal.ToInt32(numericUpDown4.Value); int w4 = Decimal.ToInt32(numericUpDown5.Value); for (int x = 1; x < ROZM - 1; ++x) { for (int y = 1; y < ROZM - 1; ++y) { stana = Plansza[x, y]; il_sasiad = ile_sasiadow(x, y); if (stana == 1) { if (il_sasiad < w1 || il_sasiad > w2) stana = 0; } else { if (il_sasiad <= w3 && il_sasiad >= w4) stana = 1; } temp_plansza[x, y] = stana; } } for (int x = 1; x < ROZM - 1; ++x) { for (int y = 1; y < ROZM - 1; ++y) { Plansza[x, y] = temp_plansza[x, y]; } } } Refresh(); } } }