C# form ile bitki büyütme simülasyonu uygulaması nasıl yapılır?
Toolbox’dan eklenecekler: 2 Timer, 3 Button, 2 Label, 2 Picturebox, 1 Progressbar.
Form1 public partial class’ın altına yazılacak:
int gun, saat, gun1, gunes, su, evre, gun2;
Button2_Click:
su++;
if (su == 3)
{
MessageBox.Show("Su Fazla Bitki Çürüyebilir.");
}
if (su == 5)
{
MessageBox.Show("Bitki Çürüdü.");
timer1.Stop();
timer2.Stop();
button2.Enabled = false;
button3.Enabled = false;
}
Button3_Click:
gunes++;
if (gunes == 2)
{
MessageBox.Show("Güneş Çok Bitki Kuruyabilir.");
}
if (gunes == 4)
{
MessageBox.Show("Bitki Kurudu.");
timer1.Stop();
timer2.Stop();
button2.Enabled = false;
button3.Enabled = false;
}
Form1_Load:
progressBar1.Value = 0;
timer1.Interval = 230;
timer2.Interval = 1000;
button2.Enabled = false;
button3.Enabled = false;
Button1_Click:
gun1 = 1;
label2.Text = gun1 + ". Gün";
timer1.Start();
timer2.Start();
button2.Enabled = true;
button3.Enabled = true;
Timer2_Tick:
if (saat != 23)
{
saat++;
if (saat < 10)
{
label1.Text = "0" + saat.ToString() + ":00";
}
else
{
label1.Text = saat.ToString() + ":00";
}
}
else
{
gun1++;
gun2++;
label2.Text = gun1 + ". Gün";
saat = 0;
}
if (gun == 1)
{
su = 0;
}
if (saat >= 7 && saat <= 19)
{
pictureBox1.ImageLocation = "GUNDUZ.png";
}
else
{
pictureBox1.ImageLocation = "GECE.png";
}
if (evre == 0)
{
pictureBox2.ImageLocation = "EVRE1.png";
}
else if (evre == 1)
{
pictureBox2.ImageLocation = "EVRE2.png";
}
else if (evre == 2)
{
pictureBox2.ImageLocation = "EVRE3.png";
}
else if (evre == 3)
{
pictureBox2.ImageLocation = "EVRE4.png";
}
if (su == 0 && gunes == 0)
{
if (gun2 == 5)
{
gun2 = 0;
if (evre == 4)
{
evre = 0;
}
evre++;
}
}
if (su > 0 && gunes == 0)
{
if (gun2 == 3)
{
gun2 = 0;
if (evre == 4)
{
evre = 0;
}
evre++;
}
}
if (su > 0 && gunes > 0)
{
if (gun2 == 2)
{
gun2 = 0;
if (evre == 4)
{
evre = 0;
}
evre++;
}
}
Timer1_Tick:
if (progressBar1.Value != 100)
{
progressBar1.Value++;
}
else
{
progressBar1.Value = 0;
gun++;
}
Çıktısı:
