-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUI.cs
105 lines (90 loc) · 2.96 KB
/
UI.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
using System;
using System.Collections.Generic;
using System.Text;
namespace Sudoku
{
class UI
{
static public void ShowMsg(string message)
{
Console.WriteLine("");
Console.WriteLine(message);
Console.WriteLine("");
}
static public void ShowHorizontalDivider()
{
Console.WriteLine("-------------------------------------------------------------------------------");
}
static public void NewLineWithTab()
{
Console.WriteLine($"");
Console.Write($"\t");
}
static public void NewLine()
{
Console.WriteLine($"");
}
static public int ShowMainMenu()
{
Console.WriteLine("==========================SUDOKU=================================");
Console.WriteLine("Select from main options below:");
Console.WriteLine();
Console.WriteLine("1. Read unsolved sudoku from a file, Solve and Classify");
Console.WriteLine("2. Solve Sudoku");
Console.WriteLine("3. Create a new unsolved sudoku and save it to file");
Console.WriteLine("4. Exit");
Console.WriteLine("===============================================================");
var result = Console.ReadLine();
if (string.IsNullOrWhiteSpace(result) || result.Length != 1)
{
return 0;
}
try
{
return Convert.ToInt32(result);
}
catch
{
return 0;
}
}
static public string GetFilenameFromUser(string msg)
{
string result;
do
{
ShowMsg(msg);
result = Console.ReadLine();
} while (!(result.Length >= 5 && result.EndsWith(".txt")));
return result;
}
static public bool UserPromt()
{
string result;
do
{
ShowMsg("Do you want to save the result to a file? Yes or No");
result = Console.ReadLine().ToLower();
} while (result != "yes" && result!="no" && result != "y" && result != "n");
if (result == "y" || result == "yes")
{
return true;
}
return false;
}
internal static void ShowValidSudokuFormat()
{
Console.WriteLine("");
Console.WriteLine("51.....83");
Console.WriteLine("8..416..5");
Console.WriteLine(".........");
Console.WriteLine(".985.461.");
Console.WriteLine("...9.1...");
Console.WriteLine(".642.357.");
Console.WriteLine(".........");
Console.WriteLine("6..157..4");
Console.WriteLine("78.....96");
Console.WriteLine("");
}
}
}