PhotoShaman

Small Adventure^^

Jul 19th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 22.07 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. using System.Threading;
  7.  
  8. namespace ConsoleApplication58
  9. {
  10.     class Program
  11.     {
  12.         private static bool isOpen, isHaveHands, isHaveKey, easyGiant, play; //Задача 1
  13.  
  14.         private static int number, x, y;
  15.  
  16.         static void Main(string[] args)
  17.         {
  18.             while (true)
  19.             {
  20.                 play = true;
  21.                 Settings();
  22.                 Loading();
  23.                 StartWindow();
  24.                 ChooseYourComplication();
  25.                 Intro();
  26.                 YourChoice();
  27.                 Console.Clear();
  28.             }
  29.         }
  30.  
  31.         private static void Settings()
  32.         {
  33.             Console.SetWindowSize(100, 40);
  34.             Console.Title = "Небольшое приключение";
  35.         }
  36.  
  37.         private static void Indent()
  38.         {
  39.             for (int i = 0; i < 7; i++)
  40.             {
  41.                 Console.WriteLine("\n");
  42.             }
  43.         }
  44.  
  45.         private static void LoadingBinary()
  46.         {
  47.             Console.ForegroundColor = ConsoleColor.Green;
  48.             for (int i = 0; i < Console.WindowWidth; i++)
  49.             {
  50.                 Random r = new Random();
  51.                 int randomBinary = r.Next(0, 2);
  52.                 Console.Write(randomBinary);
  53.                 Thread.Sleep(20);
  54.             }
  55.         }
  56.  
  57.         private static void LoadingText()
  58.         {
  59.             Console.ResetColor();
  60.             Console.WriteLine();
  61.             Console.WriteLine("█───████─████─████──███─█──█─████".PadLeft(64));
  62.             Thread.Sleep(300);
  63.             Console.WriteLine("█───█──█─█──█─█──██──█──██─█─█   ".PadLeft(64));
  64.             Thread.Sleep(300);
  65.             Console.WriteLine("█───█──█─████─█──██──█──█─██─█─██".PadLeft(64));
  66.             Thread.Sleep(300);
  67.             Console.WriteLine("█───█──█─█──█─█──██──█──█──█─█──█".PadLeft(64));
  68.             Thread.Sleep(300);
  69.             Console.WriteLine("███─████─█──█─████──███─█──█─████".PadLeft(64));
  70.             Console.WriteLine();
  71.         }
  72.  
  73.         private static void Loading()
  74.         {
  75.             Indent();
  76.             LoadingBinary();
  77.             LoadingText();
  78.             LoadingBinary();
  79.             Console.Clear();
  80.             Console.ResetColor();
  81.         }
  82.  
  83.         private static void RandomForegroundColor()
  84.         {
  85.             Random r = new Random();
  86.             int randomBinary = r.Next(0, 8);
  87.             Console.Write(randomBinary);
  88.  
  89.             switch (randomBinary)
  90.             {
  91.                 case 0:
  92.                     Console.ForegroundColor = ConsoleColor.Blue;
  93.                     break;
  94.                 case 1:
  95.                     Console.ForegroundColor = ConsoleColor.Cyan;
  96.                     break;
  97.                 case 2:
  98.                     Console.ForegroundColor = ConsoleColor.Green;
  99.                     break;
  100.                 case 3:
  101.                     Console.ForegroundColor = ConsoleColor.Red;
  102.                     break;
  103.                 case 4:
  104.                     Console.ForegroundColor = ConsoleColor.Yellow;
  105.                     break;
  106.                 case 5:
  107.                     Console.ForegroundColor = ConsoleColor.Magenta;
  108.                     break;
  109.                 case 6:
  110.                     Console.ForegroundColor = ConsoleColor.White;
  111.                     break;
  112.                 case 7:
  113.                     Console.ResetColor();
  114.                     break;
  115.             }
  116.         }
  117.  
  118.         private static void StartWindow()
  119.         {
  120.             Console.CursorVisible = false;
  121.  
  122.             ConsoleKeyInfo cki = new ConsoleKeyInfo();
  123.  
  124.             while (cki.Key != ConsoleKey.Enter)
  125.             {
  126.                 RandomForegroundColor();
  127.  
  128.                 Console.Clear();
  129.  
  130.                 Indent();
  131.  
  132.                 Console.WriteLine("████─████─███─███─███  ███─█──█─███─███─████  ███─████  ███─███─████─████─███".PadLeft(88));
  133.                 Console.WriteLine("█──█─█──█─█───█───█    █───██─█──█──█───█──█  ─█──█──█  █────█──█──█─█──█──█ ".PadLeft(88));
  134.                 Console.WriteLine("████─████─███─███─███  ███─█─██──█──███─████  ─█──█──█  ███──█──████─████──█ ".PadLeft(88));
  135.                 Console.WriteLine("█────█─█──█─────█───█  █───█──█──█──█───█─█   ─█──█──█  ──█──█──█──█─█─█───█ ".PadLeft(88));
  136.                 Console.WriteLine("█────█─█──███─███─███  ███─█──█──█──███─█─█   ─█──████  ███──█──█──█─█─█───█ ".PadLeft(88));
  137.  
  138.                 Thread.Sleep(700);
  139.                 Console.Clear();
  140.  
  141.                 if (Console.KeyAvailable == true)
  142.                 {
  143.                     cki = Console.ReadKey(true);
  144.                 }
  145.             }
  146.  
  147.             Console.CursorVisible = true;
  148.         }
  149.  
  150.         private static void Countinue()
  151.         {
  152.             Console.ForegroundColor = ConsoleColor.Red;
  153.             Console.BackgroundColor = ConsoleColor.White;
  154.             Console.WriteLine("     Продолжить>>");
  155.             Console.ResetColor();
  156.             Console.ReadLine();
  157.             Console.Clear();
  158.         }
  159.  
  160.         private static void ChooseYourComplication()
  161.         {
  162.             Console.ForegroundColor = ConsoleColor.Magenta;
  163.             Console.WriteLine("     Выберите сложность: ");
  164.  
  165.             Console.ForegroundColor = ConsoleColor.Green;
  166.             Console.WriteLine("\n     1 - Легкая\n");
  167.             Console.ForegroundColor = ConsoleColor.Yellow;
  168.             Console.WriteLine("     2 - Средняя\n");
  169.             Console.ForegroundColor = ConsoleColor.Red;
  170.             Console.WriteLine("     3 - Сложная/Невозможная\n");
  171.             Console.ResetColor();
  172.  
  173.             СheckedExceptions(1);
  174.  
  175.             switch (number)
  176.             {
  177.                 case 1:
  178.                     isOpen = true;
  179.                     isHaveHands = true;
  180.                     isHaveKey = true;
  181.                     easyGiant = true;
  182.                     break;
  183.                 case 2:
  184.                     isOpen = false;
  185.                     isHaveHands = true;
  186.                     isHaveKey = false;
  187.                     easyGiant = true;
  188.                     break;
  189.                 case 3:
  190.                     isOpen = false;
  191.                     isHaveHands = true;
  192.                     isHaveKey = false;
  193.                     easyGiant = false;
  194.                     break;
  195.             }
  196.         }
  197.  
  198.         private static void Intro()
  199.         {
  200.             Console.ForegroundColor = ConsoleColor.Red;
  201.             Console.WriteLine();
  202.             Console.BackgroundColor = ConsoleColor.White;
  203.             Console.WriteLine(" ".PadLeft(44) + "Предыстория:".PadRight(56)); //Не захотел делать метод под отцентровку
  204.             Console.ResetColor();
  205.  
  206.             Console.WriteLine("\n     Вы проснулись в странной комнате и чувствуете себя скверно.\n     Что было вчера не помните.");
  207.             Console.WriteLine("\n     Осмотревшись, вы увидели дверь ведущую к выходу из комнаты \n     и доброго великана, который идет к вам.\n");
  208.  
  209.             Countinue();
  210.         }
  211.  
  212.         private static int СheckedExceptions(int script)
  213.         {
  214.             string str = Console.ReadLine();
  215.  
  216.             bool isNum = int.TryParse(str, out number);
  217.  
  218.             if (isNum && (number == 1 || number == 2 || number == 3))
  219.             {
  220.                 Countinue();
  221.             }
  222.             else
  223.             {
  224.                 Console.WriteLine("\nВы ввели неверное значение. Давайте попробуем еще раз!\n");
  225.                 Countinue();
  226.                 Console.Clear();
  227.  
  228.                 if (script == 1)
  229.                 {
  230.                     ChooseYourComplication();
  231.                 }
  232.                 else if (script == 2)
  233.                 {
  234.                     YourChoice();
  235.                 }
  236.                 else
  237.                 {
  238.                     Talk();
  239.                 }
  240.             }
  241.             return number;
  242.         } //Задача 5, 6
  243.  
  244.         private static void YourChoice()
  245.         {
  246.             Console.ForegroundColor = ConsoleColor.Red;
  247.             Console.BackgroundColor = ConsoleColor.White;
  248.             Console.WriteLine("     У вас есть выбор:\n");
  249.  
  250.             Console.ResetColor();
  251.             Console.ForegroundColor = ConsoleColor.Green;
  252.             Console.WriteLine("\n     1 - Подбежать к двери и попробовать сбежать из комнаты");
  253.             Console.ForegroundColor = ConsoleColor.Yellow;
  254.             Console.WriteLine("\n     2 - Уболтать великана");
  255.             Console.ForegroundColor = ConsoleColor.Red;
  256.             Console.WriteLine("\n     3 - Сразится с великаном и отобрать у него ключи от двери");
  257.             Console.ResetColor();
  258.  
  259.             СheckedExceptions(2);
  260.  
  261.             switch (number)
  262.             {
  263.                 case 1:
  264.                     OpenDoor();
  265.                     break;
  266.                 case 2:
  267.                     Talk();
  268.                     break;
  269.                 case 3:
  270.                     Fight();
  271.                     break;
  272.             }
  273.         }
  274.  
  275.         private static void OpenDoor()
  276.         {
  277.             if ((isOpen || isHaveHands && isHaveKey) && play) //Задача 2
  278.             {
  279.                 Console.WriteLine("Вам удалось открыть дверь и пробраться в лабиринт.");
  280.                 Console.ReadKey();
  281.                 Labyrinth();
  282.             }
  283.             else
  284.             {
  285.                 Console.WriteLine("Вам не удалось открыть дверь. Великану не понравилось то что вы убегаите \nи теперь он будет драться с вами.");
  286.                 Console.ReadKey();
  287.                 Fight();
  288.             }
  289.         }
  290.  
  291.         private static void Talk()
  292.         {
  293.             Console.WriteLine("Вы можете что-то сказать великану: ");
  294.             string say = Console.ReadLine();
  295.  
  296.             Console.WriteLine("Великан страдает глухотой. Сколько раз скажите?: ");
  297.             СheckedExceptions(3);
  298.  
  299.             for (int i = 1; i <= number; i++) //Задача 3
  300.             {
  301.                 Console.WriteLine(say);
  302.             }
  303.  
  304.             Countinue();
  305.  
  306.             if (easyGiant)
  307.             {
  308.                 Console.ForegroundColor = ConsoleColor.Red;
  309.                 Console.WriteLine("Великан: ");
  310.                 Console.ResetColor();
  311.  
  312.                 Console.WriteLine("I don't understand you.. Argh.. Go away!");
  313.                 Console.WriteLine("Великан отпустил вас и вы попали в лабиринт.");
  314.                 Console.ReadKey();
  315.                 Labyrinth();
  316.             }
  317.             else
  318.             {
  319.                 Console.ForegroundColor = ConsoleColor.Red;
  320.                 Console.WriteLine("Великан: ");
  321.                 Console.ResetColor();
  322.  
  323.                 Console.WriteLine("I don't anderstand you.. Argh.. And I just eat you!");
  324.                 Console.ReadKey();
  325.                 GameOver();
  326.             }
  327.         }
  328.  
  329.         private static void Fight()
  330.         {
  331.             if (easyGiant)
  332.             {
  333.                 Console.WriteLine("\nВам удалось одолеть великана, забрать ключи от комнаты и уйти в лабиринт.");
  334.                 Console.ReadKey();
  335.                 Labyrinth();
  336.             }
  337.             else
  338.             {
  339.                 Console.WriteLine("Великан оказался слишком сильным. Вы стали основным ингридиентом его супа(");
  340.                 Console.ReadKey();
  341.                 GameOver();
  342.             }
  343.         }
  344.  
  345.         private static void LabyrinthMove()
  346.         {
  347.             x = 44;
  348.             y = 15;
  349.             while (play)
  350.             {
  351.                 LabyrinthMap();
  352.                 Console.SetCursorPosition(x, y);
  353.                 Console.Write("◄►");
  354.  
  355.                 Console.ResetColor();
  356.                 Thread.Sleep(500);
  357.                 ConsoleKey k = Console.ReadKey(true).Key;
  358.  
  359.                 if (k == ConsoleKey.D)
  360.                 {
  361.                     x += 2;
  362.                     if (x > Console.WindowWidth - 1)
  363.                     {
  364.                         x = Console.WindowWidth - 1;
  365.                     }
  366.                 }
  367.                 if (k == ConsoleKey.A)
  368.                 {
  369.                     x -= 2;
  370.                     if (x < 0)
  371.                     {
  372.                         x = 0;
  373.                     }
  374.                 }
  375.                 if (k == ConsoleKey.W)
  376.                 {
  377.                     y -= 1;
  378.                     if (y < 0)
  379.                     {
  380.                         y = 0;
  381.                     }
  382.                 }
  383.                 if (k == ConsoleKey.S)
  384.                 {
  385.                     y += 1;
  386.                     if (y > Console.WindowHeight - 1)
  387.                     {
  388.                         y = Console.WindowHeight - 1;
  389.                     }
  390.                 }
  391.  
  392.                 Console.Clear();
  393.                 Console.SetCursorPosition(x, y);
  394.                 Console.Write("◄►");
  395.  
  396.                 if (x == 48 && y == 30)
  397.                 {
  398.                     YouWon();
  399.                 }
  400.                 else
  401.                 {
  402.                     LabyrinthBorders();
  403.                 }
  404.             }
  405.         }
  406.  
  407.         private static void LabyrinthMap()
  408.         {
  409.             Console.SetCursorPosition(0, 0);
  410.             Indent();
  411.             Console.WriteLine("██████████████▒▒██████████████".PadLeft(60));
  412.             Console.WriteLine("██▒▒▒▒▒▒▒▒▒▒██              ██".PadLeft(60));
  413.             Console.WriteLine("██▒▒▒▒▒▒▒▒▒▒██              ██".PadLeft(60));
  414.             Console.WriteLine("██▒▒▒▒▒▒▒▒▒▒██              ██".PadLeft(60));
  415.             Console.WriteLine("██▒▒▒▒▒▒▒▒▒▒██████████████  ██".PadLeft(60));
  416.             Console.WriteLine("██▒▒▒▒▒▒▒▒▒▒▒▒              ██".PadLeft(60));
  417.             Console.WriteLine("██████▒▒██████████████████  ██".PadLeft(60));
  418.             Console.WriteLine("██▒▒▒▒▒▒▒▒                  ██".PadLeft(60));
  419.             Console.WriteLine("██▒▒██████                  ██".PadLeft(60));
  420.             Console.WriteLine("██▒▒▒▒▒▒██                  ██".PadLeft(60));
  421.             Console.WriteLine("██▒▒▒▒▒▒██  ██████████████  ██".PadLeft(60));
  422.             Console.WriteLine("██▒▒▒▒▒▒██  ▒▒▒▒██          ██".PadLeft(60));
  423.             Console.WriteLine("██████████  ▒▒▒▒██          ██".PadLeft(60));
  424.             Console.WriteLine("██▒▒▒▒▒▒██  ▒▒▒▒██          ██".PadLeft(60));
  425.             Console.WriteLine("██▒▒▒▒▒▒██  ██████          ██".PadLeft(60));
  426.             Console.WriteLine("██▒▒▒▒▒▒▒▒                  ██".PadLeft(60));
  427.             Console.WriteLine("██████████████████  ██████████".PadLeft(60));
  428.             Console.SetCursorPosition(48, 30);
  429.             Console.ForegroundColor = ConsoleColor.Green;
  430.             Console.WriteLine("██");
  431.         }
  432.  
  433.         private static void LabyrinthBorders()
  434.         {
  435.             if (y == 30 || x == 30 || x == 58 || y == 14 || (x <= 42 && y <= 20)
  436.                 || (x <= 38 && y <= 30) || ((x <= 46 && x >= 42) && (y <= 28 && y >= 24))
  437.                 || ((y == 18 || y == 20 || y == 24) && (x >= 42 && x <= 54)))
  438.             {
  439.                 Console.Clear();
  440.                 Console.ForegroundColor = ConsoleColor.Red;
  441.                 Console.WriteLine("\n     Вы погибли");
  442.                 Console.ResetColor();
  443.                 Console.WriteLine();
  444.                 Countinue();
  445.                 GameOver();
  446.             }
  447.         }
  448.  
  449.         private static void Labyrinth()
  450.         {
  451.             Console.Clear();
  452.             Console.CursorVisible = false;
  453.             LabyrinthMove();
  454.             Console.CursorVisible = true;
  455.         } //Задача 7
  456.  
  457.         private static void GameOver()
  458.         {
  459.             Console.Clear();
  460.             Console.ForegroundColor = ConsoleColor.Red;
  461.  
  462.             Indent();
  463.  
  464.             Console.WriteLine("████─████─█───█─███  ████─█─█─███─████".PadLeft(66));
  465.             Console.WriteLine("█────█──█─██─██─█    █──█─█─█─█───█──█".PadLeft(66));
  466.             Console.WriteLine("█─██─████─█─█─█─███  █──█─█─█─███─████".PadLeft(66));
  467.             Console.WriteLine("█──█─█──█─█───█─█    █──█─███─█───█─█ ".PadLeft(66));
  468.             Console.WriteLine("████─█──█─█───█─███  ████──█──███─█─█ ".PadLeft(66));
  469.             PlayAgain();
  470.         }
  471.  
  472.         private static void YouWon()
  473.         {
  474.             Console.Clear();
  475.             Console.ForegroundColor = ConsoleColor.Green;
  476.  
  477.             Indent();
  478.  
  479.             Console.WriteLine("██─██─████─█─█  █───█─████─█──█".PadLeft(65));
  480.             Console.WriteLine("─███──█──█─█─█  █───█─█──█─██─█".PadLeft(65));
  481.             Console.WriteLine("──█───█──█─█─█  █─█─█─█──█─█─██".PadLeft(65));
  482.             Console.WriteLine("──█───█──█─█─█  █████─█──█─█──█".PadLeft(65));
  483.             Console.WriteLine("──█───████─███  ─█─█──████─█──█".PadLeft(65));
  484.             PlayAgain();
  485.         }
  486.  
  487.         private static void PlayAgain()
  488.         {
  489.             Indent();
  490.  
  491.             Console.WriteLine("\n     Сыграем еще?  Y/N"); //Задача 4
  492.  
  493.             string str = Console.ReadLine();
  494.             string answer = str.ToLower();
  495.  
  496.             if (answer == "y")
  497.             {
  498.                 play = false;
  499.                 Console.Clear();
  500.             }
  501.             else if (answer == "n")
  502.             {
  503.                 CreatedBy();
  504.                 System.Environment.Exit(1);
  505.             }
  506.             else
  507.             {
  508.                 Console.WriteLine("Вы ввели неверное значение. Давайте попробуем еще раз!");
  509.                 Console.ReadKey();
  510.                 Console.Clear();
  511.                 PlayAgain();
  512.             }
  513.         }
  514.  
  515.         private static void CreatedBy()
  516.         {
  517.             Console.Clear();
  518.             Indent();
  519.             Console.ForegroundColor = ConsoleColor.Cyan;
  520.             Console.WriteLine("████─████──███─████─████      ████─████─███─███─█───█    █─█─█─█─█─█──█─████─████ ".PadLeft(90));
  521.             Console.WriteLine("█──█─█──██──█──█──█─█──█─█    █──█─█──█──█──█───██─██    █████─█─█─█─█──█──█─█──██".PadLeft(90));
  522.             Console.WriteLine("████─████───█──█──█─████      ████─████──█──███─█─█─█    ─███──███─██───█──█─████ ".PadLeft(90));
  523.             Console.WriteLine("█──█─█──██──█──█──█─█────█    █──█─█─────█──█───█───█    █████───█─█─█──█──█─█──██".PadLeft(90));
  524.             Console.WriteLine("█──█─████───█──████─█         █──█─█─────█──███─█───█    █─█─█─███─█──█─████─████ ".PadLeft(90));
  525.             Thread.Sleep(1500);
  526.         }
  527.     }
  528. }
Advertisement
Add Comment
Please, Sign In to add comment