using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Net.Mime.MediaTypeNames;

namespace PvE
{
    public partial class Form1 : Form
    {
        Random BotСhoice = new Random();
        //Создание элементов
        Button Attack = new Button();
        Button Block = new Button();
        Button Heal = new Button();
        Button Success = new Button();
        Button Reset = new Button();
        Label Combo = new Label();
        //Константы
        float Damage = 10;
        float Protection = 2.5f;
        float Healing = 5;
        //Переменные
        bool KritHHAB1 = false;
        bool KritHHAB2 = false;
        int Bot;
        string Choise = "";
        int Count = 2;
        int Krit1 = 2;
        int Krit2 = 2;

        public Form1()
        {
            InitializeComponent();
            //Значение HP - 100%
            progressBar1.Value = 100;
            progressBar2.Value = 100;
            //Добавление в управление формы
            Controls.Add(Attack);
            Controls.Add(Block);
            Controls.Add(Heal);
            Controls.Add(Success);
            Controls.Add(Reset);
            Controls.Add(Combo);
            //Настройки размера
            Attack.Size = new Size(75, 55);
            Block.Size = new Size(75, 55);
            Heal.Size = new Size(75, 55);
            Success.Size = new Size(75, 55);
            Reset.Size = new Size(75, 55);
            Combo.AutoSize = true;
            //Настройки текста
            Attack.Text = "Атака";
            Block.Text = "Блок";
            Heal.Text = "Хилл";
            Success.Text = "Принять";
            Reset.Text = "Сбросить";
            Combo.Text = "Ваш выбор:";
            //Настройки позиций
            Attack.Location = new Point(10, 100);
            Block.Location = new Point(10, 160);
            Heal.Location = new Point(10, 220);
            Success.Location = new Point(10, 320);
            Reset.Location = new Point(10, 380);
            Combo.Location = new Point(10, 290);
            //Подключение к событию Click функций
            Attack.Click += new EventHandler(Attack_Click);
            Block.Click += new EventHandler(Block_Click);
            Heal.Click += new EventHandler(Heal_Click);
            Success.Click += new EventHandler(Success_Click);
            Reset.Click += new EventHandler(Reset_Click);
        }

        //Функции кнопок
        private void Attack_Click(object sender, EventArgs e)
        {
            if (Count > 0)
            {
                Choise = Choise + "A";
                Count = Count - 1;
            }
            Combo.Text = "Ваш выбор:" + Choise;
        }

        private void Block_Click(object sender, EventArgs e)
        {
            if (Count > 0)
            {
                Choise = Choise + "B";
                Count = Count - 1;
            }
            Combo.Text = "Ваш выбор:" + Choise;
        }

        private void Heal_Click(object sender, EventArgs e)
        {
            if (Count > 0)
            {
                Choise = Choise + "H";
                Count = Count - 1;
            }
            Combo.Text = "Ваш выбор:" + Choise;
        }

        private void Success_Click(object sender, EventArgs e)
        {
            if (Count == 0)
            {
                //Отключение кнопок
                Attack.Enabled = false;
                Block.Enabled = false;
                Heal.Enabled = false;
                Success.Enabled = false;
                Reset.Enabled = false;
            }
            //Вызов функции "реализации выбора"
            realizationChoice(Choise);
            //Вызов функции "ход бота"
            stepBot();
        }

        private void Reset_Click(object sender, EventArgs e)
        {
            //Вызов функции "сброс информации"
            ResetData();
        }

        //Функция сброса
        private void ResetData()
        {
            Choise = "";
            Count = 2;
            Combo.Text = "Ваш выбор:";
        }

        //Функция реализации выбора
        private void realizationChoice(string txt)
        {
            //Сортировка по алфавиту
            txt = string.Concat(txt.OrderBy(ch => ch));

            if (progressBar2.Value == 0)
            {
                MessageBox.Show("Player win");
            }
            if (progressBar1.Value == 0)
            {
                MessageBox.Show("Bot win");
            }
            if ((progressBar1.Value != 0 || progressBar2.Value != 0) || (progressBar1.Value == 100 || progressBar2.Value == 100))
            {
                switch (txt)
                {
                    case "AA":
                        Bot = BotСhoice.Next(1, 7);
                        pictureBox2.Image = PvE.Properties.Resources.atak1;
                        if (KritHHAB2 == true)
                        {
                            progressBar2.Value = progressBar2.Value - (Damage * 5);
                            KritHHAB2 = false;
                        }
                        else
                        {
                            progressBar2.Value = progressBar2.Value - (Damage * 2);
                        }
                        break;

                    case "BB":
                        Bot = BotСhoice.Next(1, 7);
                        pictureBox2.Image = PvE.Properties.Resources.def1;
                        if (Bot == 1 || Bot == 4 || Bot == 5)
                        {
                            progressBar1.Value = progressBar1.Value - Damage / 2;
                        }
                        break;

                    case "HH":
                        Bot = BotСhoice.Next(1, 7);
                        pictureBox2.Image = PvE.Properties.Resources.hil1;
                        KritHHAB1 = true;
                        progressBar1.Value = progressBar1.Value + Healing * 3;
                        break;

                    case "AB":
                        Bot = BotСhoice.Next(1, 7);
                        if (KritHHAB2 == true)
                        {
                            progressBar2.Value = progressBar2.Value - Damage * 2;
                        }

                        else
                        {
                            progressBar2.Value = progressBar2.Value - Damage;

                            if (Bot == 1 || Bot == 4 || Bot == 5)
                            {
                                progressBar1.Value = progressBar1.Value - (Damage - 2);
                            }
                        }
                        break;

                    case "AH":
                        Bot = BotСhoice.Next(1, 7);
                        progressBar2.Value = progressBar2.Value - Damage;
                        progressBar1.Value = progressBar1.Value + Healing;
                        break;

                    case "BH":
                        Bot = BotСhoice.Next(1, 7);
                        progressBar1.Value = progressBar1.Value + Healing;
                        if (Bot == 1 || Bot == 4 || Bot == 5)
                        {
                            progressBar2.Value = progressBar2.Value - (Damage - 2);
                        }
                        break;
                }
                //Включение кнопок
                Attack.Enabled = true;
                Block.Enabled = true;
                Heal.Enabled = true;
                Success.Enabled = true;
                Reset.Enabled = true;
            }
        }

        //Функция хода бота
        private void stepBot()
        {
            switch (Bot)
            {
                //AA
                case 1:
                    if (KritHHAB1 == true)
                    {
                        progressBar1.Value = progressBar1.Value - 50;
                        KritHHAB1 = false;
                    }
                    else
                    {
                        progressBar1.Value = progressBar1.Value - Damage * 2;
                    }
                    progressBar1.Value = progressBar1.Value - Damage * 2;
                    break;
                //BB
                case 2:
                    if (Choise == "AA" || Choise == "AB" || Choise == "AH")
                    {
                        progressBar2.Value = progressBar2.Value - Damage / 2;
                    }
                    break;
                //HH
                case 3:
                    progressBar2.Value = progressBar2.Value + Healing * 3;
                    KritHHAB2 = true;
                    break;
                //AB
                case 4:

                    break;
                //AH
                case 5:

                    break;
                //BH
                case 6:

                    break;
            }
        }
    }
}