Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //--------------------------------------------
- //----------------------Program.cs
- //--------------------------------------------
- using System;
- namespace PR5
- {
- class Program
- {
- static void Main(string[] args)
- {
- Functions.Settings();
- Functions.Menu();
- TV tv = new TV();
- while (true)
- {
- if (Console.KeyAvailable)
- {
- ConsoleKey k = Console.ReadKey(true).Key;
- switch (k)
- {
- case ConsoleKey.D0: return; //Exit
- case ConsoleKey.D1:
- tv.SwitchOn();
- Functions.DrawScreen(tv.Status, tv.Channel);
- Console.BackgroundColor = ConsoleColor.Black;
- Functions.Box(60, 1, 2, 42);
- break; //TV On/Off
- case ConsoleKey.D2: break;
- case ConsoleKey.D3:
- tv.Channel--;
- Functions.DrawScreen(tv.Status, tv.Channel);
- break;
- case ConsoleKey.D4:
- tv.Channel++;
- Functions.DrawScreen(tv.Status, tv.Channel);
- break;
- case ConsoleKey.D5:
- if (tv.Status)
- {
- Console.SetCursorPosition(64, 12);
- Console.WriteLine("Введите номер канала: ");
- Console.SetCursorPosition(64, 13);
- int channel;
- string input = "";
- ConsoleKeyInfo K;
- /*Code protected by ZAV*/
- for (int i = 0; i < 2; i++)
- {
- K = Console.ReadKey();
- input += Convert.ToString(K.KeyChar);
- if (K.KeyChar == 13)
- {
- break;
- }
- }
- if (Int32.TryParse(input, out channel))
- {
- tv.Channel = channel;
- }
- Console.BackgroundColor = ConsoleColor.Black;
- Functions.Box(26, 5, 64, 12);
- Functions.DrawScreen(tv.Status, tv.Channel);
- }
- break;
- case ConsoleKey.D6:
- tv.SoundLevel--;
- break;
- case ConsoleKey.D7:
- tv.SoundLevel++;
- break;
- case ConsoleKey.D8:
- tv.SoundLevel = 0;
- break;
- case ConsoleKey.D9: break;
- }
- }
- Console.SetCursorPosition(2, 42);
- Console.ResetColor();
- tv.OutputInfo();
- }
- }
- }
- }
- //--------------------------------------------
- //----------------------Functions.cs
- //--------------------------------------------
- using System;
- namespace PR5
- {
- class Functions
- {
- public static void Box(int Width, int Height, int XPos, int YPos)
- {
- for (int i = 0; i < Height; i++)
- {
- Console.SetCursorPosition(XPos, YPos);
- Console.Write(" ".PadRight(Width));
- YPos++;
- }
- }
- public static void PrintAtPosition(string text, int x, int y)
- {
- Console.SetCursorPosition(x, y);
- Console.WriteLine(text);
- }
- public static void Menu()
- {
- Console.BackgroundColor = ConsoleColor.Black;
- PrintAtPosition("1. Включить/Выключить", 64, 1);
- PrintAtPosition("2. (Кнопка сломана)", 64, 2);
- PrintAtPosition("3. Канал--", 64, 3);
- PrintAtPosition("4. Канал++", 64, 4);
- PrintAtPosition("5. Ввести номер канала", 64, 5);
- PrintAtPosition("6. Громкость--", 64, 6);
- PrintAtPosition("7. Громкость++", 64, 7);
- PrintAtPosition("8. Выключить звук", 64, 8);
- PrintAtPosition("9. (Кнопка сломана)", 64, 9);
- PrintAtPosition("0. Выход", 64, 10);
- }
- public static void Settings()
- {
- Console.SetWindowSize(90, 44);
- Console.BufferHeight = Console.WindowHeight;
- Console.BufferWidth = Console.WindowWidth;
- Console.Title = "TV";
- Console.CursorVisible = false;
- }
- public static void DrawScreen(bool status, int color = 0)
- {
- if (status)
- {
- ConsoleColor[] colors = (ConsoleColor[])ConsoleColor.GetValues(typeof(ConsoleColor));
- Console.BackgroundColor = colors[color];
- }
- else
- {
- Console.BackgroundColor = ConsoleColor.Black;
- }
- Box(60, 40, 2, 1);
- }
- }
- }
- //--------------------------------------------
- //----------------------TV.cs
- //--------------------------------------------
- using System;
- namespace PR5
- {
- class TV
- {
- private bool status;
- private int channel;
- private int soundLevel;
- public TV()
- {
- status = false;
- }
- public bool Status
- {
- get { return status; }
- }
- public int Channel
- {
- get { return channel; }
- set
- {
- if (value > 0 && value <= 15)
- {
- channel = value;
- }
- }
- }
- public int SoundLevel
- {
- get { return soundLevel; }
- set
- {
- if (value >= 0 && value < 100)
- {
- soundLevel = value;
- }
- }
- }
- public void SwitchOn()
- {
- if (!status)
- {
- status = true;
- soundLevel = 10;
- channel = 1;
- }
- else
- {
- status = false;
- }
- }
- public void OutputInfo()
- {
- if (status)
- {
- Console.WriteLine("Телевизор включен. Канал: {0}\tГромкость: {1}\t", channel, soundLevel);
- }
- else
- {
- Console.WriteLine("Телевизор выключен");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment