Program.cs
· 1.5 KiB · C#
Raw
public class Program
{
public static void Main()
{
var script = new Scriptures();
var verse = script.GetRandomVerseWithHiddenWords();
Console.WriteLine(verse);
// Example Output
// 1 Nephi 3:7: ___ it came __ ____ that I, Nephi said ____ __ father: I ____ go and do the things _____ the Lord hath commanded...
}
}
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 | // Example Output |
9 | // 1 Nephi 3:7: ___ it came __ ____ that I, Nephi said ____ __ father: I ____ go and do the things _____ the Lord hath commanded... |
10 | } |
11 | } |
12 | |
13 | public class Scriptures |
14 | { |
15 | private string[] scripture = new string[] |
16 | { |
17 | "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.", |
18 | "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..." |
19 | }; |
20 | string[] separators = new string[] { " " }; |
21 | |
22 | private string GetRandomScripture() |
23 | { |
24 | var rand = new Random(); |
25 | int index = rand.Next(scripture.Length); |
26 | return scripture[index]; |
27 | } |
28 | |
29 | public string GetRandomVerseWithHiddenWords() |
30 | { |
31 | var selectedScipture = GetRandomScripture(); |
32 | string[] outPutverse = new string[selectedScipture.Length]; |
33 | var splitVerse = selectedScipture.Split(separators, StringSplitOptions.None); |
34 | |
35 | foreach (var item in splitVerse.Select((value, index) => new { index, value })) |
36 | { |
37 | var rand = new Random(); |
38 | var tempValue = rand.Next(0, 20); |
39 | if (tempValue % 4 == 0) |
40 | { |
41 | var hiddenWord = new string('_', item.value.Length); |
42 | outPutverse[item.index] = hiddenWord + " "; |
43 | } |
44 | else |
45 | { |
46 | outPutverse[item.index] = item.value + " "; |
47 | } |
48 | } |
49 | |
50 | return string.Concat(outPutverse); |
51 | } |
52 | } |