Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace Ampel
- {
- public partial class Form1 : Form
- {
- private bool trafficBroken = false;
- private Graphics licht1;
- private Graphics licht2;
- private Graphics licht3;
- private int[] koordsl1 = new int[2] { 7, 5 };
- private int[] koordsl2 = new int[2] { 7, 80 };
- private int[] koordsl3 = new int[2] { 7, 150 };
- private SolidBrush sb = new SolidBrush(Color.White);
- private int AmpelStep = 1;
- public Form1()
- {
- InitializeComponent();
- }
- public void UpdateAmpel()
- {
- if (trafficBroken == false)
- {
- if (AmpelStep == 1)
- {
- sb.Color = Color.Yellow;
- licht2.FillEllipse(sb, koordsl2[0], koordsl2[1], 60, 60);
- timer1.Interval = 500;
- AmpelStep = 2;
- return;
- }
- else if (AmpelStep == 2)
- {
- sb.Color = Color.White;
- licht1.FillEllipse(sb, koordsl1[0], koordsl1[1], 60, 60);
- licht2.FillEllipse(sb, koordsl2[0], koordsl2[1], 60, 60);
- sb.Color = Color.Green;
- licht3.FillEllipse(sb, koordsl3[0], koordsl3[1], 60, 60);
- timer1.Interval = 2000;
- AmpelStep = 3;
- return;
- }
- else if (AmpelStep == 3)
- {
- sb.Color = Color.White;
- licht3.FillEllipse(sb, koordsl3[0], koordsl3[1], 60, 60);
- sb.Color = Color.Yellow;
- licht2.FillEllipse(sb, koordsl2[0], koordsl2[1], 60, 60);
- timer1.Interval = 750;
- AmpelStep = 4;
- return;
- }
- else if (AmpelStep == 4)
- {
- sb.Color = Color.Red;
- licht1.FillEllipse(sb, koordsl1[0], koordsl1[1], 60, 60);
- sb.Color = Color.White;
- licht2.FillEllipse(sb, koordsl2[0], koordsl2[1], 60, 60);
- timer1.Interval = 1000;
- AmpelStep = 1;
- return;
- }
- }
- else
- {
- if (timer1.Interval != 250)
- {
- timer1.Interval = 250;
- timer1.Stop();
- timer1.Start();
- }
- if (AmpelStep == 5)
- {
- sb.Color = Color.White;
- licht2.FillEllipse(sb, koordsl2[0], koordsl2[1], 60, 60);
- AmpelStep = 6;
- }
- else if (AmpelStep == 6)
- {
- sb.Color = Color.Yellow;
- licht2.FillEllipse(sb, koordsl2[0], koordsl2[1], 60, 60);
- AmpelStep = 5;
- }
- return;
- }
- return;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (timer1.Enabled == true)
- {
- timer1.Stop();
- button1.Text = "Start!";
- }
- else
- {
- timer1.Start();
- button1.Text = "Stop!";
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- progressBar1.Value = 0;
- button1.Text = "Start";
- sb.Color = Color.Red;
- licht1.FillEllipse(sb, koordsl1[0], koordsl1[1], 60, 60);
- sb.Color = Color.White;
- licht2.FillEllipse(sb, koordsl2[0], koordsl2[1], 60, 60);
- licht3.FillEllipse(sb, koordsl3[0], koordsl3[1], 60, 60);
- timer1.Stop();
- trafficBroken = false;
- richTextBox4.Text = "";
- timer1.Interval = 1000;
- button2.Enabled = false;
- AmpelStep = 1;
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- if (trafficBroken == false)
- {
- if (progressBar1.Value == 100)
- { progressBar1.Value = 0; }
- progressBar1.Value += 20;
- if (progressBar1.Value == 100)
- {
- Random counte = new Random();
- int count = counte.Next(0, 12);
- if (count == 8)
- {
- richTextBox4.Text = "Die Ampel ist kaputt! Sie wird nun nur noch gelb leuchten! Klicke auf Reparieren, um die Ampel zu reparieren!";
- trafficBroken = true;
- button2.Enabled = true;
- timer1.Interval = 250;
- sb.Color = Color.White;
- licht1.FillEllipse(sb, koordsl1[0], koordsl1[1], 60, 60);
- licht3.FillEllipse(sb, koordsl3[0], koordsl3[1], 60, 60);
- AmpelStep = 6;
- return;
- }
- UpdateAmpel();
- return;
- }
- }
- else UpdateAmpel();
- return;
- }
- private void panel1_Paint(object sender, PaintEventArgs e)
- {
- sb.Color = Color.Red;
- licht1 = panel1.CreateGraphics();
- licht1.FillEllipse(sb, 7, 5, 60, 60);
- sb.Color = Color.White;
- licht2 = panel1.CreateGraphics();
- licht2.FillEllipse(sb, 7, 80, 60, 60);
- licht3 = panel1.CreateGraphics();
- licht3.FillEllipse(sb, 7, 150, 60, 60);
- }
- private void beendenToolStripMenuItem_Click(object sender, EventArgs e)
- {
- DialogResult result;
- result = MessageBox.Show("Wollen sie die Ampel wirklich schließen?", "Schließen", MessageBoxButtons.YesNo);
- if (result == DialogResult.Yes)
- {
- this.Close();
- }
- }
- private void changelogToolStripMenuItem_Click(object sender, EventArgs e)
- {
- MessageBox.Show("Neues:\nEs gibt nun eine runde Leuchte für die Ampelfarben.\nEs gibt den Beenden Button in der Menüleiste.\nEs gibt nun den Changelog und auch die Informationen zum Ersteller.\nDie Chance, das die Ampel kaputt geht liegt nun bei 1:12\nClose-Button entfernt","Changelog - Version 1.1");
- }
- private void erstellerToolStripMenuItem_Click(object sender, EventArgs e)
- {
- MessageBox.Show("Ersteller: NicoAiko\nAlter: 17 Jahre\nWunschberuf: Spieleentwickler\n\nViel Spaß mit diesem sinnlosen, aber trotzdem unterhaltsamen Programm.","Ersteller");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement