-
Notifications
You must be signed in to change notification settings - Fork 0
/
sim 2.cs
108 lines (90 loc) · 3.46 KB
/
sim 2.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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 v1
{
public partial class Form1 : Form
{
string lastDirection = string.Empty;
string directionHolder = string.Empty;
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
cbDirection.SelectedIndex = 0;
cbLight.SelectedIndex = 0;
lblLightStatus.Text = "Green";
lblDirection.Text = "Not moving";
radSemiTruck.Select();
}
private void btnSim_Click(object sender, EventArgs e)
{
directionHolder = cbDirection.Text;
if((lblDirection.Text.Equals("Jack Knife to a Stop") && !(cbDirection.SelectedIndex.Equals(0))) ||
lblDirection.Text.Equals("Run Over Ford Pinto") && !(cbDirection.SelectedIndex.Equals(0)))
{
MessageBox.Show($"After {lblDirection.Text} you can only move forward!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (lastDirection.Equals("Move Forward") && directionHolder.Equals("Move Forward"))
{
MessageBox.Show("Cannot move forward twice in a row!","Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if(cbDirection.SelectedIndex.Equals(1) && !(cbLight.SelectedIndex.Equals(3)))
{
MessageBox.Show("Can only make left turn on signal Left-Turn Green", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
switch (cbLight.SelectedIndex)
{
case 0:
case 3:
lblLightStatus.ForeColor = Color.Green;
break;
case 1:
lblLightStatus.ForeColor = Color.Yellow;
break;
case 2:
lblLightStatus.ForeColor = Color.Red;
break;
}
lblDirection.Text = cbDirection.SelectedItem.ToString();
lblLightStatus.Text = cbLight.SelectedItem.ToString();
lastDirection = cbDirection.SelectedItem.ToString();
cbLight.SelectedIndex = 0;
}
private void lblLightStatus_Click(object sender, EventArgs e)
{
}
private void radSemiTruck_CheckedChanged(object sender, EventArgs e)
{
cbDirection.Items.RemoveAt(3);
cbDirection.Items.Add("Jack Knife to a Stop");
cbDirection.SelectedIndex = 0;
cbLight.SelectedIndex = 0;
lblLightStatus.Text = "Green";
lblDirection.Text = "Not moving";
}
private void radSuv_CheckedChanged(object sender, EventArgs e)
{
cbDirection.Items.RemoveAt(3);
cbDirection.Items.Add("Run Over Ford Pinto");
cbDirection.SelectedIndex = 0;
cbLight.SelectedIndex = 0;
lblLightStatus.Text = "Green";
lblDirection.Text = "Not moving";
}
}
}