Compare commits
7
Commits
f3c5bf70b9
...
Main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa52afa62c
|
||
|
|
27747a3b96
|
||
|
|
07afbb1486
|
||
|
|
aa35d4a0f9
|
||
|
|
f53c47684a
|
||
|
|
ddb515f3e5
|
||
|
|
489ba98991
|
+166
-4
@@ -8,12 +8,33 @@
|
|||||||
/// └─────────────────────────────────────────────────────────────────────────────────────────┘
|
/// └─────────────────────────────────────────────────────────────────────────────────────────┘
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Threading.Tasks.Dataflow;
|
||||||
|
|
||||||
class PI114
|
class PI114
|
||||||
{
|
{
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
bool convertAgain = true;
|
||||||
|
while (convertAgain)
|
||||||
|
{
|
||||||
|
Console.Title = "Convertisseur T2M";
|
||||||
|
Console.WriteLine("\t\t\t\t┌───────────────────────────────────────────────┐");
|
||||||
|
Console.WriteLine("\t\t\t\t\tConvertisseur de texte en Morse");
|
||||||
|
Console.WriteLine("\t\t\t\t└───────────────────────────────────────────────┘");
|
||||||
|
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(){
|
||||||
|
|
||||||
Dictionary<string,string> specialCharacterDictionnary = new Dictionary<string, string>();
|
Dictionary<string,string> specialCharacterDictionnary = new Dictionary<string, string>();
|
||||||
specialCharacterDictionnary.Add("é","e");
|
specialCharacterDictionnary.Add("é","e");
|
||||||
specialCharacterDictionnary.Add("è","e");
|
specialCharacterDictionnary.Add("è","e");
|
||||||
@@ -36,10 +57,151 @@ class PI114
|
|||||||
specialCharacterDictionnary.Add("â","a");
|
specialCharacterDictionnary.Add("â","a");
|
||||||
specialCharacterDictionnary.Add("ä","a");
|
specialCharacterDictionnary.Add("ä","a");
|
||||||
specialCharacterDictionnary.Add("ç","c");
|
specialCharacterDictionnary.Add("ç","c");
|
||||||
|
return specialCharacterDictionnary;
|
||||||
foreach (var ele in specialCharacterDictionnary)
|
}
|
||||||
|
public static IDictionary<string,string> programmeLetterToMorseCode()
|
||||||
|
{
|
||||||
|
Dictionary<string, string> letterToMorse = new Dictionary<string, string>();
|
||||||
|
letterToMorse.Add("a", ".-");
|
||||||
|
letterToMorse.Add("b", "-...");
|
||||||
|
letterToMorse.Add("c", "-.-.");
|
||||||
|
letterToMorse.Add("d", "-..");
|
||||||
|
letterToMorse.Add("e", ".");
|
||||||
|
letterToMorse.Add("f", "..-.");
|
||||||
|
letterToMorse.Add("g", "--.");
|
||||||
|
letterToMorse.Add("h", "....");
|
||||||
|
letterToMorse.Add("i", "..");
|
||||||
|
letterToMorse.Add("j", ".---");
|
||||||
|
letterToMorse.Add("k", "-.-");
|
||||||
|
letterToMorse.Add("l", ".-..");
|
||||||
|
letterToMorse.Add("m", "--");
|
||||||
|
letterToMorse.Add("n", "-.");
|
||||||
|
letterToMorse.Add("o", "---");
|
||||||
|
letterToMorse.Add("p", ".--.");
|
||||||
|
letterToMorse.Add("q", "--.-");
|
||||||
|
letterToMorse.Add("r", ".-.");
|
||||||
|
letterToMorse.Add("s", "...");
|
||||||
|
letterToMorse.Add("t", "-");
|
||||||
|
letterToMorse.Add("u", "..-");
|
||||||
|
letterToMorse.Add("v", "...-");
|
||||||
|
letterToMorse.Add("w", ".--");
|
||||||
|
letterToMorse.Add("x", "-..-");
|
||||||
|
letterToMorse.Add("y", "-.--");
|
||||||
|
letterToMorse.Add("z", "--..");
|
||||||
|
letterToMorse.Add("1", "-----");
|
||||||
|
letterToMorse.Add("2", ".----");
|
||||||
|
letterToMorse.Add("3", "..---");
|
||||||
|
letterToMorse.Add("4", "...--");
|
||||||
|
letterToMorse.Add("5", "....-");
|
||||||
|
letterToMorse.Add("6", "-....");
|
||||||
|
letterToMorse.Add("7", "--...");
|
||||||
|
letterToMorse.Add("8", "---..");
|
||||||
|
letterToMorse.Add("9", "----.");
|
||||||
|
letterToMorse.Add(" ", "/");
|
||||||
|
return letterToMorse;
|
||||||
|
}
|
||||||
|
static string[] askUserSentence()
|
||||||
|
{
|
||||||
|
Console.Write("Entrez votre phrase à déchiffrer (Sans accents, A-Z 0-9): ");
|
||||||
|
string userText = Console.ReadLine();
|
||||||
|
while(userText.Length == 0)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Key: {ele.Key}, Value: {ele.Value}");
|
Console.Write("[Erreur] ─ Veuillez entrer un texte (Sans accents, A-Z 0-9): ");
|
||||||
|
userText = Console.ReadLine();
|
||||||
|
}
|
||||||
|
string[] userTextArray = userTextToAnArray(userText);
|
||||||
|
return userTextArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
static string[] userTextToAnArray(string userText)
|
||||||
|
{
|
||||||
|
string[] userTextArray = userText.Select(x => x.ToString().ToLower()).ToArray();
|
||||||
|
Console.WriteLine(string.Join("", userTextArray));
|
||||||
|
return userTextArray;
|
||||||
|
}
|
||||||
|
static string[] verifyUserSentence(string[] userTextArray, IDictionary<string, string> specialcharacterDictionnary)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
foreach( KeyValuePair<string, string> v in specialcharacterDictionnary)
|
||||||
|
{
|
||||||
|
foreach( string k in userTextArray )
|
||||||
|
{
|
||||||
|
if (v.Key.Equals(k))
|
||||||
|
{
|
||||||
|
userTextArray[i] = v.Value;
|
||||||
|
Console.WriteLine("Character : {0} Modifié en {1}", k, userTextArray[i]);
|
||||||
|
}
|
||||||
|
// else if ()
|
||||||
|
// {
|
||||||
|
|
||||||
|
// } à faire character accepté
|
||||||
|
|
||||||
|
// else if (!v.Key.Contains(k))
|
||||||
|
// {
|
||||||
|
// while (!v.Key.Contains(k))
|
||||||
|
// {
|
||||||
|
// Console.WriteLine("Veuillez entrer votre phrase sans charactère spéciale");
|
||||||
|
// string newText = Console.ReadLine();
|
||||||
|
// userTextArray = userTextToAnArray(newText);
|
||||||
|
// }
|
||||||
|
// continue;
|
||||||
|
// } à mettre en else
|
||||||
|
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return userTextArray;
|
||||||
|
}
|
||||||
|
static string translateUserSentenceToMorse(string[] userTextArray, IDictionary<string, string> letterToMorse)
|
||||||
|
{
|
||||||
|
Console.WriteLine(string.Join(" ", userTextArray));
|
||||||
|
string translatedText = null;
|
||||||
|
foreach (string k in userTextArray)
|
||||||
|
{
|
||||||
|
foreach(KeyValuePair<string, string> v in letterToMorse)
|
||||||
|
{
|
||||||
|
if (k == v.Key)
|
||||||
|
{
|
||||||
|
translatedText += 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