Exemplo n.º 1
0
        /// <summary>
        /// The Main function of the program with all operations.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            Drawer.MagentaConsole("\t\t\t\t\t<<НАЧАЛО ТВОЕГО ВЕЛИКОГО ПУТИ>>" + Environment.NewLine);
            do
            {
                Console.OutputEncoding = Encoding.UTF8;
                // Creating the arsenal of the hero.
                money = ReadInt("Для начала, введи количество монет для покупки оружия: ", 10);
                List <Gun> arsenal = new List <Gun>();
                arsenal = BuyGuns(arsenal, money);

                // This part is responsible for making the enemies' crews.
                int        crews = ReadInt("Теперь пора ввести количество отрядов противников!", 1, 10000000);
                List <Mob> mobs  = new List <Mob>(crews);
                mobs = CreateSquads(mobs, crews);

                // The starting point of the defence.
                Drawer.YellowConsole(Environment.NewLine + "\t\t\t\t       <<ДА НАЧНЕТСЯ ВЕЛИКАЯ ОБОРОНА!>>" + Environment.NewLine);
                Defence(arsenal, mobs);

                Drawer.DarkGrayConsole("Введите ENTER для продолжения, в противном случае," +
                                       " нажмите на любую клавишу");
            } while (Console.ReadKey(true).Key == ConsoleKey.Enter);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Imitates the defence with guns versus the mobs.
        /// </summary>
        /// <param name="arsenal"></param>
        /// <param name="mobs"></param>
        static public void Defence(List <Gun> arsenal, List <Mob> mobs)
        {
            // The loop for processing till the guns aren't empty and mobs are alive.
            while (mobs.Count() != 0 && arsenal.Count() != 0 && patronsSum != 0)
            {
                // Making copies of the list elements.
                gunIndex   = random.Next(0, arsenal.Count());
                squadIndex = random.Next(0, mobs.Count());
                Gun randomShootableGun = arsenal[gunIndex];
                Mob randomAliveSquad   = mobs[squadIndex];
                currentDamage = randomShootableGun.Shoot();

                if (currentDamage != 0)
                {
                    randomAliveSquad.ReceiveDamage(randomShootableGun.Shoot());
                    Drawer.DarkGrayConsole($"Отряд под номером {squadIndex + 1} получил урон в размере " +
                                           $"{randomShootableGun.Damage} от {randomShootableGun.GetType().Name}, в котором осталось " +
                                           $"{randomShootableGun.Patrons - 1} патронов и так как у самого слабого монстра из этого отряда жизней было " +
                                           $"{randomAliveSquad.MaxDamage}, теперь его жизни равны {randomAliveSquad.Health}.");
                }
                if (currentDamage == 0)
                {
                    Drawer.WhiteConsole($"Отряд под номером {squadIndex + 1} должен был получить урон, но ты промазал :(");
                }

                randomShootableGun.Patrons -= 1;
                // If the squad is dead removes it.
                if (randomAliveSquad.IsDead)
                {
                    mobs.RemoveAt(squadIndex);
                    Drawer.RedConsole(Environment.NewLine + $"\t\t\t  УРА! Отряд монстров под номером {squadIndex + 1} уничтожен!!!" + Environment.NewLine);
                }
                // If the gun is broken removes it.
                if (randomShootableGun.IsBroken)
                {
                    Drawer.RedConsole(Environment.NewLine + $"\t\t     К сожалению, оружие под индексом {gunIndex + 1} сломалось из-за неисправности :(");
                    arsenal.RemoveAt(gunIndex);
                }
                if (randomShootableGun.Patrons == 0)
                {
                    if (arsenal.Count == 1)
                    {
                        Drawer.RedConsole("\t\t\t    К сожалению, в последнем оружие закончились патроны :(" + Environment.NewLine);
                        arsenal.RemoveAt(0);
                        break;
                    }
                    Drawer.WhiteConsole(Environment.NewLine + "В одном из оружий кончились патроны," +
                                        " хочешь ли ты добавить туда патроны?"
                                        + Environment.NewLine + "1) Нет, перейти дальше." + Environment.NewLine + "2) Да, попробовать, " +
                                        "с вероятностью 50% потерять другое оружие");
                    int answerGun = ReadInt("Твой ответ: (введи либо 1, либо 2)", 1, 2);
                    // Remove gun by index.
                    if (answerGun == 1)
                    {
                        arsenal.RemoveAt(gunIndex);
                    }
                    else
                    {
                        Gun gunCopy = randomShootableGun;
                        arsenal.RemoveAt(gunIndex);
                        Drawer.WhiteConsole("Теперь тебе нужно выбрать, чем пожертвовать и потом ты испытаешь удачу!");
                        for (int i = 0; i < arsenal.Count; i++)
                        {
                            Drawer.YellowConsole($"{i + 1}. {arsenal[i].GetType().Name} с {arsenal[i].Patrons} патронами " +
                                                 $"и уроном {arsenal[i].Damage}");
                        }
                        int deleteAnotherIndex = ReadInt($"Твой ответ? (от 1 до {arsenal.Count()})", 1, arsenal.Count());
                        if (random.NextDouble() < 0.5)
                        {
                            Drawer.WhiteConsole(Environment.NewLine + "К сожалению, удача не на твоей стороне, " +
                                                "оружие осталось без патронов и ты теряешь поставленное на кон оружие :(" + Environment.NewLine);
                            if (arsenal.Count() >= 1)
                            {
                                Drawer.RedConsole($"\t\t\t\t    Оружие под индексом {deleteAnotherIndex} будет удалено!");
                                arsenal.RemoveAt(deleteAnotherIndex - 1);
                            }
                        }
                        else
                        {
                            Drawer.WhiteConsole(Environment.NewLine + "Фортуна на твоей стороне."
                                                + Environment.NewLine + "Получи 5 патронов!!!");
                            gunCopy.Patrons += 5;
                            arsenal.Add(gunCopy);
                        }
                    }
                }
                Drawer.GreenConsole("\t\t\t\t Стадия Обороны завершилась, ждем следующей!" + Environment.NewLine);
                Thread.Sleep(500);
            }
            // In case of WIN, it displays the output in the Console.
            if (arsenal.Count == 0 && mobs.Count == 0)
            {
                Drawer.GreenConsole("\t\t\t\t\t\t<<ПОБЕДА!>>");
            }
            // In case of WIN, it displays the output in the Console.
            if (arsenal.Count != 0 && mobs.Count == 0)
            {
                Drawer.GreenConsole("\t\t\t\t\t\t<<ПОБЕДА!>>");
            }
            // In case of LOSE, it displays the output in the Console.
            if (arsenal.Count == 0 && mobs.Count != 0)
            {
                Drawer.RedConsole("\t\t\t\t\t\t<<ПОРАЖЕНИЕ!>>");
            }
        }