Program.cs
· 1.4 KiB · C#
Sin formato
public class Program
{
public static void Main()
{
var script = new Scriptures();
var verse = script.GetRandomVerseWithHiddenWords();
Console.WriteLine(verse);
}
}
public class Scriptures
{
private string[] scripture = new string[]
{
"Mosiah 2:17: And behold, I tell you these things that ye may learn wisdom; that ye may learn that when ye are in the service of your fellow beings ye are only in the service of your God.",
"1 Nephi 3:7: And it came to pass that I, Nephi said unto my father: I will go and do the things which the Lord hath commanded..."
};
string[] separators = new string[] { " " };
private string GetRandomScripture()
{
var rand = new Random();
int index = rand.Next(scripture.Length);
return scripture[index];
}
public string GetRandomVerseWithHiddenWords()
{
var selectedScipture = GetRandomScripture();
string[] outPutverse = new string[selectedScipture.Length];
var splitVerse = selectedScipture.Split(separators, StringSplitOptions.None);
foreach (var item in splitVerse.Select((value, index) => new { index, value }))
{
var rand = new Random();
var tempValue = rand.Next(0, 20);
if (tempValue % 4 == 0)
{
var hiddenWord = new string('_', item.value.Length);
outPutverse[item.index] = hiddenWord + " ";
}
else
{
outPutverse[item.index] = item.value + " ";
}
}
return string.Concat(outPutverse);
}
}
1 | public class Program |
2 | { |
3 | public static void Main() |
4 | { |
5 | var script = new Scriptures(); |
6 | var verse = script.GetRandomVerseWithHiddenWords(); |
7 | Console.WriteLine(verse); |
8 | } |
9 | } |
10 | |
11 | public class Scriptures |
12 | { |
13 | private string[] scripture = new string[] |
14 | { |
15 | "Mosiah 2:17: And behold, I tell you these things that ye may learn wisdom; that ye may learn that when ye are in the service of your fellow beings ye are only in the service of your God.", |
16 | "1 Nephi 3:7: And it came to pass that I, Nephi said unto my father: I will go and do the things which the Lord hath commanded..." |
17 | }; |
18 | string[] separators = new string[] { " " }; |
19 | |
20 | private string GetRandomScripture() |
21 | { |
22 | var rand = new Random(); |
23 | int index = rand.Next(scripture.Length); |
24 | return scripture[index]; |
25 | } |
26 | |
27 | public string GetRandomVerseWithHiddenWords() |
28 | { |
29 | var selectedScipture = GetRandomScripture(); |
30 | string[] outPutverse = new string[selectedScipture.Length]; |
31 | var splitVerse = selectedScipture.Split(separators, StringSplitOptions.None); |
32 | |
33 | foreach (var item in splitVerse.Select((value, index) => new { index, value })) |
34 | { |
35 | var rand = new Random(); |
36 | var tempValue = rand.Next(0, 20); |
37 | if (tempValue % 4 == 0) |
38 | { |
39 | var hiddenWord = new string('_', item.value.Length); |
40 | outPutverse[item.index] = hiddenWord + " "; |
41 | } |
42 | else |
43 | { |
44 | outPutverse[item.index] = item.value + " "; |
45 | } |
46 | } |
47 | |
48 | return string.Concat(outPutverse); |
49 | } |
50 | } |