Compare commits

...
2 Commits
Author SHA1 Message Date
nocode aa35d4a0f9 feat(morse): implement morse code translation with audio output
Refactor morse code generation to return a dictionary for reuse across methods. Add translateUserSentenceToMorse method that converts user input to morse code and plays audio beeps based on dots and dashes. Pass letterToMorse dictionary through the call chain (askUserSentence -> userTextToAnArray -> translateUserSentenceToMorse) to enable translation functionality.

Changes:
- Make programmeLetterToMorseCode public and return IDictionary
- Add morse code translation method with beep audio feedback
- Update method signatures to accept morse code dictionary
2026-09-07 09:32:28 +02:00
nocode f53c47684a feat: add method to convert user text into character array
Add new userTextToAnArray method that converts a string into an array of individual characters using LINQ Select and ToArray. This allows for character-level processing of user input.

Also add System.Linq using statement to support LINQ operations.
2026-09-07 08:46:42 +02:00
+45 -3
View File
@@ -8,6 +8,8 @@
/// └─────────────────────────────────────────────────────────────────────────────────────────┘
using System;
using System.Linq;
using System.Threading.Tasks.Dataflow;
class PI114
{
@@ -48,9 +50,10 @@ class PI114
{
Console.WriteLine($"Key: {ele.Key}, Value: {ele.Value}");
}
askUserSentence();
IDictionary<string, string> letterToMorse = programmeLetterToMorseCode();
askUserSentence(letterToMorse);
}
static void programmeLetterToMorseCode()
public static IDictionary<string,string> programmeLetterToMorseCode()
{
Dictionary<string, string> letterToMorse = new Dictionary<string, string>();
letterToMorse.Add("a", ".-");
@@ -89,12 +92,51 @@ class PI114
letterToMorse.Add("8", "---..");
letterToMorse.Add("9", "----.");
letterToMorse.Add(" ", "/");
return letterToMorse;
}
static void askUserSentence()
static void askUserSentence(IDictionary<string, string> letterToMorse)
{
Console.Write("Entrez votre phrase à déchiffrer : ");
string userText = Console.ReadLine();
Console.WriteLine();
Console.WriteLine(userText);
userTextToAnArray(userText, letterToMorse);
}
static void userTextToAnArray(string userText, IDictionary<string, string> letterToMorse)
{
string[] userTextArray = userText.Select(x => x.ToString()).ToArray();
translateUserSentenceToMorse(userTextArray, letterToMorse);
}
static void translateUserSentenceToMorse(string[] userTextArray, IDictionary<string, string> letterToMorse)
{
Console.WriteLine(string.Join(" ", userTextArray));
foreach (string k in userTextArray)
{
foreach(KeyValuePair<string, string> 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 + " ");
}
}
}
}
}