Nemo048

Untitled

Jul 26th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.17 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4.  
  5. namespace ConsoleApplication
  6. {
  7.     /*
  8.      *  - кафе 2 на 2
  9.      *  бесконечный цикл:
  10.      *      - создание новый Person рандомное поведение и рандомный возраст
  11.      *      - у кафе вызываем метод NewVisitor
  12.      *      - если пользователь нажимает Escape, выходим из цикла и завершаем программу
  13.      */
  14.  
  15.     class Test
  16.     {
  17.         public void RandomBehavior()
  18.         {
  19.             Random r = new Random();
  20.  
  21.             PersonBehavior behavior = (PersonBehavior)r.Next(0, 3);
  22.         }
  23.     }
  24.  
  25.     #region
  26.     class Program
  27.     {
  28.         public static Random random = new Random();
  29.         static void Main(string[] args)
  30.         {
  31.             Cafe cafe = new Cafe(2, 2);
  32.  
  33.             int personCounter = 0;
  34.  
  35.             Console.WriteLine("Нажмите на Enter для начала игры и продолжайте нажимать, \nесли вы захотите увидеть нового посетителя в своем кафе. \n Для выхода из игры нажмите Escape\n");
  36.  
  37.             ConsoleKey key = Console.ReadKey(true).Key;
  38.  
  39.             while (key != ConsoleKey.Escape)
  40.             {
  41.                 Person person = new Person("Wiktor" + personCounter++, random.Next(9, 61), (PersonBehavior)random.Next(0, 3));
  42.                 cafe.NewVisitor(person);
  43.  
  44.                 //System.Threading.Thread.Sleep(2000);
  45.                 Console.WriteLine();
  46.                 key = Console.ReadKey(true).Key;
  47.             }
  48.            
  49.         }
  50.     }
  51.  
  52.     class Person
  53.     {
  54.         public string Name;
  55.         public int Age;
  56.         private PersonBehavior Behavior;
  57.  
  58.         public Person(string name, int age, PersonBehavior behavior)
  59.         {
  60.             Name = name;
  61.             Age = age;
  62.             Behavior = behavior;
  63.         }
  64.  
  65.         public Person(string name, int age)
  66.         {
  67.             Name = name;
  68.             Age = age;
  69.         }
  70.  
  71.         public PersonBehavior GetBehavior()
  72.         {
  73.             return Behavior;
  74.         }
  75.     }
  76.  
  77.     class Employee : Person
  78.     {
  79.         public int Salary { get; private set; }
  80.  
  81.         public Employee(string name, int age, int salary) : base(name, age)
  82.         {
  83.             Salary = salary;
  84.         }
  85.     }
  86.  
  87.     class Waiter : Employee
  88.     {
  89.         public Waiter(string name, int age, int salary) : base(name, age, salary)
  90.         {
  91.  
  92.         }
  93.     }
  94.  
  95.     class Security : Employee
  96.     {
  97.         public Security(string name, int age, int salary) : base(name, age, salary)
  98.         {
  99.         }
  100.     }
  101.  
  102.     class Cafe
  103.     {
  104.         private int CurrentWaiters = 0;
  105.         private int CurrentSecurities = 0;
  106.         private int MaxWaiters;
  107.         private int MaxSecurities;
  108.         private Employee[] Employees;
  109.  
  110.         public Cafe(int maxWaiters, int maxSecurities)
  111.         {
  112.             Employees = new Employee[maxWaiters + maxSecurities];
  113.             MaxWaiters = maxWaiters;
  114.             MaxSecurities = maxSecurities;
  115.         }
  116.        
  117.         public void NewVisitor(Person person)
  118.         {
  119.             Console.WriteLine("У нас новый посетитель:)");
  120.             Console.WriteLine("{0}, {1}, {2}", person.Name, person.Age, person.GetBehavior());
  121.  
  122.             switch (person.GetBehavior())
  123.             {
  124.                 case PersonBehavior.Aggressive:
  125.                     Console.WriteLine("Пожалуйста поспокойнее, {0}!", person.Name);
  126.                     RecruitmentSecurity(person);
  127.                     break;
  128.                 case PersonBehavior.Passive:
  129.                     if (person.Age < 18)
  130.                     {
  131.                         Console.WriteLine("Здравствуй, {0}, у нас кафе для взрослых! \nГде твои родители?", person.Name);
  132.                     }
  133.                     else
  134.                     {
  135.                         Console.WriteLine("С вас 30000 рублей, уважаемый, {0}!", person.Name);
  136.                     }
  137.                     break;
  138.                 case PersonBehavior.Polite:
  139.                     Console.WriteLine("О, Вы так вежливы, {0}! \nВозможно у меня будет для Вас кое-какое предложение", person.Name);
  140.                     RecruitmentWaiter(person);
  141.                     break;
  142.             }
  143.         }
  144.  
  145.         private void RecruitmentSecurity(Person person)
  146.         {
  147.             if(CurrentSecurities < MaxSecurities)
  148.             {
  149.                
  150.                 Security security = new Security(person.Name, person.Age, 20000);
  151.                 Employees[GetIndexOfNull(Employees)] = security;
  152.                 Console.WriteLine("Поздравляем, {0}! \nВы приняты на должность охранника с зарплатой {1} рублей!", security.Name, security.Salary);
  153.                 CurrentSecurities++;
  154.             }
  155.             else
  156.             {
  157.                 Console.WriteLine("Охрана, выкиньте {0} из зала!", person.Name);
  158.             }
  159.         }
  160.  
  161.         private int GetIndexOfNull(Employee[] employees)
  162.         {
  163.             int indexOfNull = -1;
  164.  
  165.             for(int i = 0; i < employees.Length; i++)
  166.             {
  167.                 if(employees[i] == null)
  168.                 {
  169.                     indexOfNull = i;
  170.                     break;
  171.                 }
  172.             }
  173.  
  174.             return indexOfNull;
  175.         }
  176.  
  177.         private void RecruitmentWaiter(Person person)
  178.         {
  179.             if (CurrentWaiters < MaxWaiters)
  180.             {
  181.                 Waiter waiter = new Waiter(person.Name, person.Age, 30000);
  182.                 Employees[GetIndexOfNull(Employees)] = waiter;
  183.                 Console.WriteLine("{0}, без Вас мы не справимся! \nВы приняты на должность официанта с зарплатой {1} рублей!", waiter.Name, waiter.Salary);
  184.                 CurrentWaiters++;
  185.             }
  186.             else
  187.             {
  188.                 Console.WriteLine("Ох...Очень жаль, {0}, \nно у нас сейчас нет места для еще одного официанта :(", person.Name);
  189.             }
  190.         }
  191.     }
  192.  
  193.     public enum PersonBehavior
  194.     {
  195.         Aggressive,
  196.         Passive,
  197.         Polite
  198.     }
  199.  
  200. }
  201. #endregion
Advertisement
Add Comment
Please, Sign In to add comment