Compare commits
3
Commits
aa35d4a0f9
...
Main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa52afa62c
|
||
|
|
27747a3b96
|
||
|
|
07afbb1486
|
+103
-38
@@ -9,19 +9,31 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Threading.Tasks.Dataflow;
|
using System.Threading.Tasks.Dataflow;
|
||||||
|
|
||||||
class PI114
|
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("└───────────────────────────────────────────────┘");
|
{
|
||||||
programeDictionnary();
|
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 void programeDictionnary(){
|
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");
|
||||||
@@ -45,13 +57,7 @@ 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)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Key: {ele.Key}, Value: {ele.Value}");
|
|
||||||
}
|
|
||||||
IDictionary<string, string> letterToMorse = programmeLetterToMorseCode();
|
|
||||||
askUserSentence(letterToMorse);
|
|
||||||
}
|
}
|
||||||
public static IDictionary<string,string> programmeLetterToMorseCode()
|
public static IDictionary<string,string> programmeLetterToMorseCode()
|
||||||
{
|
{
|
||||||
@@ -94,49 +100,108 @@ class PI114
|
|||||||
letterToMorse.Add(" ", "/");
|
letterToMorse.Add(" ", "/");
|
||||||
return letterToMorse;
|
return letterToMorse;
|
||||||
}
|
}
|
||||||
static void askUserSentence(IDictionary<string, string> letterToMorse)
|
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();
|
||||||
Console.WriteLine();
|
while(userText.Length == 0)
|
||||||
Console.WriteLine(userText);
|
{
|
||||||
userTextToAnArray(userText, letterToMorse);
|
Console.Write("[Erreur] ─ Veuillez entrer un texte (Sans accents, A-Z 0-9): ");
|
||||||
|
userText = Console.ReadLine();
|
||||||
|
}
|
||||||
|
string[] userTextArray = userTextToAnArray(userText);
|
||||||
|
return userTextArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void userTextToAnArray(string userText, IDictionary<string, string> letterToMorse)
|
static string[] userTextToAnArray(string userText)
|
||||||
{
|
{
|
||||||
string[] userTextArray = userText.Select(x => x.ToString()).ToArray();
|
string[] userTextArray = userText.Select(x => x.ToString().ToLower()).ToArray();
|
||||||
translateUserSentenceToMorse(userTextArray, letterToMorse);
|
Console.WriteLine(string.Join("", userTextArray));
|
||||||
|
return userTextArray;
|
||||||
}
|
}
|
||||||
static void translateUserSentenceToMorse(string[] userTextArray, IDictionary<string, string> letterToMorse)
|
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));
|
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, 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 + " ");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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