Exemplo n.º 1
0
        public static void CreateWeapon()
        {
            Weapon weapon = new Weapon();
            bool   error  = false;

            try
            {
                StreamWriter outputFile = File.AppendText(@"../../../TextAdventureLib/Docs/Weapons.csv");
                Console.Write("Enter the name of the weapon: ");
                weapon.Name = Console.ReadLine().Trim();
                Console.Write("Enter the description of the weapon: ");
                weapon.Description = Console.ReadLine().Trim();
                do
                {
                    Console.Write("Enter the durablitly of the weapon: ");
                    weapon.Durability = ConvertInput.ConvertToInt(Console.ReadLine().Trim());
                    if (weapon.Durability > 0)
                    {
                        Console.WriteLine(StandardMessages.DisplayCreaterNumberError());
                        error = true;
                    }
                    else
                    {
                        error = false;
                    }
                } while (error == true);
                do
                {
                    Console.Write("Enter the damage of the weapon: ");
                    weapon.Damage = ConvertInput.ConvertToInt(Console.ReadLine().Trim());
                    if (weapon.Damage > 0)
                    {
                        Console.WriteLine(StandardMessages.DisplayCreaterNumberError());
                        error = true;
                    }
                    else
                    {
                        error = false;
                    }
                } while (error == true);

                outputFile.Write($"{weapon.Name},{weapon.Description},{weapon.Durability},{weapon.Damage}");
                outputFile.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            World.weapons.Add(weapon);
            Console.WriteLine("Weapon created successfully!");
        }
Exemplo n.º 2
0
        public static void CreateMob()
        {
            Mob  mob   = new Mob();
            bool error = false;

            try
            {
                StreamWriter outputFile = File.AppendText(@"../../../TextAdventureLib/Docs/Monsters.csv");
                Console.Write("Enter the name of the mob: ");
                mob.Name = Console.ReadLine().Trim();
                do
                {
                    Console.Write("Enter the health of the mob: ");
                    mob.Health = ConvertInput.ConvertToInt(Console.ReadLine().Trim());
                    if (mob.Health < 0)
                    {
                        error = true;
                        Console.WriteLine(StandardMessages.DisplayCreaterNumberError());
                    }
                    else
                    {
                        error = false;
                    }
                } while (error == true);
                do
                {
                    Console.Write("Enter the damage of the mob: ");
                    mob.Damage = ConvertInput.ConvertToInt(Console.ReadLine().Trim());
                    if (mob.Damage < 0)
                    {
                        error = true;
                        Console.WriteLine(StandardMessages.DisplayCreaterNumberError());
                    }
                    else
                    {
                        error = false;
                    }
                } while (error == true);

                outputFile.Write($"{mob.Name},{mob.Health},{mob.Damage}");
                outputFile.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            World.mobs.Add(mob);
            Console.WriteLine("Mob created successfully!");
        }