Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.65 KB | None | 0 0
  1. /* Polecenie - typ interfejsowy */
  2.  
  3. public interface ICommand {
  4.     void Execute();
  5.     void Unexecute();
  6. }
  7.  
  8.  
  9. /* Menu - obiekt wywolujacy */
  10.  
  11. class Menu {
  12.     private Command command;
  13.     public void SetCommand (Command _command) { command = _command; }
  14.     public void ExecuteCommand() { command.execute(); }
  15.     public void UnexecuteCommand() { command.unexecute(); }
  16. }
  17.  
  18.  
  19. /* WordCreator - odbiorca polecenia */
  20.  
  21. class WordCreator {
  22.     private string language;
  23.     private string polish;
  24.     private string foreign;
  25.     private Word newWord;
  26.     public WordCreator () {
  27.         language = "";
  28.         polish = "";
  29.         foreign = "";
  30.     }
  31.     public WordCreator (string _language) {
  32.         language = _language;
  33.         polish = "";
  34.         foreign = "";
  35.     }
  36.     public WordCreator (string _language, string _polish) {
  37.         language = _language;
  38.         polish = _polish;
  39.         foreign = "";
  40.     }
  41.     public WordCreator (string _language, string _polish, string _foreign) {
  42.         language = _language;
  43.         polish = _polish;
  44.         foreign = _foreign;
  45.     }
  46.    
  47.     public void SetWordLanguage () {
  48.         bool correctKey = false;
  49.         do {
  50.             Console.Clear();
  51.             Console.WriteLine("Wybierz język dodawanego słowa:");
  52.             Console.WriteLine("(A)ngielski");
  53.             Console.Write("(N)iemiecki");
  54.             ConsoleKeyInfo pressedKey = Console.ReadKey();
  55.             switch (pressedKey.Key) {
  56.                 case ConsoleKey.A:
  57.                     language = "english";
  58.                     correctKey = true;
  59.                     break;
  60.                 case ConsoleKey.N:
  61.                     language = "german";
  62.                     correctKey = true;
  63.                     break;
  64.                 default:
  65.                     break;
  66.             }
  67.         } while (!correctKey);
  68.     }
  69.    
  70.     public void UnsetWordLanguage () {
  71.         language = "";
  72.         SetWordLanguage();
  73.     }
  74.    
  75.     public void SetPolishTranslation () {
  76.         bool correctTranslation = false;
  77.         do {
  78.             Console.Clear();
  79.             Console.Write("Podaj polskie tłumaczenie dodawanego słowa: ");
  80.             string _polish = Console.ReadLine();
  81.             bool translationFound = false;
  82.             if (_polish.Length > 2) {
  83.                 if (language == "english") {
  84.                     foreach (Word word in dictionary.GetEnglishWords()) {
  85.                         if (word.GetPolish() == _polish)
  86.                             translationFound = true;
  87.                     }
  88.                 }
  89.                 else if (language == "german") {
  90.                     foreach (Word word in dictionary.GetGermanWords()) {
  91.                         if (word.GetPolish() == _polish)
  92.                             translationFound = true;
  93.                     }
  94.                 }
  95.                 if (!translationFound) {
  96.                     polish = _polish;
  97.                     correctTranslation = true;
  98.                 }
  99.             }
  100.         } while (!correctTranslation);
  101.     }
  102.    
  103.     public void UnsetPolishTranslation () {
  104.         polish = "";
  105.         SetPolishTranslation();
  106.     }
  107.    
  108.     public void SetForeignTranslation () {
  109.         bool correctTranslation = false;
  110.         do {
  111.             Console.Clear();
  112.             if (language == "english")
  113.                 Console.Write("Podaj angielskie tłumaczenie dodawanego słowa: ");
  114.             if (language == "german")
  115.                 Console.Write("Podaj niemieckie tłumaczenie dodawanego słowa: ");
  116.             string _foreign = Console.ReadLine();
  117.             bool translationFound = false;
  118.             if (_foreign.Length > 2) {
  119.                 if (language == "english") {
  120.                     foreach (Word word in dictionary.GetEnglishWords()) {
  121.                         if (word.GetForeign() == _foreign)
  122.                             translationFound = true;
  123.                     }
  124.                 }
  125.                 else if (language == "german") {
  126.                     foreach (Word word in dictionary.GetGermanWords()) {
  127.                         if (word.GetForeign() == _foreign)
  128.                             translationFound = true;
  129.                     }
  130.                 }
  131.                 if (!translationFound) {
  132.                     foreign = _foreign;
  133.                     correctTranslation = true;
  134.                 }
  135.             }
  136.         } while (!correctTranslation);
  137.     }
  138.    
  139.     public void UnsetForeignTranslation () {
  140.         foreign = "";
  141.         SetForeignTranslation();
  142.     }
  143.    
  144.     public void Finalization () {
  145.         if (language == "english") {
  146.             newWord = new EnglishWord(polish,english,"");
  147.             dictionary.GetEnglishWords().Add(newWord);
  148.             // dopisać do pliku
  149.         }
  150.         else if (language == "german") {
  151.             newWord = new GermanWord(polish,english,"");
  152.             dictionary.GetGermanWords().Add(newWord);
  153.             // dopisać do pliku
  154.         }
  155.         Console.Clear();
  156.         Console.WriteLine(new StringBuilder().append("Nowe słowo: ").append(polish).append(" - ").append(foreign).toString());
  157.         Console.Write("Wciśnij dowolny klawisz, aby kontynuować. ");
  158.         Console.ReadKey();
  159.         AdministratorPanel(justLogged);
  160.     }
  161. }
  162.  
  163. /* Polecenie dla ustawienia języka */
  164.  
  165. public class LanguageCommand : ICommand {
  166.     private WordCreator creator; //obiekt wykonujacy
  167.     public LanguageCommand () { creator = new WordCreator(); }
  168.     public LanguageCommand (WordCreator _creator) { creator = _creator; }
  169.     public void execute() { creator.SetWordLanguage(); }
  170.     public void unexecute() { creator.UnsetWordLanguage(); }
  171. }
  172.  
  173.  
  174. /* Polecenie dla ustawienia polskiego tłumaczenia */
  175.  
  176. public class PolishCommand : ICommand {
  177.     private WordCreator creator; //obiekt wykonujacy
  178.     public PolishCommand () { creator = new WordCreator(); }
  179.     public PolishCommand (WordCreator _creator) { creator = _creator; }
  180.     public void execute() { creator.SetPolishTranslation(); }
  181.     public void unexecute() { creator.UnsetPolishTranslation(); }
  182. }
  183.  
  184.  
  185. /* Polecenie dla ustawienia obcego tłumaczenia */
  186.  
  187. public class ForeignCommand : ICommand {
  188.     private WordCreator creator; //obiekt wykonujacy
  189.     public ForeignCommand () { creator = new WordCreator(); }
  190.     public ForeignCommand (WordCreator _creator) { creator = _creator; }
  191.     public void execute() { creator.SetForeignTranslation(); }
  192.     public void unexecute() { creator.UnsetForeignTranslation(); }
  193. }
  194.  
  195. public class FinalCommand : ICommand {
  196.     private WordCreator creator; //obiekt wykonujacy
  197.     public FinalCommand () { creator = new WordCreator(); }
  198.     public FinalCommand (WordCreator _creator) { creator = _creator; }
  199.     public void execute() { creator.Finalization(); }
  200.     public void unexecute() { creator.Finalization(); }
  201. }
  202.  
  203.  
  204. Jeśli BackSpace, to unexecute, ustawić Command na poprzednie i znów execute
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement