redSkywalker

Задача 2.4.1.2

Feb 11th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.03 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Zadacha_1
  8. {
  9.     class QuestionaryForNewAdeptsItem
  10.     {
  11.         private string _question;
  12.         private string[] _answerVariation;
  13.  
  14.         public string Question
  15.         {
  16.             get { return _question; }
  17.             set { _question = value; }
  18.         }
  19.         public string[] AnswerVariation
  20.         {
  21.             get { return _answerVariation; }
  22.             set { _answerVariation = value; }
  23.         }
  24.  
  25.         public QuestionaryForNewAdeptsItem(string quest, string[] answers)
  26.         {
  27.             Question = quest;
  28.             AnswerVariation = answers;
  29.            
  30.         }
  31.  
  32.     }
  33.  
  34.     class Candidate
  35.     {
  36.         private string _whoIam;
  37.         private string _whatIwant;
  38.         private string _myOccupation;
  39.  
  40.         public string WhoIam
  41.         {
  42.             get { return _whoIam; }
  43.             set { _whoIam = value; }
  44.         }
  45.         public string WhatIwant
  46.         {
  47.             get { return _whatIwant; }
  48.             set { _whatIwant = value; }
  49.         }
  50.         public string MyOccupation
  51.         {
  52.             get { return _myOccupation; }
  53.             set { _myOccupation = value; }
  54.         }
  55.  
  56.         public Candidate()
  57.         {
  58.  
  59.         }
  60.  
  61.     }
  62.  
  63.     class Door
  64.     {
  65.         private bool _isOpen;
  66.  
  67.         public bool IsOpen
  68.         {
  69.             get { return _isOpen; }
  70.             set { _isOpen = value; }
  71.         }
  72.  
  73.         public Door()
  74.         {
  75.             IsOpen = false;
  76.         }
  77.     }
  78.  
  79.     class Interview
  80.     {
  81.         public Interview()
  82.         {
  83.  
  84.         }
  85.  
  86.         public void GenerateDialog(QuestionaryForNewAdeptsItem[] Items, Door[] doors)
  87.         {
  88.             Candidate adept = new Candidate();
  89.             for (int i = 0; i < Items.Length; i++)
  90.             {
  91.                 int selectionIndex = 0;
  92.                 var q = Items[i];
  93.                 Console.WriteLine(q.Question);                
  94.                 PrintVariants(q);            
  95.                 selectionIndex = CheckingValue();
  96.  
  97.                 if (i == 0)
  98.             {
  99.                 adept.WhoIam = q.AnswerVariation[selectionIndex];
  100.             }
  101.  
  102.             if (i == 1)
  103.             {
  104.                 adept.WhatIwant = q.AnswerVariation[selectionIndex];
  105.             }
  106.  
  107.             if (i == 2)
  108.                 {
  109.                     adept.MyOccupation = q.AnswerVariation[selectionIndex];
  110.                     if (CheckingNewCandidate(adept))
  111.                     {
  112.                         Console.WriteLine("Отлично! Ты-то нам и нужен! Эй, Джонни, открой дверь - добро пожаловать в Орден, брат!");
  113.                         doors[i].IsOpen = true;
  114.                         Console.ReadKey();
  115.                     }
  116.                     else
  117.                     {
  118.                         Console.WriteLine("Ты не подходишь Ордену!");
  119.                         Console.ReadKey();
  120.                     }
  121.                 }
  122.             }
  123.         }
  124.  
  125.         public bool CheckingNewCandidate(Candidate newCandidate)
  126.         {
  127.             bool isNeo = false;
  128.             if(newCandidate.MyOccupation.Equals("Я отличный воин") && newCandidate.WhatIwant.Equals("Найти боевых товарищей"))
  129.             {
  130.                 isNeo = true;
  131.             }
  132.             return isNeo;
  133.         }
  134.  
  135.         public int CheckingValue()
  136.         {
  137.             int Index = 0;
  138.             try
  139.             {    
  140.                 int Value = Int32.Parse(Console.ReadLine());
  141.                 if (Value <= 2 && Value >= 0)
  142.                 {
  143.                     Index = Value;
  144.                 }
  145.                 else
  146.                 {
  147.                     Console.WriteLine("Введите значение от 0 до 2!");
  148.                     CheckingValue();
  149.                 }
  150.             }
  151.             catch(Exception)
  152.             {
  153.                 Console.WriteLine("Введите значение от 0 до 2!");
  154.                 CheckingValue();
  155.             }
  156.  
  157.             return Index;
  158.         }
  159.  
  160.  
  161.         public void PrintVariants(QuestionaryForNewAdeptsItem newItem)
  162.         {
  163.             for (int j = 0; j < newItem.AnswerVariation.Length; j++)
  164.             {
  165.                 Console.WriteLine("[{0}]>{1}", j, newItem.AnswerVariation[j]);
  166.             }
  167.         }
  168.     }
  169.  
  170.    
  171.  
  172.     class Program
  173.     {
  174.  
  175.         static void Main(string[] args)
  176.         {
  177.             Interview Dialog = new Interview();            
  178.             Door[] doors = new Door[] { new Door(), new Door(), new Door() };
  179.  
  180.             Console.WriteLine("Совершенно очевидно, что мы не берём в наш орден кого попало. Поэтому заполни вот эту анкету, " +
  181.                                   "и мы примем решение, брать тебя или нет");
  182.  
  183.             string[] answers1 = new string[] { "Человек", "Брандлмуха", "Кхаджит" };
  184.             QuestionaryForNewAdeptsItem firstQuest = new QuestionaryForNewAdeptsItem("Кто вы?", answers1);
  185.             string[] answers2 = new string[] { "Победить Аразота", "Стать богатым", "Найти боевых товарищей" };
  186.             QuestionaryForNewAdeptsItem secondQuest = new QuestionaryForNewAdeptsItem("Что вы хотите?", answers2);
  187.             string[] answers3 = new string[] { "Я отличный воин", "Я добротный маг", "Я могу работать в кузнице" };
  188.             QuestionaryForNewAdeptsItem thirdQuest = new QuestionaryForNewAdeptsItem("Чем вы можете помочь ордену?", answers3);            
  189.  
  190.             QuestionaryForNewAdeptsItem[] questionary = new QuestionaryForNewAdeptsItem[] { firstQuest, secondQuest, thirdQuest };
  191.             Dialog.GenerateDialog(questionary, doors);
  192.            
  193.         }
  194.     }
  195. }
Advertisement
Add Comment
Please, Sign In to add comment