PhotoShaman

ПР #5

May 13th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.24 KB | None | 0 0
  1. //--------------------------------------------
  2. //----------------------Program.cs
  3. //--------------------------------------------
  4. using System;
  5.  
  6. namespace PR5
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Functions.Settings();
  13.             Functions.Menu();
  14.  
  15.             TV tv = new TV();
  16.             while (true)
  17.             {
  18.                 if (Console.KeyAvailable)
  19.                 {
  20.                     ConsoleKey k = Console.ReadKey(true).Key;
  21.                     switch (k)
  22.                     {
  23.                         case ConsoleKey.D0: return; //Exit
  24.                         case ConsoleKey.D1:
  25.                             tv.SwitchOn();
  26.                             Functions.DrawScreen(tv.Status, tv.Channel);
  27.                             Console.BackgroundColor = ConsoleColor.Black;
  28.                             Functions.Box(60, 1, 2, 42);
  29.                             break;  //TV On/Off
  30.                         case ConsoleKey.D2: break;
  31.                         case ConsoleKey.D3:
  32.                             tv.Channel--;
  33.                             Functions.DrawScreen(tv.Status, tv.Channel);
  34.                             break;
  35.                         case ConsoleKey.D4:
  36.                             tv.Channel++;
  37.                             Functions.DrawScreen(tv.Status, tv.Channel);
  38.                             break;
  39.                         case ConsoleKey.D5:
  40.                             if (tv.Status)
  41.                             {
  42.                                 Console.SetCursorPosition(64, 12);
  43.                                 Console.WriteLine("Введите номер канала: ");
  44.                                 Console.SetCursorPosition(64, 13);
  45.  
  46.                                 int channel;
  47.                                 string input = "";
  48.                                 ConsoleKeyInfo K;
  49.                                 /*Code protected by ZAV*/
  50.                                 for (int i = 0; i < 2; i++)
  51.                                 {
  52.                                     K = Console.ReadKey();
  53.                                     input += Convert.ToString(K.KeyChar);
  54.                                     if (K.KeyChar == 13)
  55.                                     {
  56.                                         break;
  57.                                     }
  58.                                 }
  59.                                 if (Int32.TryParse(input, out channel))
  60.                                 {
  61.                                     tv.Channel = channel;
  62.                                 }
  63.                                 Console.BackgroundColor = ConsoleColor.Black;
  64.                                 Functions.Box(26, 5, 64, 12);
  65.                                 Functions.DrawScreen(tv.Status, tv.Channel);
  66.                             }
  67.                             break;
  68.                         case ConsoleKey.D6:
  69.                             tv.SoundLevel--;
  70.                             break;
  71.                         case ConsoleKey.D7:
  72.                             tv.SoundLevel++;
  73.                             break;
  74.                         case ConsoleKey.D8:
  75.                             tv.SoundLevel = 0;
  76.                             break;
  77.                         case ConsoleKey.D9: break;
  78.                     }
  79.                 }
  80.                 Console.SetCursorPosition(2, 42);
  81.                 Console.ResetColor();
  82.                 tv.OutputInfo();
  83.             }
  84.         }
  85.     }
  86. }
  87.  
  88. //--------------------------------------------
  89. //----------------------Functions.cs
  90. //--------------------------------------------
  91. using System;
  92.  
  93. namespace PR5
  94. {
  95.     class Functions
  96.     {
  97.         public static void Box(int Width, int Height, int XPos, int YPos)
  98.         {
  99.             for (int i = 0; i < Height; i++)
  100.             {
  101.                 Console.SetCursorPosition(XPos, YPos);
  102.                 Console.Write(" ".PadRight(Width));
  103.                 YPos++;
  104.             }
  105.         }
  106.         public static void PrintAtPosition(string text, int x, int y)
  107.         {
  108.             Console.SetCursorPosition(x, y);
  109.             Console.WriteLine(text);
  110.         }
  111.         public static void Menu()
  112.         {
  113.             Console.BackgroundColor = ConsoleColor.Black;
  114.             PrintAtPosition("1. Включить/Выключить", 64, 1);
  115.             PrintAtPosition("2. (Кнопка сломана)", 64, 2);
  116.             PrintAtPosition("3. Канал--", 64, 3);
  117.             PrintAtPosition("4. Канал++", 64, 4);
  118.             PrintAtPosition("5. Ввести номер канала", 64, 5);
  119.             PrintAtPosition("6. Громкость--", 64, 6);
  120.             PrintAtPosition("7. Громкость++", 64, 7);
  121.             PrintAtPosition("8. Выключить звук", 64, 8);
  122.             PrintAtPosition("9. (Кнопка сломана)", 64, 9);
  123.             PrintAtPosition("0. Выход", 64, 10);
  124.         }
  125.         public static void Settings()
  126.         {
  127.             Console.SetWindowSize(90, 44);
  128.             Console.BufferHeight = Console.WindowHeight;
  129.             Console.BufferWidth = Console.WindowWidth;
  130.             Console.Title = "TV";
  131.             Console.CursorVisible = false;
  132.         }
  133.         public static void DrawScreen(bool status, int color = 0)
  134.         {
  135.             if (status)
  136.             {
  137.                 ConsoleColor[] colors = (ConsoleColor[])ConsoleColor.GetValues(typeof(ConsoleColor));
  138.                 Console.BackgroundColor = colors[color];
  139.             }
  140.             else
  141.             {
  142.                 Console.BackgroundColor = ConsoleColor.Black;
  143.             }
  144.             Box(60, 40, 2, 1);
  145.         }
  146.     }
  147. }
  148.  
  149. //--------------------------------------------
  150. //----------------------TV.cs
  151. //--------------------------------------------
  152. using System;
  153.  
  154. namespace PR5
  155. {
  156.     class TV
  157.     {
  158.         private bool status;
  159.         private int channel;
  160.         private int soundLevel;
  161.  
  162.         public TV()
  163.         {
  164.             status = false;
  165.         }
  166.         public bool Status
  167.         {
  168.             get { return status; }
  169.         }
  170.         public int Channel
  171.         {
  172.             get { return channel; }
  173.             set
  174.             {
  175.                 if (value > 0 && value <= 15)
  176.                 {
  177.                     channel = value;
  178.                 }
  179.             }
  180.         }
  181.         public int SoundLevel
  182.         {
  183.             get { return soundLevel; }
  184.             set
  185.             {
  186.                 if (value >= 0 && value < 100)
  187.                 {
  188.                     soundLevel = value;
  189.                 }
  190.             }
  191.         }
  192.         public void SwitchOn()
  193.         {
  194.             if (!status)
  195.             {
  196.                 status = true;
  197.                 soundLevel = 10;
  198.                 channel = 1;
  199.             }
  200.             else
  201.             {
  202.                 status = false;
  203.             }
  204.         }
  205.         public void OutputInfo()
  206.         {
  207.             if (status)
  208.             {
  209.                 Console.WriteLine("Телевизор включен. Канал: {0}\tГромкость: {1}\t", channel, soundLevel);
  210.             }
  211.             else
  212.             {
  213.                 Console.WriteLine("Телевизор выключен");
  214.             }
  215.         }
  216.     }
  217. }
Advertisement
Add Comment
Please, Sign In to add comment