Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.IO;
- namespace source
- {
- class Program
- {
- public static void Main(string[] args)
- {
- var objCommand = new List<SetName>
- {
- new SetName("SetName"),
- new DisplayName("DisplayName"),
- new SetColor("SetColor"),
- new DicplayBoxWithName("DicplayBoxWithName")
- };
- while(true)
- {
- Console.Clear();
- Console.WriteLine("Введите команду:");
- GetCommand(objCommand);
- CommandExecution(Console.ReadLine(), objCommand);
- Console.ReadLine();
- }
- }
- static void GetCommand(List<SetName> objComm)
- {
- for(int i = 0; i < objComm.Count; i++)
- {
- Console.WriteLine(objComm[i].NameCommand);
- }
- Console.WriteLine(Environment.NewLine);
- }
- static void CommandExecution(string command, List<SetName> objcomm)
- {
- foreach(var obj in objcomm)
- {
- if(obj.NameCommand == command)
- {
- obj.Action();
- return;
- }
- }
- Console.WriteLine("Такой команды нет.");
- }
- }
- class SetName
- {
- public SetName(string namecommand)
- {
- NameCommand = namecommand;
- Name = "Иван";
- }
- public string NameCommand{get;set;}
- public string Name{get;set;}
- public virtual void Action()
- {
- Console.WriteLine("Введите имя:");
- this.Name = Console.ReadLine();
- }
- }
- class DisplayName: SetName
- {
- public DisplayName(string namecommand): base(namecommand)
- {
- base.NameCommand = namecommand;
- }
- public int CountName{get;set;}
- public override void Action()
- {
- Console.WriteLine("Введите целое число:");
- this.CountName = InputNumber();
- for(int i = 0; i < this.CountName; i++)
- {
- Console.WriteLine(Name);
- }
- }
- static public int InputNumber()
- {
- int userNumber;
- while(int.TryParse(Console.ReadLine(), out userNumber) == false)
- {
- Console.WriteLine("Ошибка ввода! Попробуйте еще раз.");
- }
- return userNumber;
- }
- }
- class SetColor: SetName
- {
- public SetColor(string namecommand): base(namecommand)
- {
- base.NameCommand = namecommand;
- }
- public override void Action()
- {
- Console.WriteLine("Выберите цифру цвета:");
- var colors = Enum.GetValues(typeof(ConsoleColor));
- for(int i = 0; i < colors.Length; i++)
- {
- Console.WriteLine("Цвет - {0}; Команда - {1}", colors.GetValue(i), i);
- }
- Console.WriteLine("Цвет фона:");
- Console.BackgroundColor = (ConsoleColor)colors.GetValue(DisplayName.InputNumber());
- Console.WriteLine("Цвет текста:");
- Console.ForegroundColor = (ConsoleColor)colors.GetValue(DisplayName.InputNumber());
- }
- }
- class DicplayBoxWithName: SetName
- {
- public DicplayBoxWithName(string namecommand): base(namecommand)
- {
- base.NameCommand = namecommand;
- }
- public override void Action()
- {
- Console.WriteLine("Установите размер стороны квадрата: ");
- int sizeSquare = DisplayName.InputNumber();
- for(int i = 0; i < sizeSquare; i++)
- {
- if(i == 0 || i == sizeSquare-1)
- {
- Console.WriteLine(new String('#', sizeSquare));
- }
- else
- {
- Char[] mass = Name.ToCharArray();
- if(sizeSquare/2 == i)
- {
- Console.WriteLine("#" + new String(mass, 0, mass.Length) + new String(' ', sizeSquare-2-mass.Length) + "#");
- }
- else
- {
- Console.WriteLine("#" + new String(' ', sizeSquare - 2) + "#");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement