Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Polecenie - typ interfejsowy */
- public interface ICommand {
- void Execute();
- void Unexecute();
- }
- /* Menu - obiekt wywolujacy */
- class Menu {
- private Command command;
- public void SetCommand (Command _command) { command = _command; }
- public void ExecuteCommand() { command.execute(); }
- public void UnexecuteCommand() { command.unexecute(); }
- }
- /* WordCreator - odbiorca polecenia */
- class WordCreator {
- private string language;
- private string polish;
- private string foreign;
- private Word newWord;
- public WordCreator () {
- language = "";
- polish = "";
- foreign = "";
- }
- public WordCreator (string _language) {
- language = _language;
- polish = "";
- foreign = "";
- }
- public WordCreator (string _language, string _polish) {
- language = _language;
- polish = _polish;
- foreign = "";
- }
- public WordCreator (string _language, string _polish, string _foreign) {
- language = _language;
- polish = _polish;
- foreign = _foreign;
- }
- public void SetWordLanguage () {
- bool correctKey = false;
- do {
- Console.Clear();
- Console.WriteLine("Wybierz język dodawanego słowa:");
- Console.WriteLine("(A)ngielski");
- Console.Write("(N)iemiecki");
- ConsoleKeyInfo pressedKey = Console.ReadKey();
- switch (pressedKey.Key) {
- case ConsoleKey.A:
- language = "english";
- correctKey = true;
- break;
- case ConsoleKey.N:
- language = "german";
- correctKey = true;
- break;
- default:
- break;
- }
- } while (!correctKey);
- }
- public void UnsetWordLanguage () {
- language = "";
- SetWordLanguage();
- }
- public void SetPolishTranslation () {
- bool correctTranslation = false;
- do {
- Console.Clear();
- Console.Write("Podaj polskie tłumaczenie dodawanego słowa: ");
- string _polish = Console.ReadLine();
- bool translationFound = false;
- if (_polish.Length > 2) {
- if (language == "english") {
- foreach (Word word in dictionary.GetEnglishWords()) {
- if (word.GetPolish() == _polish)
- translationFound = true;
- }
- }
- else if (language == "german") {
- foreach (Word word in dictionary.GetGermanWords()) {
- if (word.GetPolish() == _polish)
- translationFound = true;
- }
- }
- if (!translationFound) {
- polish = _polish;
- correctTranslation = true;
- }
- }
- } while (!correctTranslation);
- }
- public void UnsetPolishTranslation () {
- polish = "";
- SetPolishTranslation();
- }
- public void SetForeignTranslation () {
- bool correctTranslation = false;
- do {
- Console.Clear();
- if (language == "english")
- Console.Write("Podaj angielskie tłumaczenie dodawanego słowa: ");
- if (language == "german")
- Console.Write("Podaj niemieckie tłumaczenie dodawanego słowa: ");
- string _foreign = Console.ReadLine();
- bool translationFound = false;
- if (_foreign.Length > 2) {
- if (language == "english") {
- foreach (Word word in dictionary.GetEnglishWords()) {
- if (word.GetForeign() == _foreign)
- translationFound = true;
- }
- }
- else if (language == "german") {
- foreach (Word word in dictionary.GetGermanWords()) {
- if (word.GetForeign() == _foreign)
- translationFound = true;
- }
- }
- if (!translationFound) {
- foreign = _foreign;
- correctTranslation = true;
- }
- }
- } while (!correctTranslation);
- }
- public void UnsetForeignTranslation () {
- foreign = "";
- SetForeignTranslation();
- }
- public void Finalization () {
- if (language == "english") {
- newWord = new EnglishWord(polish,english,"");
- dictionary.GetEnglishWords().Add(newWord);
- // dopisać do pliku
- }
- else if (language == "german") {
- newWord = new GermanWord(polish,english,"");
- dictionary.GetGermanWords().Add(newWord);
- // dopisać do pliku
- }
- Console.Clear();
- Console.WriteLine(new StringBuilder().append("Nowe słowo: ").append(polish).append(" - ").append(foreign).toString());
- Console.Write("Wciśnij dowolny klawisz, aby kontynuować. ");
- Console.ReadKey();
- AdministratorPanel(justLogged);
- }
- }
- /* Polecenie dla ustawienia języka */
- public class LanguageCommand : ICommand {
- private WordCreator creator; //obiekt wykonujacy
- public LanguageCommand () { creator = new WordCreator(); }
- public LanguageCommand (WordCreator _creator) { creator = _creator; }
- public void execute() { creator.SetWordLanguage(); }
- public void unexecute() { creator.UnsetWordLanguage(); }
- }
- /* Polecenie dla ustawienia polskiego tłumaczenia */
- public class PolishCommand : ICommand {
- private WordCreator creator; //obiekt wykonujacy
- public PolishCommand () { creator = new WordCreator(); }
- public PolishCommand (WordCreator _creator) { creator = _creator; }
- public void execute() { creator.SetPolishTranslation(); }
- public void unexecute() { creator.UnsetPolishTranslation(); }
- }
- /* Polecenie dla ustawienia obcego tłumaczenia */
- public class ForeignCommand : ICommand {
- private WordCreator creator; //obiekt wykonujacy
- public ForeignCommand () { creator = new WordCreator(); }
- public ForeignCommand (WordCreator _creator) { creator = _creator; }
- public void execute() { creator.SetForeignTranslation(); }
- public void unexecute() { creator.UnsetForeignTranslation(); }
- }
- public class FinalCommand : ICommand {
- private WordCreator creator; //obiekt wykonujacy
- public FinalCommand () { creator = new WordCreator(); }
- public FinalCommand (WordCreator _creator) { creator = _creator; }
- public void execute() { creator.Finalization(); }
- public void unexecute() { creator.Finalization(); }
- }
- Jeśli BackSpace, to unexecute, ustawić Command na poprzednie i znów execute
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement