diff --git a/Program.cs b/Program.cs index c8d148a..81ce083 100644 --- a/Program.cs +++ b/Program.cs @@ -9,6 +9,7 @@ using System; using System.Linq; +using System.Threading.Tasks.Dataflow; class PI114 { @@ -49,9 +50,10 @@ class PI114 { Console.WriteLine($"Key: {ele.Key}, Value: {ele.Value}"); } - askUserSentence(); + IDictionary letterToMorse = programmeLetterToMorseCode(); + askUserSentence(letterToMorse); } - static void programmeLetterToMorseCode() + public static IDictionary programmeLetterToMorseCode() { Dictionary letterToMorse = new Dictionary(); letterToMorse.Add("a", ".-"); @@ -90,19 +92,51 @@ class PI114 letterToMorse.Add("8", "---.."); letterToMorse.Add("9", "----."); letterToMorse.Add(" ", "/"); + return letterToMorse; } - static void askUserSentence() + static void askUserSentence(IDictionary letterToMorse) { Console.Write("Entrez votre phrase à déchiffrer : "); string userText = Console.ReadLine(); Console.WriteLine(); Console.WriteLine(userText); - userTextToAnArray(userText); + userTextToAnArray(userText, letterToMorse); } - static void userTextToAnArray(string userText) + static void userTextToAnArray(string userText, IDictionary letterToMorse) { string[] userTextArray = userText.Select(x => x.ToString()).ToArray(); + translateUserSentenceToMorse(userTextArray, letterToMorse); + } + static void translateUserSentenceToMorse(string[] userTextArray, IDictionary letterToMorse) + { + Console.WriteLine(string.Join(" ", userTextArray)); + foreach (string k in userTextArray) + { + foreach(KeyValuePair v in letterToMorse) + { + if (k == v.Key) + { + if (v.Value.Contains(".")) + { + var resultCount = v.Value.Count(x => x.ToString() == "."); + for (int i = 0 ; i < resultCount; i++) + { + Console.Beep(1000, 200); + } + } + else if (v.Value.Contains("-")) + { + var resultCount = v.Value.Count(x => x.ToString() == "-"); + for (int i = 0 ; i < resultCount; i++) + { + Console.Beep(1000, 200); + } + } + Console.Write(v.Value + " "); + } + } + } } } \ No newline at end of file