Compare commits
1
Commits
27747a3b96
...
Main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa52afa62c
|
+62
-28
@@ -16,14 +16,21 @@ class PI114
|
|||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Console.WriteLine("┌───────────────────────────────────────────────┐");
|
bool convertAgain = true;
|
||||||
Console.WriteLine("\n cc");
|
while (convertAgain)
|
||||||
Console.WriteLine("└───────────────────────────────────────────────┘");
|
{
|
||||||
IDictionary<string, string> specialcharacterDictionnary = programeDictionnary();
|
Console.Title = "Convertisseur T2M";
|
||||||
IDictionary<string, string> letterToMorse = programmeLetterToMorseCode();
|
Console.WriteLine("\t\t\t\t┌───────────────────────────────────────────────┐");
|
||||||
string[] userTextArray = askUserSentence();
|
Console.WriteLine("\t\t\t\t\tConvertisseur de texte en Morse");
|
||||||
verifyUserSentence(userTextArray, specialcharacterDictionnary);
|
Console.WriteLine("\t\t\t\t└───────────────────────────────────────────────┘");
|
||||||
translateUserSentenceToMorse(userTextArray, letterToMorse);
|
IDictionary<string, string> specialcharacterDictionnary = programeDictionnary();
|
||||||
|
IDictionary<string, string> letterToMorse = programmeLetterToMorseCode();
|
||||||
|
string[] userTextArray = askUserSentence();
|
||||||
|
verifyUserSentence(userTextArray, specialcharacterDictionnary);
|
||||||
|
string translatedText = translateUserSentenceToMorse(userTextArray, letterToMorse);
|
||||||
|
showResultInConsole(translatedText, ref convertAgain);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static IDictionary<string, string> programeDictionnary(){
|
static IDictionary<string, string> programeDictionnary(){
|
||||||
@@ -95,15 +102,20 @@ class PI114
|
|||||||
}
|
}
|
||||||
static string[] askUserSentence()
|
static string[] askUserSentence()
|
||||||
{
|
{
|
||||||
Console.Write("Entrez votre phrase à déchiffrer : ");
|
Console.Write("Entrez votre phrase à déchiffrer (Sans accents, A-Z 0-9): ");
|
||||||
string userText = Console.ReadLine();
|
string userText = Console.ReadLine();
|
||||||
|
while(userText.Length == 0)
|
||||||
|
{
|
||||||
|
Console.Write("[Erreur] ─ Veuillez entrer un texte (Sans accents, A-Z 0-9): ");
|
||||||
|
userText = Console.ReadLine();
|
||||||
|
}
|
||||||
string[] userTextArray = userTextToAnArray(userText);
|
string[] userTextArray = userTextToAnArray(userText);
|
||||||
return userTextArray;
|
return userTextArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
static string[] userTextToAnArray(string userText)
|
static string[] userTextToAnArray(string userText)
|
||||||
{
|
{
|
||||||
string[] userTextArray = userText.Select(x => x.ToString()).ToArray();
|
string[] userTextArray = userText.Select(x => x.ToString().ToLower()).ToArray();
|
||||||
Console.WriteLine(string.Join("", userTextArray));
|
Console.WriteLine(string.Join("", userTextArray));
|
||||||
return userTextArray;
|
return userTextArray;
|
||||||
}
|
}
|
||||||
@@ -140,34 +152,56 @@ class PI114
|
|||||||
}
|
}
|
||||||
return userTextArray;
|
return userTextArray;
|
||||||
}
|
}
|
||||||
static void translateUserSentenceToMorse(string[] userTextArray, IDictionary<string, string> letterToMorse)
|
static string translateUserSentenceToMorse(string[] userTextArray, IDictionary<string, string> letterToMorse)
|
||||||
{
|
{
|
||||||
Console.WriteLine(string.Join(" ", userTextArray));
|
Console.WriteLine(string.Join(" ", userTextArray));
|
||||||
|
string translatedText = null;
|
||||||
foreach (string k in userTextArray)
|
foreach (string k in userTextArray)
|
||||||
{
|
{
|
||||||
foreach(KeyValuePair<string, string> v in letterToMorse)
|
foreach(KeyValuePair<string, string> v in letterToMorse)
|
||||||
{
|
{
|
||||||
if (k == v.Key)
|
if (k == v.Key)
|
||||||
{
|
{
|
||||||
if (v.Value.Contains("."))
|
translatedText += v.Value;
|
||||||
{
|
|
||||||
var resultCount = v.Value.Count(x => x.ToString() == ".");
|
|
||||||
for (int i = 0 ; i < resultCount; i++)
|
|
||||||
{
|
|
||||||
Console.Beep(1000, 100);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (v.Value.Contains("-"))
|
|
||||||
{
|
|
||||||
var resultCount = v.Value.Count(x => x.ToString() == "-");
|
|
||||||
for (int i = 0 ; i < resultCount; i++)
|
|
||||||
{
|
|
||||||
Console.Beep(1000, 400);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Console.Write(v.Value + " ");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return translatedText;
|
||||||
|
}
|
||||||
|
static bool showResultInConsole(string translatedText, ref bool convertAgain)
|
||||||
|
{
|
||||||
|
string[] translatedTextArray = translatedText.Select(x => x.ToString()).ToArray();
|
||||||
|
foreach (string v in translatedTextArray)
|
||||||
|
{
|
||||||
|
if (v.Equals("."))
|
||||||
|
{
|
||||||
|
Console.Write(v);
|
||||||
|
Console.Beep(1000, 100);
|
||||||
|
}
|
||||||
|
else if (v.Equals("-"))
|
||||||
|
{
|
||||||
|
Console.Write(v);
|
||||||
|
Console.Beep(1000, 400);
|
||||||
|
}
|
||||||
|
else if (v.Equals("/")){
|
||||||
|
Console.Write(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("");
|
||||||
|
Console.Write("Voulez vous refaire une conversion ? (O/N) : ");
|
||||||
|
string wannaDoItAgain = Console.ReadLine();
|
||||||
|
wannaDoItAgain = wannaDoItAgain.ToLower();
|
||||||
|
if (wannaDoItAgain == "o")
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
return convertAgain = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
Console.WriteLine("Merci aurevoir !!");
|
||||||
|
return convertAgain = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user