-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIO.cs
More file actions
98 lines (85 loc) · 2.86 KB
/
IO.cs
File metadata and controls
98 lines (85 loc) · 2.86 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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Battleship
{
internal abstract class IO
{
public static void DisplayColored(string msg, ConsoleColor fg, ConsoleColor bg = ConsoleColor.Black, bool inline = false)
{
Console.ForegroundColor = fg;
Console.BackgroundColor = bg;
if (inline) Console.Write(msg); else Console.WriteLine(msg);
Console.ResetColor();
}
public static string ReadLineColored(ConsoleColor fg, ConsoleColor bg = ConsoleColor.Black) {
Console.ForegroundColor = fg;
Console.BackgroundColor = bg;
string input = Console.ReadLine();
Console.ResetColor();
return input;
}
public static void DisplayTitle(string[] title) {
Console.ForegroundColor = ConsoleColor.Cyan;
foreach (string line in title) {
Console.WriteLine(line);
}
Console.ResetColor();
}
public static void DisplaySuccess(string msg, bool inline = false)
{
IO.DisplayColored(msg, ConsoleColor.Green, ConsoleColor.Black, inline);
}
public static void DisplayWarning(string msg, bool inline = false)
{
IO.DisplayColored(msg, ConsoleColor.Yellow, ConsoleColor.Black, inline);
}
public static void DisplayError(string msg, bool inline = false)
{
IO.DisplayColored(msg, ConsoleColor.Red, ConsoleColor.Black, inline);
}
public static bool PromptForBool() {
int i = 0;
while (true) {
if (i > 0) {
IO.DisplayError("Wprowadzono złą wartość. Wyperz ponownie: (T / N)", true);
}
i++;
switch (Console.ReadKey().KeyChar) {
case 'T':
case 't':
return true;
case 'N':
case 'n':
return false;
}
};
}
public static Direction PromptForDirection()
{
int i = 0;
do
{
if (i > 0)
{
Console.Write("\nPodano błędną wartość. Podaj kierunek statku (H / V): ");
} else
{
Console.Write("Podaj kierunek statku (H / V): ");
}
switch (Console.ReadKey().KeyChar)
{
case 'H':
case 'h':
return Direction.Horizontal;
case 'V':
case 'v':
return Direction.Vertical;
}
i++;
} while (true);
}
}
}