Advertisement
golovanovd

MicroWave2.0

Sep 18th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 17.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7.  
  8. namespace MicroWave
  9. {
  10.     class Program
  11.     {
  12.  
  13.  
  14.         static void Main(string[] args)
  15.         {
  16.  
  17.             Microwave Microwave_1 = new Microwave("LG", "MS2042DY");
  18.             Microwave_1.Print();
  19.             int power_op = 1, temp_op = 1, weight_op = 1, time_op=1;
  20.  
  21.  
  22.  
  23.  
  24.             while (true)
  25.             {
  26.                 char key = Console.ReadKey().KeyChar;
  27.                 switch (key)
  28.                 {
  29.                     case '1':
  30.                         Microwave_1.SwitchON_OFF();
  31.                         break;
  32.  
  33.                     case '2':
  34.                         Microwave_1.PreviousMode();
  35.                         break;
  36.                     case '3':
  37.                         Microwave_1.NextMode();
  38.                         break;
  39.                     case 'q':
  40.                     case 'Q':
  41.                     case 'й':
  42.                     case 'Й':
  43.                         power_op = 1;
  44.                         Microwave_1.DecreasePower(power_op);
  45.                         break;
  46.                     case 'w':
  47.                     case 'W':
  48.                     case 'ц':
  49.                     case 'Ц':
  50.                         power_op = 1;
  51.                         Microwave_1.IncreasePower(power_op);
  52.                         break;
  53.                     case 'e':
  54.                     case 'E':
  55.                     case 'у':
  56.                     case 'У':
  57.                         power_op=2;
  58.                         Microwave_1.DecreasePower(power_op);
  59.                         break;
  60.                     case 'r':
  61.                     case 'R':
  62.                     case 'к':
  63.                     case 'К':
  64.                         power_op = 2;
  65.                         Microwave_1.IncreasePower(power_op);
  66.                         break;
  67.                     case 'a':
  68.                     case 'A':
  69.                     case 'ф':
  70.                     case 'Ф':
  71.                         temp_op = 1;
  72.                         Microwave_1.DecreaseTemperature(temp_op);
  73.                         break;
  74.                     case 's':
  75.                     case 'S':
  76.                     case 'ы':
  77.                     case 'Ы':
  78.                         temp_op = 1;
  79.                         Microwave_1.IncreaseTemperature(temp_op);
  80.                         break;
  81.                     case 'd':
  82.                     case 'D':
  83.                     case 'в':
  84.                     case 'В':
  85.                         temp_op = 2;
  86.                         Microwave_1.DecreaseTemperature(temp_op);
  87.                         break;
  88.                     case 'f':
  89.                     case 'F':
  90.                     case 'а':
  91.                     case 'А':
  92.                         temp_op = 2;
  93.                         Microwave_1.IncreaseTemperature(temp_op);
  94.                         break;
  95.                     case 'z':
  96.                     case 'Z':
  97.                     case 'я':
  98.                     case 'Я':
  99.                         weight_op = 1;
  100.                         Microwave_1.DecreaseWeight(weight_op);
  101.                         break;
  102.                     case 'x':
  103.                     case 'X':
  104.                     case 'ч':
  105.                     case 'Ч':
  106.                         weight_op = 1;
  107.                         Microwave_1.IncreaseWeight(weight_op);
  108.                         break;
  109.                     case 'c':
  110.                     case 'C':
  111.                     case 'с':
  112.                     case 'С':
  113.                         weight_op = 2;
  114.                         Microwave_1.DecreaseWeight(weight_op);
  115.                         break;
  116.                     case 'v':
  117.                     case 'V':
  118.                     case 'м':
  119.                     case 'М':
  120.                         weight_op = 2;
  121.                         Microwave_1.IncreaseWeight(weight_op);
  122.                         break;
  123.                     case '4':
  124.                         time_op = 1;
  125.                         Microwave_1.DecreaseTime(time_op);
  126.                         break;
  127.                     case '5':
  128.                         time_op = 1;
  129.                         Microwave_1.IncreaseTime(time_op);
  130.                         break;
  131.                     case '6':
  132.                         time_op = 2;
  133.                         Microwave_1.DecreaseTime(time_op);
  134.                         break;
  135.                     case '7':
  136.                         time_op = 2;
  137.                         Microwave_1.IncreaseTime(time_op);
  138.                         break;
  139.                     case '9':
  140.                         Microwave_1.TM_ON();
  141.                         break;
  142.  
  143.                     case '`':
  144.                     case '~':
  145.                     case 'Ё':
  146.                     case 'ё':
  147.                         Microwave_1.Info_ON_OFF();
  148.                         break;
  149.                     case '0':
  150.                         Environment.Exit(0);
  151.                         break;
  152.                     case ' ':
  153.                         {
  154.  
  155.                             Microwave_1.TM_ON();
  156.                             break;
  157.  
  158.                         }
  159.  
  160.                 }
  161.                 Microwave_1.Print();
  162.             }
  163.         }
  164.  
  165.         public void TM()
  166.         {
  167.             Console.WriteLine("Hello!");
  168.         }
  169.  
  170.  
  171.     }
  172.  
  173.  
  174.     public enum Modes
  175.     {
  176.         MICROWAVE, OVEN, DEFROSTING
  177.  
  178.     }
  179.  
  180.  
  181.     class Microwave
  182.     {
  183.         private string m_brand = "no_name";
  184.         private string m_model = "no_name";
  185.         private bool m_state = false;
  186.         private static bool m_tm = false;
  187.         private bool m_info = false;
  188.         private Modes mode = Modes.MICROWAVE;
  189.         private int temperature = 0, power = 300;
  190.         private double weight = 0.1;
  191.         private static int time = 15;
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.         public Microwave(string brand, string model)
  199.         {
  200.             if (brand.Length <= 15)
  201.                 m_brand = brand;
  202.             m_model = model;
  203.         }
  204.  
  205.         public Microwave(Modes startMode)
  206.         {
  207.             mode = startMode;
  208.         }
  209.  
  210.         public void SwitchON_OFF()
  211.         {
  212.             if(m_state == false) m_state = true;
  213.             else m_state = false;
  214.         }
  215.         public void Info_ON_OFF()
  216.         {
  217.             if (m_info == false) m_info = true;
  218.             else m_info = false;
  219.         }
  220.  
  221.         public void TM_OFF()
  222.         {
  223.             m_tm = false;
  224.         }
  225.         public void TM_ON()
  226.         {
  227.             m_tm = true;
  228.         }
  229.  
  230.  
  231.         public void NextMode()
  232.         {
  233.             if (m_state && mode != Modes.DEFROSTING)
  234.             {
  235.                 mode++;
  236.             }
  237.         }
  238.  
  239.         public void PreviousMode()
  240.         {
  241.             if (m_state && mode != Modes.MICROWAVE)
  242.             {
  243.                 mode--;
  244.             }
  245.         }
  246.         public void IncreasePower(int op)
  247.         {
  248.             if (m_state && power != 700)
  249.             {
  250.                 if (op == 2) power += 100;
  251.                 else power += 25;
  252.  
  253.             }
  254.         }
  255.  
  256.         public void DecreasePower(int op)
  257.         {
  258.             if (m_state && power != 300)
  259.             {
  260.                 if (op == 2) power -= 100;
  261.                 else power -= 25;
  262.             }
  263.         }
  264.         public void IncreaseTemperature(int op)
  265.         {
  266.             if (m_state && temperature != 250)
  267.             {
  268.                 if (op == 2) temperature += 30;
  269.                 else temperature += 10;
  270.             }
  271.         }
  272.  
  273.         public void DecreaseTemperature(int op)
  274.         {
  275.             if (m_state && temperature != 0)
  276.             {
  277.                 if (op == 2) temperature -= 30;
  278.                 else temperature -= 10;
  279.             }
  280.         }
  281.         public void IncreaseWeight(int op)
  282.         {
  283.             if (m_state && weight < 2.5)
  284.             {
  285.                 if (op == 2)
  286.                 {
  287.                     weight += 0.25;
  288.                     time += 300;
  289.                 }
  290.                 else
  291.                 {
  292.                     weight += 0.1;
  293.                     time += 120;
  294.                 }
  295.             }
  296.         }
  297.  
  298.         public void DecreaseWeight(int op)
  299.         {
  300.             if (m_state && weight > 0.1)
  301.             {
  302.                 if (op == 2)
  303.                 {
  304.                     weight -= 0.25;
  305.                     time -= 300;
  306.                 }
  307.                 else
  308.                 {
  309.                     weight -= 0.1;
  310.                     time -= 120;
  311.                 }
  312.             }
  313.         }
  314.         public void IncreaseTime(int op)
  315.         {
  316.             if (m_state && time < 10800)
  317.             {
  318.                 if (op == 2) time += 300;
  319.                 else time += 15;
  320.             }
  321.         }
  322.  
  323.         public void DecreaseTime(int op)
  324.         {
  325.             if (m_state && time > 0)
  326.             {
  327.                 if (op == 2) time -= 300;
  328.                 else time -= 15;
  329.             }
  330.         }
  331.  
  332.  
  333.  
  334.         public static void timer_func()
  335.         {
  336.  
  337.                 int num = 0;
  338.  
  339.                 // устанавливаем метод обратного вызова
  340.                 TimerCallback tm = new TimerCallback(Count);
  341.                 // создаем таймер
  342.                 Timer timer = new Timer(tm, num, 0, 1000);
  343.  
  344.         }
  345.         public static void Count(object obj)
  346.         {
  347.            
  348.             //    Console.Clear();
  349.             Console.ForegroundColor = ConsoleColor.White;
  350.             if (time >= 0)
  351.             {
  352.                 Console.Clear();
  353.                 timer_print();
  354.                 time--;
  355.             }
  356.             else Console.ReadLine();
  357.            
  358.         }
  359.         public static void timer_print()
  360.         {
  361.  
  362.             Console.ForegroundColor = ConsoleColor.White;
  363.             if (time > 3599 && time < 10800)
  364.             {
  365.                 Console.Write("{0}:", time / 3600);
  366.  
  367.             }
  368.             if (time % 3600 > 59 && time % 3600 < 3600)
  369.             {
  370.                 if (time % 3600 < 600) Console.Write("0{0}:", (time % 3600) / 60);
  371.                 else Console.Write("{0}:", (time % 3600) / 60);
  372.             }
  373.             else Console.Write("00:");
  374.  
  375.             if ((time % 3600) % 60 < 10) Console.Write("0{0}", (time % 3600) % 60);      
  376.             else Console.Write("{0}", (time % 3600) % 60);
  377.             Console.ForegroundColor = ConsoleColor.Gray;
  378.  
  379.             if (!m_tm) Console.Write("\t\t\t\t\t\t[4]-[5] - Увеличить/Уменьшить время");
  380.             else Console.WriteLine("");
  381.  
  382.         }
  383.  
  384.  
  385.  
  386.  
  387.         public  void Print()
  388.         {
  389.  
  390.             Program program_1 = new Program();
  391.             program_1.TM();
  392.  
  393.  
  394.  
  395.             Console.Clear();
  396.             // изменение цвета текста
  397.             Console.ForegroundColor = ConsoleColor.Gray;
  398.             Console.Write(" Микроволновая печь: ");
  399.             Console.ForegroundColor = ConsoleColor.White;
  400.             Console.Write(m_brand + " " + m_model);
  401.  
  402.             if (m_state)
  403.             {
  404.                 Console.ForegroundColor = ConsoleColor.Gray;
  405.                 Console.Write("\t\t\t    [~] - Допольнительная информация");
  406.             }
  407.             Console.WriteLine("\n");
  408.  
  409.             if (m_state)
  410.             {
  411.                 Console.Title = m_brand + " " + m_model + " - Включено";
  412.                 Console.ForegroundColor = ConsoleColor.Gray;
  413.                 Console.Write(" Состояние:");
  414.                 Console.ForegroundColor = ConsoleColor.Green;
  415.                 Console.Write(" включена");
  416.                 Console.ForegroundColor = ConsoleColor.Gray;
  417.                 Console.WriteLine("\t\t\t\t\t    [1] - Включить/Выключить\n");
  418.                 Console.ForegroundColor = ConsoleColor.Gray;
  419.  
  420.                 Console.Write(" Режим: ");
  421.  
  422.                 switch (mode)
  423.                 {
  424.                     case Modes.MICROWAVE:
  425.                         Console.ForegroundColor = ConsoleColor.Yellow;
  426.                         Console.Write("СВЧ      ");
  427.                         break;
  428.                     case Modes.OVEN:
  429.                         Console.ForegroundColor = ConsoleColor.Red;
  430.                         Console.Write("Духовка  ");
  431.                         break;
  432.                     case Modes.DEFROSTING:
  433.  
  434.                         Console.ForegroundColor = ConsoleColor.Cyan;
  435.                         Console.Write("Разморозка");
  436.                         break;
  437.                     default:
  438.                         Console.ForegroundColor = ConsoleColor.Red;
  439.                         Console.WriteLine(mode);
  440.                         break;
  441.                 }
  442.                 Console.ForegroundColor = ConsoleColor.Gray;
  443.                 Console.WriteLine("\t\t\t\t\t[2]-[3] - Предыдущий/Следующий режим");
  444.                 Console.ForegroundColor = ConsoleColor.Gray;
  445.  
  446.  
  447.  
  448.                 if (mode == Modes.MICROWAVE)
  449.                 {
  450.                     Console.Write(" Мощность: ");
  451.                     Console.ForegroundColor = ConsoleColor.White;
  452.                     Console.Write("{0}", power);
  453.                     Console.ForegroundColor = ConsoleColor.Gray;
  454.                     Console.Write(" W");
  455.                     Console.ForegroundColor = ConsoleColor.Gray;
  456.                     Console.Write("\t\t\t\t\t[Q]-[W] - Уменьшить/Увеличить мощность");
  457.                     if (m_info)
  458.                     {
  459.  
  460.                         Console.ForegroundColor = ConsoleColor.DarkGray;
  461.                         Console.WriteLine("      25 W");
  462.                         Console.ForegroundColor = ConsoleColor.DarkYellow;
  463.                         Console.Write("\t\t\t\t\t\t\t[E]-[R]\t\t\t\t\t   100 W ");
  464.                     }
  465.                     else Console.WriteLine("");
  466.                     Console.ForegroundColor = ConsoleColor.Gray;
  467.  
  468.                 }
  469.                 if (mode == Modes.OVEN)
  470.                 {
  471.                     Console.Write(" Температура: ");
  472.                     Console.ForegroundColor = ConsoleColor.White;
  473.                     Console.Write("{0}", temperature);
  474.                     Console.ForegroundColor = ConsoleColor.Gray;
  475.                     Console.Write("*C");
  476.                     Console.ForegroundColor = ConsoleColor.Gray;
  477.                     Console.Write("\t\t\t\t\t[E]-[R] - Уменьшить/Увеличить температуру ");
  478.                     if (m_info)
  479.                     {
  480.  
  481.                         Console.ForegroundColor = ConsoleColor.DarkGray;
  482.                         Console.WriteLine("  10*C");
  483.                         Console.ForegroundColor = ConsoleColor.DarkRed;
  484.                         Console.Write("\t\t\t\t\t\t\t[D]-[F]\t\t\t\t\t    30*C  ");
  485.                     }
  486.                     else Console.WriteLine("");
  487.  
  488.  
  489.                     Console.ForegroundColor = ConsoleColor.Gray;
  490.                 }
  491.                 if (mode == Modes.DEFROSTING)
  492.                 {
  493.                     Console.Write(" Вес: ");
  494.                     Console.ForegroundColor = ConsoleColor.White;
  495.                     Console.Write("{0}", weight);
  496.                     Console.ForegroundColor = ConsoleColor.Gray;
  497.                     Console.Write(" Kg");
  498.                     Console.ForegroundColor = ConsoleColor.Gray;
  499.                     Console.Write("\t\t\t\t\t\t[A]-[S] - Уменьшить/Увеличить вес");
  500.                     if (m_info)
  501.                     {
  502.                         Console.ForegroundColor = ConsoleColor.DarkGray;
  503.                         Console.WriteLine("\t   100 g ");
  504.                         Console.ForegroundColor = ConsoleColor.DarkCyan;
  505.                         Console.Write("\t\t\t\t\t\t\t[C]-[V]\t\t\t\t\t   250 g ");
  506.                     }
  507.                     else Console.WriteLine("");
  508.                     Console.ForegroundColor = ConsoleColor.Gray;
  509.                 }
  510.                
  511.                 Console.Write("\n Таймер: ");
  512.                 if (m_tm && time > 0)
  513.                 {
  514.                     Console.Clear();
  515.                     timer_func();
  516.                 }
  517.                 else
  518.                 {
  519.                     m_tm = false;
  520.                     timer_print();
  521.                     if (m_info)
  522.                     {
  523.                         Console.ForegroundColor = ConsoleColor.DarkGray;
  524.                         Console.WriteLine("\t    15 sec ");
  525.                         Console.Write("\t\t\t\t\t\t\t[6]-[7]\t\t\t\t\t     1 min ");
  526.                     }
  527.                     else Console.WriteLine("");
  528.                     Console.ForegroundColor = ConsoleColor.Gray;
  529.                     Console.WriteLine("\n\t\t\t\t\t\t\t[Space] - Пуск");
  530.                 }
  531.                 Console.ForegroundColor = ConsoleColor.Gray;
  532.                 if (m_info&&!m_tm)
  533.                 {
  534.                     Console.ForegroundColor = ConsoleColor.DarkGray;
  535.                     Console.WriteLine("\n\t\t\t\t\t\t\t    [0] - Завершение программы");
  536.                     Console.ForegroundColor = ConsoleColor.Gray;
  537.                 }
  538.                
  539.  
  540.             }
  541.             else
  542.             {
  543.                 Console.Title = m_brand + " " + m_model + " - Отключено";
  544.                 Console.ForegroundColor = ConsoleColor.Gray;
  545.                 Console.Write(" Состояние: ");
  546.                 Console.ForegroundColor = ConsoleColor.Red;
  547.                 Console.Write("выключена ");
  548.                 Console.ForegroundColor = ConsoleColor.Gray;
  549.                 Console.WriteLine("\t\t\t\t\t    [1] - Включить/Выключить\n");
  550.                 Console.ForegroundColor = ConsoleColor.Gray;
  551.                 Console.WriteLine("");
  552.             }
  553.  
  554.         }
  555.     }
  556. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement