Advertisement
Garloon

5.6

Sep 15th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 15.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7.  
  8. namespace CSLight
  9. {
  10.     class Menu
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             Fighter[] Fighters =
  15.             {
  16.                 new Fighter("РЕКЕТИР", 95, 0, 20, true),
  17.                 new Fighter("БАНДИТ", 95, 3, 20, true),
  18.                 new Fighter("ГОПНИК", 95, 5, 20, true),
  19.                 new Fighter("БОКСЕР", 95, 7, 20, true),
  20.                 new Fighter("ПЕШЕХОД", 95, 9, 20, true)
  21.             };
  22.  
  23.             Fighter LeftFighter = new Fighter();
  24.             Fighter RightFighter = new Fighter();
  25.             Fight Fight = new Fight(LeftFighter, RightFighter);
  26.             Renderer renderer = new Renderer(LeftFighter, RightFighter, Fight);
  27.            
  28.  
  29.             bool preparation = true, isFight;
  30.  
  31.             Console.SetWindowSize(100, 30);
  32.             Console.CursorVisible = false;
  33.  
  34.             while (preparation == true)
  35.             {
  36.                 Console.Clear();
  37.                 renderer.ShowAllFighters(ref Fighters);
  38.                 renderer.ShowArena();
  39.                 Console.SetCursorPosition(1, 10);
  40.                 Console.ForegroundColor = ConsoleColor.Cyan;
  41.                 Console.Write("Имя первого бойца: ");
  42.                 string leftFighter = Console.ReadLine().ToUpper();
  43.  
  44.                 Console.SetCursorPosition(65, 10);
  45.                 Console.ForegroundColor = ConsoleColor.Cyan;
  46.                 Console.Write("Имя второго бойца: ");
  47.                 string rightFighter = Console.ReadLine().ToUpper();
  48.                 Console.ResetColor();
  49.  
  50.                 isFight = true;
  51.                 while (isFight == true)
  52.                 {
  53.                     renderer.ShowFight(isFight, ref Fighters, leftFighter, rightFighter);
  54.  
  55.                     if (LeftFighter.IsLeave == false)
  56.                     {
  57.                         isFight = false;
  58.                     }
  59.                     else if (RightFighter.IsLeave == false)
  60.                     {
  61.                         isFight = false;
  62.                     }
  63.                 }
  64.                 if (Fighters.Length == 1)
  65.                 {
  66.                     preparation = false;
  67.                 }
  68.             }
  69.             Console.Clear();
  70.             Console.ForegroundColor = ConsoleColor.Green;
  71.             Console.SetCursorPosition(40, 10);
  72.             Console.WriteLine("Победитель: " + Fighters[0].FighterName);
  73.             Console.ReadKey();
  74.         }
  75.     }
  76.     class Fighter
  77.     {
  78.         public string FighterName;
  79.         public float Health;
  80.         public float Armor;
  81.         public float Damage;
  82.         public bool IsLeave;
  83.  
  84.         public Fighter() { }
  85.         public Fighter(string fighterName, float health, float armor, float damage, bool isLeave)
  86.         {
  87.             FighterName = fighterName;
  88.             Health = health;
  89.             Armor = armor;
  90.             Damage = damage;
  91.             IsLeave = isLeave;
  92.         }
  93.         public void ShowFighter(int posX, int posY)
  94.         {
  95.             Console.ForegroundColor = ConsoleColor.Yellow;
  96.             Console.SetCursorPosition(posX, posY);
  97.             Console.WriteLine("Боец: " + FighterName);
  98.             Console.SetCursorPosition(posX, ++posY);
  99.             Console.WriteLine("Здоровье: " + Health);
  100.             Console.SetCursorPosition(posX, ++posY);
  101.             Console.WriteLine("Броня: " + Armor);
  102.             Console.SetCursorPosition(posX, ++posY);
  103.             Console.WriteLine("Урон: " + Damage);
  104.         }
  105.     }
  106.  
  107.     class Fight
  108.     {
  109.         public Fighter LeftFighter;
  110.         public Fighter RightFighter;
  111.  
  112.         public Fight(Fighter leftFighter, Fighter rightFighter)
  113.         {
  114.             LeftFighter = leftFighter;
  115.             RightFighter = rightFighter;
  116.         }
  117.         public void IsDead(ref Fighter[] fighters)
  118.         {
  119.             foreach (Fighter figter in fighters)
  120.             {
  121.                 if (figter.IsLeave == false)
  122.                 {
  123.                     int index = 0;
  124.  
  125.                     for (int i = 0; i < fighters.Length; ++i)
  126.                     {
  127.                         if (fighters[i].IsLeave == false)
  128.                         {
  129.                             index = i;
  130.                             break;
  131.                         }
  132.                     }
  133.                     Fighter[] tempFigters = new Fighter[fighters.Length - 1];
  134.                     for (int i = 0, j = 0; i < tempFigters.Length; ++i, ++j)
  135.                     {
  136.                         if (j == index)
  137.                             ++j;
  138.  
  139.                         tempFigters[i] = fighters[j];
  140.                     }
  141.                     fighters = tempFigters;
  142.                 }
  143.             }
  144.         }
  145.         public void TakingDamageLeftFighter(Fighter leftFighter, Fighter rightFighter)
  146.         {
  147.             leftFighter.Health -= (rightFighter.Damage - leftFighter.Armor);
  148.         }
  149.         public void TakingDamageRightFighter(Fighter leftFighter, Fighter rightFighter)
  150.         {
  151.             rightFighter.Health -= (leftFighter.Damage - rightFighter.Armor);
  152.         }
  153.     }
  154.    
  155.     class Renderer
  156.     {
  157.         public Fighter LeftFighter;
  158.         public Fighter RightFighter;
  159.         public Fight Fight;
  160.  
  161.         public bool IsFight = true;
  162.         public char[,] Arena =
  163.         {
  164.             {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',},
  165.             {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|',},
  166.             {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|',},
  167.             {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|',},
  168.             {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|',},
  169.             {'=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=',}
  170.         };
  171.  
  172.         public char[,] LeftFighterAppearance =
  173.         {
  174.             {' ','0',' ',' '},
  175.             {'/','|','-','o'},
  176.             {'/',' ','\\',' '}
  177.         };
  178.         public char[,] RightFighterAppearance =
  179.         {
  180.             {' ',' ','0',' '},
  181.             {'o','-','|','\\'},
  182.             {' ','/',' ','\\'}
  183.         };
  184.         public char[,] ClearFighter =
  185.             {
  186.             {' ',' ',' ',' '},
  187.             {' ',' ',' ',' '},
  188.             {' ',' ',' ',' '}
  189.         };
  190.  
  191.         public Renderer(Fighter leftFighter, Fighter rightFighter, Fight fight)
  192.         {
  193.             LeftFighter = leftFighter;
  194.             RightFighter = rightFighter;
  195.             Fight = fight;
  196.         }
  197.  
  198.         public void ShowArena()
  199.         {
  200.             int posY = 7;
  201.             Console.SetCursorPosition(31, posY);
  202.             for (int i = 0; i < Arena.GetLength(0); i++)
  203.             {
  204.                 for(int j = 0; j < Arena.GetLength(1); j++)
  205.                 {
  206.                     Console.Write(Arena[i, j]);
  207.                 }
  208.                 Console.WriteLine();
  209.                 Console.SetCursorPosition(31, ++posY);
  210.             }
  211.         }
  212.  
  213.         public void ShowFight(bool isFight, ref Fighter[] fighters, string leftFighter, string rightFighter)
  214.         {
  215.             foreach (Fighter fighter in fighters)
  216.             {
  217.                 if (leftFighter == fighter.FighterName)
  218.                     LeftFighter = fighter;
  219.                 else if (leftFighter != fighter.FighterName)
  220.                 {
  221.                     isFight = false;
  222.                 }
  223.  
  224.                 if (rightFighter != leftFighter && rightFighter == fighter.FighterName)
  225.                     RightFighter = fighter;
  226.                 else if (rightFighter != fighter.FighterName)
  227.                 {
  228.                     isFight = false;
  229.                 }
  230.             }
  231.  
  232.             while (LeftFighter.IsLeave != false || RightFighter.IsLeave != false)
  233.             {
  234.                 Console.SetCursorPosition(39, 5);
  235.                 Console.ForegroundColor = ConsoleColor.Red;
  236.                 Console.WriteLine("<<<< БОЙ >>>>");
  237.  
  238.                 Console.SetCursorPosition(33, 13);
  239.                 Console.ForegroundColor = ConsoleColor.Green;
  240.                 Console.Write(LeftFighter.FighterName);
  241.  
  242.                 Console.SetCursorPosition(33, 14);
  243.                 Console.Write(LeftFighter.Health);
  244.  
  245.                 Console.ForegroundColor = ConsoleColor.Cyan;
  246.                 Console.SetCursorPosition(44, 13);
  247.                 Console.Write("VS");
  248.  
  249.                 Console.ForegroundColor = ConsoleColor.Green;
  250.                 Console.SetCursorPosition(53, 13);
  251.                 Console.Write(RightFighter.FighterName);
  252.  
  253.                 Console.SetCursorPosition(53, 14);
  254.                 Console.Write(RightFighter.Health);
  255.                 Console.ResetColor();
  256.  
  257.                 ShowLeftFighter();
  258.                 ShowRightFighter();
  259.                 Thread.Sleep(1000);
  260.  
  261.                 ClearRightFighter();
  262.                 AttackRightFighter();
  263.                 Fight.TakingDamageLeftFighter(LeftFighter, RightFighter);
  264.                 Console.ForegroundColor = ConsoleColor.Green;
  265.                 Console.SetCursorPosition(33, 14);
  266.                 Console.Write(LeftFighter.Health);
  267.                 Console.ResetColor();
  268.                 Thread.Sleep(500);
  269.                 ClearAttackRightFighter();
  270.                 ShowRightFighter();
  271.  
  272.                 if (LeftFighter.Health <= 0)
  273.                 {
  274.                     LeftFighter.IsLeave = false;
  275.                     break;
  276.                 }
  277.  
  278.                 Thread.Sleep(1000);
  279.                 ClearLeftFighter();
  280.                 AttackLeftFighter();
  281.                 Fight.TakingDamageRightFighter(LeftFighter, RightFighter);
  282.                 Console.ForegroundColor = ConsoleColor.Green;
  283.                 Console.SetCursorPosition(53, 14);
  284.                 Console.Write(RightFighter.Health);
  285.                 Console.ResetColor();
  286.                 Thread.Sleep(500);
  287.                 ClearAttackLeftFighter();
  288.                 ShowLeftFighter();
  289.  
  290.                 if (RightFighter.Health <= 0)
  291.                 {
  292.                     RightFighter.IsLeave = false;
  293.                     break;
  294.                 }
  295.             }
  296.             Fight.IsDead(ref fighters);
  297.         }
  298.  
  299.         public void ShowAllFighters(ref Fighter[] fighters)
  300.         {
  301.             int posX = 0, posY = 0;
  302.             foreach (Fighter fighter in fighters)
  303.             {
  304.                 fighter.ShowFighter(posX, posY);
  305.                 posX += 20;
  306.                 posY = 0;
  307.             }
  308.             Console.ResetColor();
  309.         }
  310.  
  311.         public void ShowLeftFighter()
  312.         {
  313.             int posY = 9;
  314.             Console.ForegroundColor = ConsoleColor.Red;
  315.             Console.SetCursorPosition(36, posY);
  316.  
  317.             if (LeftFighter.IsLeave != false)
  318.             {
  319.                 for (int i = 0; i < LeftFighterAppearance.GetLength(0); i++)
  320.                 {
  321.                     for (int j = 0; j < LeftFighterAppearance.GetLength(1); j++)
  322.                     {
  323.                         Console.Write(LeftFighterAppearance[i, j]);
  324.                     }
  325.                     Console.WriteLine();
  326.                     Console.SetCursorPosition(36, ++posY);
  327.                 }
  328.             }
  329.             Console.ResetColor();
  330.         }
  331.         public void ClearLeftFighter()
  332.         {
  333.             int posY = 9;
  334.             Console.ForegroundColor = ConsoleColor.Red;
  335.             Console.SetCursorPosition(36, posY);
  336.             for (int i = 0; i < ClearFighter.GetLength(0); i++)
  337.             {
  338.                 for (int j = 0; j < ClearFighter.GetLength(1); j++)
  339.                 {
  340.                     Console.Write(ClearFighter[i, j]);
  341.                 }
  342.                 Console.WriteLine();
  343.                 Console.SetCursorPosition(36, ++posY);
  344.             }
  345.         }
  346.         public void AttackLeftFighter()
  347.         {
  348.             int posY = 9;
  349.             Console.ForegroundColor = ConsoleColor.Red;
  350.             Console.SetCursorPosition(48, posY);
  351.  
  352.             if (LeftFighter.IsLeave != false)
  353.             {
  354.                 for (int i = 0; i < LeftFighterAppearance.GetLength(0); i++)
  355.                 {
  356.                     for (int j = 0; j < LeftFighterAppearance.GetLength(1); j++)
  357.                     {
  358.                         Console.Write(LeftFighterAppearance[i, j]);
  359.                     }
  360.                     Console.WriteLine();
  361.                     Console.SetCursorPosition(48, ++posY);
  362.                 }
  363.             }
  364.             Console.ResetColor();
  365.         }
  366.         public void ClearAttackLeftFighter()
  367.         {
  368.             int posY = 9;
  369.             Console.ForegroundColor = ConsoleColor.Red;
  370.             Console.SetCursorPosition(48, posY);
  371.             for (int i = 0; i < ClearFighter.GetLength(0); i++)
  372.             {
  373.                 for (int j = 0; j < ClearFighter.GetLength(1); j++)
  374.                 {
  375.                     Console.Write(ClearFighter[i, j]);
  376.                 }
  377.                 Console.WriteLine();
  378.                 Console.SetCursorPosition(48, ++posY);
  379.             }
  380.         }
  381.  
  382.         public void ShowRightFighter()
  383.         {
  384.             int posY = 9;
  385.             Console.ForegroundColor = ConsoleColor.Blue;
  386.             Console.SetCursorPosition(53, posY);
  387.             if (RightFighter.IsLeave != false)
  388.             {
  389.                 for (int i = 0; i < RightFighterAppearance.GetLength(0); i++)
  390.                 {
  391.                     for (int j = 0; j < RightFighterAppearance.GetLength(1); j++)
  392.                     {
  393.                         Console.Write(RightFighterAppearance[i, j]);
  394.                     }
  395.                     Console.WriteLine();
  396.                     Console.SetCursorPosition(53, ++posY);
  397.                 }
  398.             }
  399.             Console.ResetColor();
  400.         }
  401.         public void ClearRightFighter()
  402.         {
  403.             int posY = 9;
  404.             Console.ForegroundColor = ConsoleColor.Red;
  405.             Console.SetCursorPosition(53, posY);
  406.             for (int i = 0; i < ClearFighter.GetLength(0); i++)
  407.             {
  408.                 for (int j = 0; j < ClearFighter.GetLength(1); j++)
  409.                 {
  410.                     Console.Write(ClearFighter[i, j]);
  411.                 }
  412.                 Console.WriteLine();
  413.                 Console.SetCursorPosition(53, ++posY);
  414.             }
  415.         }
  416.         public void AttackRightFighter()
  417.         {
  418.             int posY = 9;
  419.             Console.ForegroundColor = ConsoleColor.Blue;
  420.             Console.SetCursorPosition(41, posY);
  421.             if (RightFighter.IsLeave != false)
  422.             {
  423.                 for (int i = 0; i < RightFighterAppearance.GetLength(0); i++)
  424.                 {
  425.                     for (int j = 0; j < RightFighterAppearance.GetLength(1); j++)
  426.                     {
  427.                         Console.Write(RightFighterAppearance[i, j]);
  428.                     }
  429.                     Console.WriteLine();
  430.                     Console.SetCursorPosition(41, ++posY);
  431.                 }
  432.             }
  433.             Console.ResetColor();
  434.         }
  435.         public void ClearAttackRightFighter()
  436.         {
  437.             int posY = 9;
  438.             Console.ForegroundColor = ConsoleColor.Red;
  439.             Console.SetCursorPosition(41, posY);
  440.             for (int i = 0; i < ClearFighter.GetLength(0); i++)
  441.             {
  442.                 for (int j = 0; j < ClearFighter.GetLength(1); j++)
  443.                 {
  444.                     Console.Write(ClearFighter[i, j]);
  445.                 }
  446.                 Console.WriteLine();
  447.                 Console.SetCursorPosition(41, ++posY);
  448.             }
  449.         }
  450.     }
  451. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement