Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp42
- {
- class Program
- {
- static void Main(string[] args)
- {
- int end = 0;
- Console.CursorVisible = false;
- int width = Console.WindowWidth;
- Console.SetCursorPosition(width / 2 - 24, 7);
- Console.Write("Тестирование шкалы здоровья");
- Console.SetCursorPosition(width / 2 - 24, 9);
- Console.Write("Доступны два удара. Первый удар на 50, второй на 100");
- Console.SetCursorPosition(width / 2 - 24, 11);
- Console.Write("Нажмите любую клавишу");
- Console.ReadLine();
- Console.Clear();
- int MaxLife = 1000;
- int Life = 1000;
- int hit = 0;
- int zero = 0;
- while (true)
- {
- Console.SetCursorPosition(width / 2 - 24, 7);
- Console.Write("Выберите удар клавишей 1 или 2");
- if (zero == 0)
- {
- Console.SetCursorPosition(26, 9);
- Console.Write("Здоровье: ");
- Console.Write(Life);
- ConsoleColor DefaultColor = Console.BackgroundColor;
- Console.SetCursorPosition(24, 10);
- Console.Write("[");
- Console.BackgroundColor = ConsoleColor.Red;
- Console.SetCursorPosition(25, 10);
- Console.Write("##########");
- Console.BackgroundColor = DefaultColor;
- Console.Write("]");
- }
- zero = 1;
- ConsoleKeyInfo charKey = Console.ReadKey();
- switch (charKey.Key)
- {
- case ConsoleKey.D1:
- Console.Write("\b \b");
- Console.SetCursorPosition(width / 2 - 24, 8);
- hit = 50;
- Life = draw(Life,MaxLife, hit, "Здоровье", ConsoleColor.Red);
- if (Life <= 0)
- end = 5;
- break;
- case ConsoleKey.D2:
- Console.Write("\b \b");
- Console.SetCursorPosition(width / 2 - 24, 8);
- hit = 100;
- Life = draw(Life,MaxLife, hit, "Здоровье", ConsoleColor.Red);
- if (Life <= 0)
- {
- end = 5;
- }
- break;
- }
- hit = 0;
- if (end > 2)
- break;
- }
- Console.WriteLine();
- }
- static int draw(int Value, int MaxLife,int hit, string name, ConsoleColor color, char barchar='#')
- {
- ConsoleColor DefaultColor = Console.BackgroundColor;
- Console.Clear();
- Value -= hit;
- if (Value < 0)
- Value = 0;
- Console.SetCursorPosition(26, 9);
- Console.Write(name + ": " + Value);
- Console.SetCursorPosition(24, 10);
- Console.SetCursorPosition(24, 10);
- Console.Write("[");
- Console.BackgroundColor = color;
- string bar = "";
- for (int i=0;i<Value/100;i++)
- {
- bar += barchar;
- }
- Console.Write(bar);
- Console.BackgroundColor = DefaultColor;
- bar = "";
- barchar = ' ';
- for (int i = Value/100; i < MaxLife/100; i++)
- bar += barchar;
- Console.Write(bar);
- Console.BackgroundColor = DefaultColor;
- Console.Write("]");
- return Value;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement