Benjail

5.6

Sep 15th, 2019
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.99 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Гладиаторские_бои
  4. {
  5.     class gladiator
  6.     {
  7.         public string name { get; private set; }
  8.         public int health { get; private set;}
  9.         public int uron { get; private set;}
  10.         string kontur1= "\\____/ " + "\n|*_ *|\n ____\n|    |\n ____\n/    \\\n";
  11.         string kontur21;
  12.         string kontur22;
  13.        
  14.         public gladiator(string inputname,int inputhealth, int inputuron,string inputkontur21,string inputkontur22)
  15.         {
  16.              name=inputname;
  17.              health=inputhealth;
  18.              uron=inputuron;
  19.              kontur21= inputkontur21;                                  
  20.              kontur22= inputkontur22;                                              
  21.         }
  22.         public void drawgladiator(int inputX, int inputY,string direction)
  23.         {
  24.             int X = inputX;
  25.             int Y = inputY;
  26.             switch (direction)
  27.             {
  28.                 case "right":
  29.                     string[] array1 = kontur21.Split("\n"); //разбиваем строку игрока на массив элементов
  30.                     for (int i = 0; i < array1.Length; i++)
  31.                     {
  32.                         Console.SetCursorPosition(X, Y + i);
  33.                         Console.Write(array1[i]);                      
  34.                     }
  35.                     break;                                                
  36.                 case "left":
  37.                     string[] array2 = kontur22.Split("\n"); //разбиваем строку игрока на массив элементов
  38.                     for (int i = 0; i < array2.Length; i++)
  39.                     {
  40.                         Console.SetCursorPosition(X, Y + i);            
  41.                         Console.Write(array2[i]);
  42.                     }
  43.                     break;
  44.                 case "0":
  45.                     string[] array = kontur1.Split("\n"); //разбиваем строку игрока на массив элементов
  46.                     for (int i = 0; i < array.Length; i++)
  47.                     {
  48.                         Console.SetCursorPosition(X, Y + i);
  49.                         Console.Write(array[i]);
  50.                     }
  51.                     break;
  52.                 default:
  53.                     break;
  54.             }
  55.            
  56.         }
  57.         public void showstats()
  58.         {
  59.             Console.WriteLine("Имя: " + name + "\nHP: " + health + "\nДамаг: " + uron);
  60.         }
  61.         public void suffer(gladiator gladiator)
  62.         {
  63.             health -= gladiator.uron;
  64.         }
  65.     }
  66.     class arena
  67.     {
  68.         gladiator[] gladiators = new gladiator[0];
  69.         //
  70.         public arena(gladiator[] inputgladiators)
  71.         {
  72.             gladiators = new gladiator[inputgladiators.Length];
  73.             for (int i = 0; i < gladiators.Length; i++)
  74.             {
  75.                 gladiators[i] = inputgladiators[i];
  76.             }
  77.         }
  78.         public void deletegladiator(int num1)
  79.         {
  80.             gladiator[] temp = new gladiator[gladiators.Length-1];
  81.             for (int i = num1+1; i < temp.Length; i++)
  82.             {
  83.                 gladiators[i - 1] = gladiators[i];//после символа с индексом удаления, мы присваиваем предыдущим элементам значение последующих,смещая элементы влево на 1
  84.             }
  85.             for (int i = 0; i < temp.Length; i++)
  86.             {
  87.                 temp[i] = gladiators[i]; //и затем, когда нужные элементы умещаются в длину-1, перемещаем их в temp
  88.             }
  89.             gladiators = temp;
  90.         }
  91.         public void bitva()
  92.         {
  93.             gladiator[] igroki = new gladiator[2];
  94.             Console.ForegroundColor = ConsoleColor.Yellow;
  95.             Console.WriteLine("Выберите героя: ");
  96.             Console.ForegroundColor = ConsoleColor.White;
  97.             for (int i = 0; i < gladiators.Length; i++)    
  98.             {
  99.                 Console.Write(i + 1 + ") ");
  100.                 gladiators[i].showstats();
  101.                 gladiators[i].drawgladiator(25,i*7,"right");
  102.                 Console.WriteLine();
  103.             }
  104.             Console.Write("Герой 1: ");
  105.             int num1 = Convert.ToInt32(Console.ReadLine()) - 1;
  106.             igroki[0] = gladiators[num1];
  107.             deletegladiator(num1);
  108.             Console.Clear();
  109.             for (int i = 0; i < gladiators.Length; i++)
  110.             {
  111.                 Console.Write(i + 1 + ") ");
  112.                 gladiators[i].showstats();
  113.                 gladiators[i].drawgladiator(25, i * 7, "right");
  114.                 Console.WriteLine();
  115.             }
  116.             Console.WriteLine();
  117.             Console.Write("Герой 2: ");                
  118.             igroki[1] = gladiators[Convert.ToInt32(Console.ReadLine()) - 1];
  119.             Console.WriteLine();
  120.             Console.Clear();
  121.             Console.WriteLine("Битва начинается!");
  122.             Console.ReadKey();
  123.             Console.Clear();
  124.             while (igroki[0].health>0 & igroki[1].health > 0)
  125.             {
  126.                 igroki[0].showstats();                      
  127.                 igroki[1].showstats();
  128.                 igroki[0].drawgladiator(20,20,"0");
  129.                 igroki[1].drawgladiator(55, 20, "0");
  130.                 Console.ReadKey();                          
  131.                 Console.ForegroundColor = ConsoleColor.Red;
  132.                 igroki[0].drawgladiator(20, 20, "right");
  133.                 igroki[1].drawgladiator(55, 20, "left");
  134.                 Console.ForegroundColor = ConsoleColor.White;
  135.                 igroki[0].suffer(igroki[1]);
  136.                 igroki[1].suffer(igroki[0]);
  137.                 Console.ReadKey();
  138.                 Console.Clear();                        
  139.             }
  140.             if(igroki[0].health> igroki[1].health)
  141.             {
  142.                 Console.WriteLine(igroki[0].name + " - Победитель!");
  143.                 Console.ForegroundColor = ConsoleColor.Green;                
  144.                 igroki[0].drawgladiator(0, 5, "right");
  145.                 Console.ForegroundColor = ConsoleColor.White;
  146.             }
  147.             if (igroki[1].health > igroki[0].health)
  148.             {
  149.                 Console.WriteLine(igroki[1].name + " - Победитель!");
  150.                 Console.ForegroundColor = ConsoleColor.Green;
  151.                 igroki[1].drawgladiator(0, 5, "right");
  152.                 Console.ForegroundColor = ConsoleColor.White;
  153.                
  154.             }
  155.             if (igroki[1].health == igroki[0].health)
  156.             {
  157.                 Console.ForegroundColor = ConsoleColor.Green;
  158.                 Console.WriteLine("Ничья");
  159.                 Console.ForegroundColor = ConsoleColor.White;
  160.             }
  161.         }                                              
  162.     }                                              
  163.     class Program                                                    
  164.     {
  165.         static void Main(string[] args)
  166.         {
  167.            
  168.             bool open = true;
  169.             while(open)
  170.             {
  171.                 gladiator[] gladiators = {
  172.                 new gladiator("Кинжальщик", 100, 5, "\\____/ " + "\n|*_ *|\n ____\n|    |____\n ____\n/    \\\n", "    \\____/ " + "\n    |*_ *|\n     ____\n____|    |\n     ____\n    /    \\\n"),
  173.                 new gladiator("Лучник",100,7, "\\____/ " + "\n|*_ *|\n ____\n|    |____\n ____\n/    \\\n", "    \\____/ " + "\n    |*_ *|\n     ____\n____|    |\n     ____\n    /    \\\n"),
  174.                 new gladiator("Меченосец", 100, 12, "\\____/ " + "\n|*_ *|\n ____\n|    |____\n ____\n/    \\\n", "    \\____/ " + "\n    |*_ *|\n     ____\n____|    |\n     ____\n    /    \\\n"),
  175.                 new gladiator("Рукопашник",100,2, "\\____/ " + "\n|*_ *|\n ____\n|    |____\n ____\n/    \\\n", "    \\____/ " + "\n    |*_ *|\n     ____\n____|    |\n     ____\n    /    \\\n"),
  176.                 new gladiator("Владелец картечи",100,7, "\\____/ " + "\n|*_ *|\n ____\n|    |____\n ____\n/    \\\n", "    \\____/ " + "\n    |*_ *|\n     ____\n____|    |\n     ____\n    /    \\\n")
  177.                 };
  178.                 Console.WriteLine("Поиграем?\n1.Да\n2.Выход");
  179.                 string sw=Console.ReadLine();
  180.                 switch (sw)
  181.                 {
  182.                     case "1":
  183.                         Console.Clear();
  184.                         arena arena1 = new arena(gladiators);
  185.                         arena1.bitva();
  186.                         break;
  187.                     case "2":
  188.                         open = false;
  189.                         break;
  190.                     default:
  191.                         break;
  192.                 }
  193.                
  194.                 Console.ReadLine();
  195.                 Console.Clear();
  196.             }        
  197.         }
  198.     }
  199. }
Advertisement
Add Comment
Please, Sign In to add comment