Tools.cs
1.43 KB
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
using System;
namespace Flicker
{
internal static class Tools
{
public static T Clamp<T>(this T val, T min)
where T : IComparable<T> =>
val.CompareTo(min) < 0
? min
: val;
public static T Clamp<T>(this T val, T min, T max)
where T : IComparable<T> =>
val.CompareTo(min) < 0
? min
: val.CompareTo(max) > 0
? max
: val;
public static T Wrap<T>(this T val, T min, T max)
where T : IComparable<T> =>
val.CompareTo(min) < 0
? max
: val.CompareTo(max) > 0
? min
: val;
public static class Console
{
public static void WriteAt(int x, int y, string str)
{
System.Console.CursorLeft = x;
System.Console.CursorTop = y;
System.Console.Write(str);
}
public static void WriteAt(int x, int y, string str, ConsoleColor colour)
{
var old = System.Console.ForegroundColor;
System.Console.ForegroundColor = colour;
WriteAt(x, y, str);
System.Console.ForegroundColor = old;
}
public static void Fill(int x, int y, int width, int height, char c)
{
for (var i = x; i < x + width; ++i)
for (var j = y; j < y + height; ++j)
WriteAt(i, j, c.ToString());
}
public static void Fill(int x, int y, int width, int height, char c, ConsoleColor colour)
{
var old = System.Console.ForegroundColor;
System.Console.ForegroundColor = colour;
Fill(x, y, width, height, c);
System.Console.ForegroundColor = old;
}
}
}
}