-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
161 lines (143 loc) · 5.25 KB
/
Copy pathProgram.cs
File metadata and controls
161 lines (143 loc) · 5.25 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
using System.Data;
using MySql.Data.MySqlClient;
namespace word_picker
{
internal class Program
{
static void Main()
{
while (true)
{
var foundWords = SearchWords();
Console.WriteLine();
for (int i = 0; i < foundWords.Count; i++)
{
Console.WriteLine(foundWords[i]);
}
Console.WriteLine("\n\n\n-----------------------------------------\n\n\n");
Console.ReadKey();
}
}
static private List<string> SearchWords()
{
Word word = GetInformation();
List<string> words = CreateWordArray(word.length);
for (int i = 0; i < words.Count; i++)
{
foreach (var apcentLetter in word.apsentLetters)
{
if (words[i].Contains(apcentLetter))
{
words.RemoveAt(i);
i--;
break;
}
}
}
for (int i = 0; i < words.Count; i++)
{
foreach (var presentLetter in word.presentLetters)
{
if (!words[i].Contains(presentLetter))
{
words.RemoveAt(i);
i--;
break;
}
}
}
if (word.lettersOrder.Count != 0)
{
for (int i = 0; i < words.Count; i++)
{
for (int j = 0; j < word.lettersOrder.Count; j++)
{
if (words[i][j] != word.lettersOrder[j])
{
words.RemoveAt(i);
i--;
}
}
}
}
return words;
}
static private List<string> CreateWordArray(int length)
{
DB DataBase = new DB();
DataTable table = new DataTable();
MySqlCommand command = new MySqlCommand("SELECT word FROM nouns WHERE char_length(word) = @length", DataBase.GetConnection());
command.Parameters.Add("@length", MySqlDbType.Int32, 12).Value = length;
MySqlDataAdapter adapter = new MySqlDataAdapter(command);
adapter.Fill(table);
DataBase.OpenConnection();
DataBase.CloseConnection();
DataRow[] rows = table.Select();
List<string> words = new List<string>(rows.Length - 1);
for (int i = 0; i < rows.Length; i++)
{
words.Add(rows[i].ItemArray[0].ToString());
}
return words;
}
static private Dictionary<int, char> RequestLettersOrder(int wordLength, string description)
{
var lettersOrder = new Dictionary<int, char>();
string String;
Console.WriteLine(description);
for (int i = 0; i < wordLength; i++)
{
Console.Write(i + 1 + " - ");
String = Console.ReadLine();
if (!string.IsNullOrEmpty(String))
{
if (char.IsLetter(String[0]))
{
lettersOrder.Add(i, String[0]);
}
else
{
RequestLettersOrder(wordLength, description);
}
}
}
return lettersOrder;
}
static private string RequestLetters(string description)
{
Console.Write(description);
return Console.ReadLine().ToLower();
}
static private int RequestNumber(string descripton)
{
Console.Write(descripton);
int result;
if (int.TryParse(Console.ReadLine(), out result))
{
return result;
}
else
{
Console.WriteLine("\nВведите корректное значение");
return RequestNumber(descripton);
}
}
static private void WriteChars(List<char> array, string sourse)
{
foreach (var item in sourse)
{
array.Add(item);
}
}
static private Word GetInformation()
{
var word = new Word();
Console.WriteLine("Это подбиратель слов!\n\nВведите буквы(без пробелов и запятых) которые");
WriteChars(word.apsentLetters, RequestLetters("Отсутствуют в слове(серые): "));
WriteChars(word.presentLetters, RequestLetters("\nЕсть в слове, но неизвестно где(белые): "));
word.length = RequestNumber("\nВведите длину слова: ");
word.lettersOrder = RequestLettersOrder(word.length, "\nНиже нужно записать буквы, которые стоят в слове в определённом месте(желтые)\n");
return word;
}
}
}