Example #1
0
        /// <summary>
        /// Perform an attack on a character
        /// </summary>
        /// <param name="character">A reference to the character being attacked</param>
        /// <returns>The result of the attack as an AttackResult object</returns>
        public AttackResult Attack(CharacterBase character)
        {
            //average the Physical Characteristics to determine hit chance
            float hitChance;
            int hitRoll;
            int damage;
            int damageSeed;
            int potentialDamage;
            Random random;

            hitChance = (float)this.PhysicalStrength * 1.25f;
            hitChance += (float)this.ManualDexterity * 2f;
            hitChance += (float)this.Swiftness * 1.25f;
            hitChance -= (float)character.Swiftness;
            hitChance = hitChance / 3;

            random = new Random();
            hitRoll = random.Next(100) + 1;

            if (hitChance > (float)hitRoll)
            {
                damageSeed = Convert.ToInt32(this.PhysicalStrength / 4);
                potentialDamage = damageSeed + this.Weapon.BaseDamage;
                random = new Random();
                damage = this.Weapon.BaseDamage + random.Next(damageSeed) + 1;
                if (damage == potentialDamage)
                {
                    damage = damage * 2;
                    return new AttackResult(damage, true, true);
                }
                return new AttackResult(damage, true, false);
            }

            return new AttackResult(0, false, false);
        }
Example #2
0
        private static void Main(string[] args)
        {
            bool done = false;

            InitializeOccupations();
            while (!done)
            {
                Console.Out.WriteLine("Do you want to create a new character or load a character?");

                char loadChoice = HandleStartup();
                if (loadChoice == '1')
                {
                    CharacterBase character = new CharacterBase();
                    Console.Out.WriteLine("What is the character`s name? Type the name and hit enter.");
                    string characterName = Console.ReadLine();
                    character.CharacterName = characterName;
                    char classKey = ChooseCharacterOccupation();
                    bool worked   = Int32.TryParse(classKey.ToString(), out int actualNumber);
                    if (!worked)
                    {
                        Console.Out.WriteLine("Something went wrong with setting the character class. Please alert the developers.");
                    }
                    else
                    {
                        character.CharacterOccupation = Occupations[actualNumber];
                    }
                    Console.Out.WriteLine(character.ToString());

                    character.Level = GetDesiredLevel();
                    Console.Out.Write("If this is correct, we will now save your character.");
                    character.Save();
                    Console.Out.WriteLine(characterName + " has been saved into Characters/" + characterName.Replace(' ', '_') + ".xml");
                    character = CharacterBase.Load(character.CharacterName);
                    Console.Out.WriteLine(character.ToString());
                }
                else if (loadChoice == '2')
                {
                    CharacterBase character;
                    bool          rightCharacterFound = false;
                    do
                    {
                        Console.Out.WriteLine("What is the name of the character you wish to update?");
                        string characterName = Console.ReadLine();
                        character = CharacterBase.Load(characterName.Replace(' ', '_'));
                        ConsoleKeyInfo key;
                        if (character != null)
                        {
                            Console.Out.WriteLine("These are the character stats.");

                            Console.Out.WriteLine(character.ToString());
                            Console.Out.WriteLine("Is the right file to be loaded? Type 1 if yes. Type 2 if no.");
                            key = Console.ReadKey();
                            Console.ReadLine();
                        }
                        else
                        {
                            Console.Out.WriteLine("No file found with that name. Type 1 to .");
                            key = Console.ReadKey();
                            Console.ReadLine();
                        }


                        if (key.KeyChar == '1')
                        {
                            rightCharacterFound = true;
                        }
                    }while (!rightCharacterFound);
                    char classKey = ChooseCharacterOccupation();
                    bool worked   = Int32.TryParse(classKey.ToString(), out int actualNumber);
                    if (!worked)
                    {
                        Console.Out.WriteLine("Something went wrong with setting the character class. Please alert the developers.");
                    }
                    else
                    {
                        character.CharacterOccupation = Occupations[actualNumber];
                    }
                    character.Level = GetDesiredLevel();
                    Console.Out.WriteLine(character.ToString());

                    Console.Out.WriteLine("If this is correct, we will now save your character.");
                    character.Save();
                    Console.Out.WriteLine(character.CharacterName + " has been saved into Characters/" + character.CharacterName + ".xml");
                }
                else
                {
                    done = true;
                }
            }
            Console.Out.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }