Esempio n. 1
0
 public void Save(string savename, MainHero mainHero, Boss boss)
 {
     using (StreamWriter sw = new StreamWriter($"saves/savelog.txt", true))
     {
         sw.WriteLine($"{savename}.txt");
     }
     using (StreamWriter sw = new StreamWriter($"saves/{savename}.txt"))
     {
         sw.WriteLine($"Map Size - {Map.Size}");
         for (int i = 0; i < mainHero.Location; i++)
         {
             sw.WriteLine($"null: Location - {i}");
         }
         for (int i = mainHero.Location; i < Map.Size; i++)
         {
             if (Map[i] is Unit)
             {
                 if (Map[i] is MainHero)
                 {
                     MainHero temp = (MainHero)Map[i];
                     sw.WriteLine($"Unit/MainHero/: Name - {temp.Name}, HP - {temp.HP}, Mana - {temp.Mana}, Armor - {temp.Armor}, Damage - {temp.Damage}, Gold - {temp.Gold}, Location - {temp.Location}, ");
                 }
                 else if (Map[i] is Boss)
                 {
                     Boss temp = (Boss)Map[i];
                     sw.WriteLine($"Unit/Boss/: Name - {temp.Name}, HP - {temp.HP}, Mana - {temp.Mana}, Armor - {temp.Armor}, Damage - {temp.Damage}, Location - {temp.Location}, ");
                 }
                 else
                 {
                     //Все рядовые мобы
                     if (Map[i] is Goblin)
                     {
                         Goblin temp = (Goblin)Map[i];
                         sw.WriteLine($"Unit/Goblin/: Name - {temp.Name}, HP - {temp.HP}, Mana - {temp.Mana}, Armor - {temp.Armor}, Damage - {temp.Damage}, Gold - {temp.Gold}, Location - {temp.Location}, ");
                     }
                     else if (Map[i] is Spider)
                     {
                         Spider temp = (Spider)Map[i];
                         sw.WriteLine($"Unit/Spider/: Name - {temp.Name}, HP - {temp.HP}, Mana - {temp.Mana}, Armor - {temp.Armor}, Damage - {temp.Damage}, Location - {temp.Location}, ");
                     }
                 }
             }
             else if (Map[i] is Loot)
             {
                 if (Map[i] is Chest)
                 {
                     Chest temp = (Chest)Map[i];
                     sw.WriteLine($"Loot/Chest/: Gold - {temp.Gold}, Location - {temp.Location}, ");
                 }
                 else if (Map[i] is Aura)
                 {
                     if (Map[i] is AttackAura)
                     {
                         AttackAura temp = (AttackAura)Map[i];
                         sw.WriteLine($"Loot/Aura/AttackAura/: AttackBuff - {temp.AttackBuff}, Location - {temp.Location}, ");
                     }
                 }
             }
         }
     }
 }
Esempio n. 2
0
        public void Load(string savename, ref MainHero mainHero, ref Boss boss)
        {
            using (StreamReader sr = new StreamReader($"saves/{savename}"))
            {
                //Поиск размера
                string buff = sr.ReadLine();
                buff     = buff.Remove(0, (buff.IndexOf("-") + 2));
                Map.Size = Convert.ToInt32(buff);
                //

                //Поиск всего, что лежит на карте
                for (int i = 0; !sr.EndOfStream; i++)
                {
                    buff = sr.ReadLine();
                    if (buff.Contains("null"))
                    {
                        Map[i] = null;
                    }
                    else
                    {
                        string typeOfObject_Main = buff.Substring(0, buff.IndexOf("/"));
                        buff = buff.Remove(0, (buff.IndexOf("/") + 1));
                        string typeOfObject_1 = "", typeOfObject_2 = ""; //Если создаются новые ветки наследования объектов, то сюда просто новое
                        if (typeOfObject_Main == "Unit")
                        {
                            typeOfObject_1 = buff.Substring(0, buff.IndexOf("/"));
                            buff           = buff.Remove(0, (buff.IndexOf(":") + 2));
                        }
                        else if (typeOfObject_Main == "Loot")
                        {
                            typeOfObject_1 = buff.Substring(0, buff.IndexOf("/"));
                            if (typeOfObject_1 == "Chest")
                            {
                                buff = buff.Remove(0, (buff.IndexOf(":") + 2));
                            }
                            else if (typeOfObject_1 == "Aura")
                            {
                                buff           = buff.Remove(0, (buff.IndexOf("/") + 1));
                                typeOfObject_2 = buff.Substring(0, buff.IndexOf("/"));
                                if (typeOfObject_2 == "AttackAura")
                                {
                                    buff = buff.Remove(0, (buff.IndexOf(":") + 2));
                                }
                            }
                        }
                        List <string> attributes = new List <string>();
                        for (int j = 0; buff != ""; j++)
                        {
                            buff = buff.Remove(0, (buff.IndexOf("-") + 2));
                            attributes.Add(buff.Substring(0, buff.IndexOf(",")));
                            buff = buff.Remove(0, (buff.IndexOf(",") + 2));
                        }


                        if (typeOfObject_Main == "Unit")
                        {
                            if (typeOfObject_1 == "MainHero")
                            {
                                MainHero temp = (MainHero)Map[i];
                                temp     = new MainHero(attributes[0], Convert.ToInt32(attributes[1]), Convert.ToInt32(attributes[2]), Convert.ToInt32(attributes[3]), Convert.ToInt32(attributes[4]), Convert.ToInt32(attributes[5]), Convert.ToInt32(attributes[6]));
                                Map[i]   = temp;
                                mainHero = temp;
                            }
                            else if (typeOfObject_1 == "Boss")
                            {
                                Boss temp = (Boss)Map[i];
                                temp   = new Boss(attributes[0], Convert.ToInt32(attributes[1]), Convert.ToInt32(attributes[2]), Convert.ToInt32(attributes[3]), Convert.ToInt32(attributes[4]), Convert.ToInt32(attributes[5]));
                                Map[i] = temp;
                                boss   = temp;
                            }
                            else
                            {
                                if (typeOfObject_1 == "Goblin")
                                {
                                    Goblin temp = (Goblin)Map[i];
                                    temp   = new Goblin(attributes[0], Convert.ToInt32(attributes[1]), Convert.ToInt32(attributes[2]), Convert.ToInt32(attributes[3]), Convert.ToInt32(attributes[4]), Convert.ToInt32(attributes[5]), Convert.ToInt32(attributes[6]));
                                    Map[i] = temp;
                                }
                                else if (typeOfObject_1 == "Spider")
                                {
                                    Spider temp = (Spider)Map[i];
                                    temp   = new Spider(attributes[0], Convert.ToInt32(attributes[1]), Convert.ToInt32(attributes[2]), Convert.ToInt32(attributes[3]), Convert.ToInt32(attributes[4]), Convert.ToInt32(attributes[5]));
                                    Map[i] = temp;
                                }
                            }
                        }
                        else if (typeOfObject_Main == "Loot")
                        {
                            if (typeOfObject_1 == "Chest")
                            {
                                Chest temp = (Chest)Map[i];
                                temp   = new Chest(Convert.ToInt32(attributes[0]), Convert.ToInt32(attributes[1]));
                                Map[i] = temp;
                            }
                            else if (typeOfObject_1 == "Aura")
                            {
                                if (typeOfObject_2 == "AttackAura")
                                {
                                    AttackAura temp = (AttackAura)Map[i];
                                    temp   = new AttackAura(Convert.ToInt32(attributes[0]), Convert.ToInt32(attributes[1]));
                                    Map[i] = temp;
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            var Game = new Game();

            var MainHero = new MainHero("MainHero", 100, 0, 2, 20, 100, 0);
            var Boss     = new Boss("Boss", 100, 0, 5, 5, Game.Map.Size - 1);


            Game.BattleEventArgs.MainHero = MainHero;
            Game.OnBattleEvent           += Game_OnBattleEvent;


            using (StreamReader sr = new StreamReader("saves/savelog.txt"))
            {
                if (sr.ReadLine() == null)
                {
                    Console.WriteLine("1 - Начать новую игру\n3 - Выйти из игры");
                }
                else
                {
                    Console.WriteLine("1 - Начать новую игру\n2 - Загрузить игру\n3 - Выйти из игры");
                }
            }
            int menu = Convert.ToInt32(Console.ReadLine());

            Console.Clear();

            if (menu == 1)
            {
                Game.Start(ref MainHero, ref Boss);
            }
            else if (menu == 2)
            {
                Game.Load(AskSaveName(), ref MainHero, ref Boss);
            }
            else if (menu == 3)
            {
                Environment.Exit(0);
            }

            while (!Game.End)
            {
                MainHero.ShowStatus();
                Console.WriteLine("-------------------------------------------");
                if (Game.Map[Game.Map.Size - 2] != MainHero) //Обычная ходьба по подземелью
                {
                    Console.WriteLine("Ваши действия:\n1 - Идти вперед\n8 - Сохраниться\n9 - Выйти из игры");
                    int turn = Convert.ToInt32(Console.ReadLine());
                    Console.Clear();


                    if (turn == 1)
                    {
                        if (Game.Map[MainHero.Location + 1] is Loot)
                        {
                            if (Game.Map[MainHero.Location + 1] is Chest)
                            {
                                Chest temp = (Chest)Game.Map[MainHero.Location + 1];
                                Console.Write($"Вы нашли золото!\n+{temp.Gold} золота\n");
                                Console.WriteLine("-------------------------------------------");
                                MainHero.Gold          += temp.Gold;
                                Game.Map[temp.Location] = MainHero;
                                MainHero.Location++;
                            }
                            else if (Game.Map[MainHero.Location + 1] is Aura)
                            {
                                if (Game.Map[MainHero.Location + 1] is AttackAura)
                                {
                                    AttackAura temp = (AttackAura)Game.Map[MainHero.Location + 1];
                                    Console.Write($"Вы обнаружили алтарь древних Богов Войны!\n+{temp.AttackBuff} к урону\n");
                                    Console.WriteLine("-------------------------------------------");
                                    MainHero.Damage        += temp.AttackBuff;
                                    Game.Map[temp.Location] = MainHero;
                                    MainHero.Location++;
                                }
                            }
                        }
                        else if (Game.Map[MainHero.Location + 1] is Unit)
                        {
                            Unit temp = (Unit)Game.Map[MainHero.Location + 1];
                            Console.WriteLine($"Вы встретились с {temp.Name}!");
                            Console.WriteLine("-------------------------------------------");
                            Game.BattleEventArgs.Enemy = temp;
                            Game.Meeting(temp, Game.BattleEventArgs);

                            Game.Map[temp.Location] = MainHero;
                            MainHero.Location++;
                        }
                    }
                    else if (turn == 8)
                    {
                        Console.WriteLine("Выберите название для сохранения");
                        string savename = Console.ReadLine();
                        Game.Save(savename, MainHero, Boss);
                    }
                    else if (turn == 9)
                    {
                        Environment.Exit(0);
                    }
                }
                else //Встреча с боссом
                {
                    Console.Write("Впереди босс...\nВаши действия:\n1 - Идти вперед\n2 - Отдохнуть, восстановив здоровье, но дав боссу времени на приготовления\n");
                    int turn = Convert.ToInt32(Console.ReadLine());
                    Console.Clear();
                    if (turn == 2)
                    {
                        var rnd  = new Random();
                        int temp = rnd.Next(5, 11);
                        Console.WriteLine($"Вы полностью восстановились, но {Boss.Name} увеличил свою броню на {temp}");
                        Console.WriteLine("-------------------------------------------");
                        Boss.Armor += temp;
                        MainHero.HP = 100; //Изменить на максимум
                    }
                    Console.WriteLine($"Вы встретились с {Boss.Name}!");
                    Game.BattleEventArgs.Enemy = Boss;
                    Game.Meeting(Boss, Game.BattleEventArgs);

                    Game.Map[Boss.Location] = MainHero;
                    MainHero.Location++;
                    Game.End = true;
                }
            }
        }