static void Main(string[] args) { // fields Character characterTest = new Character(); // variable to test the character class. Hero heroTest = new Hero(); // variable to test the hero class. Hero hero1 = new SoftwareEngineer("Stuart", true); // variable to test the S.E. class as a Hero. Enemy enemyTest = new Enemy(); // variable to test the enemy class. // test content of the Character and hero class. //Console.WriteLine("\n" + heroTest.toString()); // test content of the Enemy class. //Console.WriteLine(enemyTest.ToString()); // test content of the software engineer as a hero. Console.WriteLine(hero1.ToString()); // hold the terminal open to view the stats. Console.ReadLine(); }
/********************************************************************** * Checks to see if the Character can hit the other Character. * The attack will be successful if the agressor's attack is greater * than the defender's * If the Character is successful, The first Character will * inflict damage to the second Character. * ******************************************************************** */ public String InitiateAttack(Character aCharacter) { String damage; //if the first characters aim is better than the second characters dodge //the attack will go through. if ((BattleChance() - aCharacter.BattleChance()) > 0) { damage = BattleDamage(aCharacter); } else { damage = "MISS"; } return damage; }
private int BattleChance(Character opponent) { Random random = new Random(); int chance = random.Next((75 + currentAgility), 101); return chance; }
// calculates special battle damage. private String SpecialBattleDamage(Character opponent) { Random random = new Random(baseSpecialAttack); double criticalChance = random.NextDouble(); String amount; amount = ((int)(((currentSpecialAttack * criticalChance) + currentSpecialAttack) - (opponent.CurrentSpecialDefense)) + ""); opponent.DecreaseHealth(Int32.Parse(amount)); return amount; }
/********************************************************************** * Checks to see if the Character can hit the other Character. * The attack will be successful if the agressor's attack is greater * than the defender's * If the Character is successful, The first Character will * inflict damage to the second Character. * ******************************************************************** */ public String initiateAttack(Character aCharacter) { Random random = new Random(baseAttack); double criticalChance = random.NextDouble(); String damage; if ((BattleChance() - aCharacter.BattleChance()) > 0) { damage = ((int)(((currentAttack * criticalChance) + currentAttack)) + ""); aCharacter.DecreaseHealth(Int32.Parse(damage)); } else { damage = "MISS"; } return damage; }