Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- namespace ConsoleApplication
- {
- /*
- * - кафе 2 на 2
- * бесконечный цикл:
- * - создание новый Person рандомное поведение и рандомный возраст
- * - у кафе вызываем метод NewVisitor
- * - если пользователь нажимает Escape, выходим из цикла и завершаем программу
- */
- class Test
- {
- public void RandomBehavior()
- {
- Random r = new Random();
- PersonBehavior behavior = (PersonBehavior)r.Next(0, 3);
- }
- }
- #region
- class Program
- {
- public static Random random = new Random();
- static void Main(string[] args)
- {
- Cafe cafe = new Cafe(2, 2);
- int personCounter = 0;
- Console.WriteLine("Нажмите на Enter для начала игры и продолжайте нажимать, \nесли вы захотите увидеть нового посетителя в своем кафе. \n Для выхода из игры нажмите Escape\n");
- ConsoleKey key = Console.ReadKey(true).Key;
- while (key != ConsoleKey.Escape)
- {
- Person person = new Person("Wiktor" + personCounter++, random.Next(9, 61), (PersonBehavior)random.Next(0, 3));
- cafe.NewVisitor(person);
- //System.Threading.Thread.Sleep(2000);
- Console.WriteLine();
- key = Console.ReadKey(true).Key;
- }
- }
- }
- class Person
- {
- public string Name;
- public int Age;
- private PersonBehavior Behavior;
- public Person(string name, int age, PersonBehavior behavior)
- {
- Name = name;
- Age = age;
- Behavior = behavior;
- }
- public Person(string name, int age)
- {
- Name = name;
- Age = age;
- }
- public PersonBehavior GetBehavior()
- {
- return Behavior;
- }
- }
- class Employee : Person
- {
- public int Salary { get; private set; }
- public Employee(string name, int age, int salary) : base(name, age)
- {
- Salary = salary;
- }
- }
- class Waiter : Employee
- {
- public Waiter(string name, int age, int salary) : base(name, age, salary)
- {
- }
- }
- class Security : Employee
- {
- public Security(string name, int age, int salary) : base(name, age, salary)
- {
- }
- }
- class Cafe
- {
- private int CurrentWaiters = 0;
- private int CurrentSecurities = 0;
- private int MaxWaiters;
- private int MaxSecurities;
- private Employee[] Employees;
- public Cafe(int maxWaiters, int maxSecurities)
- {
- Employees = new Employee[maxWaiters + maxSecurities];
- MaxWaiters = maxWaiters;
- MaxSecurities = maxSecurities;
- }
- public void NewVisitor(Person person)
- {
- Console.WriteLine("У нас новый посетитель:)");
- Console.WriteLine("{0}, {1}, {2}", person.Name, person.Age, person.GetBehavior());
- switch (person.GetBehavior())
- {
- case PersonBehavior.Aggressive:
- Console.WriteLine("Пожалуйста поспокойнее, {0}!", person.Name);
- RecruitmentSecurity(person);
- break;
- case PersonBehavior.Passive:
- if (person.Age < 18)
- {
- Console.WriteLine("Здравствуй, {0}, у нас кафе для взрослых! \nГде твои родители?", person.Name);
- }
- else
- {
- Console.WriteLine("С вас 30000 рублей, уважаемый, {0}!", person.Name);
- }
- break;
- case PersonBehavior.Polite:
- Console.WriteLine("О, Вы так вежливы, {0}! \nВозможно у меня будет для Вас кое-какое предложение", person.Name);
- RecruitmentWaiter(person);
- break;
- }
- }
- private void RecruitmentSecurity(Person person)
- {
- if(CurrentSecurities < MaxSecurities)
- {
- Security security = new Security(person.Name, person.Age, 20000);
- Employees[GetIndexOfNull(Employees)] = security;
- Console.WriteLine("Поздравляем, {0}! \nВы приняты на должность охранника с зарплатой {1} рублей!", security.Name, security.Salary);
- CurrentSecurities++;
- }
- else
- {
- Console.WriteLine("Охрана, выкиньте {0} из зала!", person.Name);
- }
- }
- private int GetIndexOfNull(Employee[] employees)
- {
- int indexOfNull = -1;
- for(int i = 0; i < employees.Length; i++)
- {
- if(employees[i] == null)
- {
- indexOfNull = i;
- break;
- }
- }
- return indexOfNull;
- }
- private void RecruitmentWaiter(Person person)
- {
- if (CurrentWaiters < MaxWaiters)
- {
- Waiter waiter = new Waiter(person.Name, person.Age, 30000);
- Employees[GetIndexOfNull(Employees)] = waiter;
- Console.WriteLine("{0}, без Вас мы не справимся! \nВы приняты на должность официанта с зарплатой {1} рублей!", waiter.Name, waiter.Salary);
- CurrentWaiters++;
- }
- else
- {
- Console.WriteLine("Ох...Очень жаль, {0}, \nно у нас сейчас нет места для еще одного официанта :(", person.Name);
- }
- }
- }
- public enum PersonBehavior
- {
- Aggressive,
- Passive,
- Polite
- }
- }
- #endregion
Advertisement
Add Comment
Please, Sign In to add comment