diff --git a/Emne 3/Trafikklys/Trafikklys/Demo1/Demo1.cs b/Emne 3/Trafikklys/Trafikklys/Demo1/Demo1.cs new file mode 100644 index 0000000..c0c2220 --- /dev/null +++ b/Emne 3/Trafikklys/Trafikklys/Demo1/Demo1.cs @@ -0,0 +1,39 @@ +namespace Trafikklys.Demo1; + +internal class Demo1 +{ + public static void Run() + { + var red = true; + var yellow = false; + var green = false; + + while (true) + { + Console.Clear(); + TrafikklysKonsoll.Show(red, yellow, green); + if (red && !yellow) + { + yellow = true; + } + else if (red) + { + red = false; + yellow = false; + green = true; + } + else if (green) + { + green = false; + yellow = true; + } + else if (yellow) + { + yellow = false; + red = true; + } + + Console.ReadKey(true); + } + } +} diff --git a/Emne 3/Trafikklys/Trafikklys/Program.cs b/Emne 3/Trafikklys/Trafikklys/Program.cs index 5f28270..567871d 100644 --- a/Emne 3/Trafikklys/Trafikklys/Program.cs +++ b/Emne 3/Trafikklys/Trafikklys/Program.cs @@ -1 +1,3 @@ - \ No newline at end of file +using Trafikklys.Demo1; + +Demo1.Run(); diff --git a/Emne 3/Trafikklys/Trafikklys/TrafikklysKonsoll.cs b/Emne 3/Trafikklys/Trafikklys/TrafikklysKonsoll.cs new file mode 100644 index 0000000..5777a77 --- /dev/null +++ b/Emne 3/Trafikklys/Trafikklys/TrafikklysKonsoll.cs @@ -0,0 +1,31 @@ +using System.Text; +namespace Trafikklys; + +internal class TrafikklysKonsoll +{ + public static void Show(bool red, bool yellow, bool green) + { + Console.OutputEncoding = Encoding.UTF8; + Console.Clear(); + Console.ForegroundColor = ConsoleColor.Gray; + //Console.WriteLine("\u250f\u2501\u2513"); + Console.WriteLine("┏━┓"); + DrawLine(red ? ConsoleColor.Red : ConsoleColor.Black); + DrawLine(yellow ? ConsoleColor.Yellow : ConsoleColor.Black); + DrawLine(green ? ConsoleColor.Green : ConsoleColor.Black); + Console.WriteLine("┗━┛"); + //Console.WriteLine("\u2517\u2501\u251b"); + } + + private static void DrawLine(ConsoleColor color) + { + Console.ForegroundColor = ConsoleColor.Gray; + Console.Write("┃"); + //Console.Write("\u2503"); + Console.ForegroundColor = color; + Console.Write("O"); + Console.ForegroundColor = ConsoleColor.Gray; + Console.WriteLine("┃"); + //Console.Write("\u2503"); + } +} \ No newline at end of file