Vi lærte litt om utf8 og om oppsett av csharp prosjekter

This commit is contained in:
Geir Okkenhaug Jerstad 2024-12-09 13:33:08 +01:00
parent 9841b6bd33
commit d3db60a6e3
3 changed files with 73 additions and 1 deletions

View file

@ -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);
}
}
}

View file

@ -1 +1,3 @@
 using Trafikklys.Demo1;
Demo1.Run();

View file

@ -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");
}
}