public static Robot GetRobot(RobotDifficulty difficulty, DiceService diceService) { var damageMaximum = 0; var healthMaximum = 0; switch (difficulty) { case RobotDifficulty.Difficult: { damageMaximum = 50; healthMaximum = 50; break; } case RobotDifficulty.Moderate: { damageMaximum = 35; healthMaximum = 35; break; } case RobotDifficulty.Easy: { damageMaximum = 20; healthMaximum = 20; break; } } var robot = new Robot { Name = "Robot", Difficulty = difficulty, Health = diceService.Roll(healthMaximum), DamageMaximum = diceService.Roll(damageMaximum) }; return robot; }
public static BattleResult PerformBattle(string userId, RobotDifficulty difficulty) { BattleResult battleResult; try { using (var heroContext = new HeroContext()) { string validationMessage; var hero = heroContext.Heroes.Single(p => p.UserId == userId); if (!ValidationService.Validate(hero, 0, out validationMessage)) { throw new Exception(validationMessage); } var dice = new DiceService(); var robot = RobotFactory.GetRobot(difficulty, dice); battleResult = performBattle(hero, robot, dice); heroContext.SaveChanges(); } } catch (Exception exception) { Trace.TraceError(exception.Message); throw; } return(battleResult); }
public static Result VisitMedicBay(string userId) { var result = new Result(); try { using (var heroContext = new HeroContext()) { var hero = heroContext.Heroes.Single(p => p.UserId == userId); string validationMessage; if (!ValidationService.Validate(hero, 1, out validationMessage)) { throw new Exception(validationMessage); } var dice = new DiceService(); var healthRestored = restoreHealth(hero, dice); heroContext.SaveChanges(); var successMessage = string.Format("The Medic Bay restored {0} health!", healthRestored); result.Message = successMessage; result.Hero = hero; ActivityService.QueueActivity(userId, EventType.Medic, successMessage); } } catch (Exception exception) { Trace.TraceError(exception.Message); throw; } return result; }
public static Result VisitMedicBay(string userId) { var result = new Result(); try { using (var heroContext = new HeroContext()) { var hero = heroContext.Heroes.Single(p => p.UserId == userId); string validationMessage; if (!ValidationService.Validate(hero, 1, out validationMessage)) { throw new Exception(validationMessage); } var dice = new DiceService(); var healthRestored = restoreHealth(hero, dice); heroContext.SaveChanges(); var successMessage = string.Format("The Medic Bay restored {0} health!", healthRestored); result.Message = successMessage; result.Hero = hero; ActivityService.QueueActivity(userId, EventType.Medic, successMessage); } } catch (Exception exception) { Trace.TraceError(exception.Message); throw; } return(result); }
public int CollectCredits(DiceService diceService, RobotDifficulty difficulty) { var maxCredits = 0; switch (difficulty) { case RobotDifficulty.Difficult: { maxCredits = DifficultRobotMaxCredits; break; } case RobotDifficulty.Moderate: { maxCredits = ModerateRobotMaxCredits; break; } case RobotDifficulty.Easy: { maxCredits = EasyRobotMaxCredits; break; } } var creditsEarned = diceService.Roll(maxCredits); Credits += creditsEarned; return creditsEarned; }
public static BattleResult PerformBattle(string userId, RobotDifficulty difficulty) { BattleResult battleResult; try { using (var heroContext = new HeroContext()) { string validationMessage; var hero = heroContext.Heroes.Single(p => p.UserId == userId); if (!ValidationService.Validate(hero, 0, out validationMessage)) { throw new Exception(validationMessage); } var dice = new DiceService(); var robot = RobotFactory.GetRobot(difficulty, dice); battleResult = performBattle(hero, robot, dice); heroContext.SaveChanges(); } } catch (Exception exception) { Trace.TraceError(exception.Message); throw; } return battleResult; }
private static int upgradeWeapon(Hero hero, DiceService diceService) { var weaponImprovement = diceService.Roll(12, 2); hero.WeaponBonus += weaponImprovement; hero.Credits -= 10; hero.MovesRemaining -= 1; return weaponImprovement; }
public int AwardBonusMoves(DiceService diceService, RobotDifficulty difficulty) { if (difficulty != RobotDifficulty.Difficult) return 0; var bonusMoves = diceService.Roll(3); MovesRemaining = MovesRemaining + bonusMoves; return bonusMoves; }
private static int improveArmor(Hero hero, DiceService diceService) { var armorImprovement = diceService.Roll(12, 2); hero.ArmorBonus += armorImprovement; hero.Credits -= 10; hero.MovesRemaining -= 1; return armorImprovement; }
private static int restoreHealth(Hero hero, DiceService diceService) { var healthRestored = diceService.Roll(20, 5); hero.Credits -= 1; hero.Health += healthRestored; hero.MovesRemaining -= 1; return healthRestored; }
private static int performTraining(Hero hero, DiceService diceService) { var trainingImprovement = diceService.Roll(10); hero.TrainingLevel += trainingImprovement; hero.Credits -= 1; hero.MovesRemaining -= 1; return trainingImprovement; }
private static int improveArmor(Hero hero, DiceService diceService) { var armorImprovement = diceService.Roll(12, 2); hero.ArmorBonus += armorImprovement; hero.Credits -= 10; hero.MovesRemaining -= 1; return(armorImprovement); }
private static int restoreHealth(Hero hero, DiceService diceService) { var healthRestored = diceService.Roll(20, 5); hero.Credits -= 1; hero.Health += healthRestored; hero.MovesRemaining -= 1; return(healthRestored); }
private static int upgradeWeapon(Hero hero, DiceService diceService) { var weaponImprovement = diceService.Roll(12, 2); hero.WeaponBonus += weaponImprovement; hero.Credits -= 10; hero.MovesRemaining -= 1; return(weaponImprovement); }
private static int performTraining(Hero hero, DiceService diceService) { var trainingImprovement = diceService.Roll(10); hero.TrainingLevel += trainingImprovement; hero.Credits -= 1; hero.MovesRemaining -= 1; return(trainingImprovement); }
private static BattleResult performBattle( Hero hero, Robot robot, DiceService diceService) { var battleResult = new BattleResult(); var round = 0; while (hero.Health > 0 && robot.Health > 0) { var battleRound = new BattleRound(); round++; battleRound.RoundNumber = round; battleRound.RobotHealthBeginning = robot.Health; battleRound.HeroDamageInflicted = robot.Defend(hero.Attack(diceService)); battleRound.RobotHealth = robot.Health; battleRound.HeroHealthBeginning = hero.Health; battleRound.RobotDamageInflicted = hero.Defend(robot.Attack(hero, diceService)); battleRound.HeroHealth = hero.Health; battleResult.BattleRounds.Add(battleRound); } if (hero.Health > 0) { hero.MovesRemaining--; hero.Wins++; hero.Health = hero.Health; battleResult.CreditsEarned = hero.CollectCredits(diceService, robot.Difficulty); battleResult.BonusMovesAwarded = hero.AwardBonusMoves(diceService, robot.Difficulty); } else { hero.MovesRemaining = 0; hero.Losses--; hero.Health = 0; } battleResult.Hero = hero; battleResult.Robot = robot; return(battleResult); }
private static BattleResult performBattle( Hero hero, Robot robot, DiceService diceService) { var battleResult = new BattleResult(); var round = 0; while (hero.Health > 0 && robot.Health > 0) { var battleRound = new BattleRound(); round++; battleRound.RoundNumber = round; battleRound.RobotHealthBeginning = robot.Health; battleRound.HeroDamageInflicted = robot.Defend(hero.Attack(diceService)); battleRound.RobotHealth = robot.Health; battleRound.HeroHealthBeginning = hero.Health; battleRound.RobotDamageInflicted = hero.Defend(robot.Attack(hero, diceService)); battleRound.HeroHealth = hero.Health; battleResult.BattleRounds.Add(battleRound); } if (hero.Health > 0) { hero.MovesRemaining--; hero.Wins++; hero.Health = hero.Health; battleResult.CreditsEarned = hero.CollectCredits(diceService, robot.Difficulty); battleResult.BonusMovesAwarded = hero.AwardBonusMoves(diceService, robot.Difficulty); } else { hero.MovesRemaining = 0; hero.Losses--; hero.Health = 0; } battleResult.Hero = hero; battleResult.Robot = robot; return battleResult; }
public static Robot GetRobot(RobotDifficulty difficulty, DiceService diceService) { var damageMaximum = 0; var healthMaximum = 0; switch (difficulty) { case RobotDifficulty.Difficult: { damageMaximum = 50; healthMaximum = 50; break; } case RobotDifficulty.Moderate: { damageMaximum = 35; healthMaximum = 35; break; } case RobotDifficulty.Easy: { damageMaximum = 20; healthMaximum = 20; break; } } var robot = new Robot { Name = "Robot", Difficulty = difficulty, Health = diceService.Roll(healthMaximum), DamageMaximum = diceService.Roll(damageMaximum) }; return(robot); }
public static Result Train(string userId) { var result = new Result(); try { using (var heroContext = new HeroContext()) { var hero = heroContext.Heroes.Single(p => p.UserId == userId); string validationMessage; if (!ValidationService.Validate(hero, 1, out validationMessage)) { throw new Exception(validationMessage); } var dice = new DiceService(); var trainingIncrease = performTraining(hero, dice); heroContext.SaveChanges(); var successMessage = string.Format("Training was successful earning you a {0} point training advantage!", trainingIncrease); result.Message = successMessage; result.Hero = hero; ActivityService.QueueActivity(userId, EventType.Weapon, successMessage); } } catch (Exception exception) { Trace.TraceError(exception.Message); throw; } return(result); }
public static Result PurchaseArmor(string userId) { var result = new Result(); try { using (var heroContext = new HeroContext()) { var hero = heroContext.Heroes.Single(p => p.UserId == userId); string validationMessage; if (!ValidationService.Validate(hero, 10, out validationMessage)) { throw new Exception(validationMessage); } var dice = new DiceService(); var armorImprovement = improveArmor(hero, dice); heroContext.SaveChanges(); var successMessage = string.Format( "Armor upgrade was successful giving you an improvement of {0}!", armorImprovement); result.Message = successMessage; result.Hero = hero; ActivityService.QueueActivity(userId, EventType.Armor, successMessage); } } catch (Exception ex) { Trace.TraceError(ex.Message); throw new Exception(ex.Message); } return(result); }
public static Result PurchaseArmor(string userId) { var result = new Result(); try { using (var heroContext = new HeroContext()) { var hero = heroContext.Heroes.Single(p => p.UserId == userId); string validationMessage; if (!ValidationService.Validate(hero, 10, out validationMessage)) { throw new Exception(validationMessage); } var dice = new DiceService(); var armorImprovement = improveArmor(hero, dice); heroContext.SaveChanges(); var successMessage = string.Format( "Armor upgrade was successful giving you an improvement of {0}!", armorImprovement); result.Message = successMessage; result.Hero = hero; ActivityService.QueueActivity(userId, EventType.Armor, successMessage); } } catch (Exception ex) { Trace.TraceError(ex.Message); throw new Exception(ex.Message); } return result; }
public static Result Train(string userId) { var result = new Result(); try { using (var heroContext = new HeroContext()) { var hero = heroContext.Heroes.Single(p => p.UserId == userId); string validationMessage; if (!ValidationService.Validate(hero, 1, out validationMessage)) { throw new Exception(validationMessage); } var dice = new DiceService(); var trainingIncrease = performTraining(hero, dice); heroContext.SaveChanges(); var successMessage = string.Format("Training was successful earning you a {0} point training advantage!", trainingIncrease); result.Message = successMessage; result.Hero = hero; ActivityService.QueueActivity(userId, EventType.Weapon, successMessage); } } catch (Exception exception) { Trace.TraceError(exception.Message); throw; } return result; }
public int Attack(Hero hero, DiceService diceService) { var damageMaximum = DamageMaximum - hero.ArmorBonus; damageMaximum = (damageMaximum > 10 ? damageMaximum : 10); return diceService.Roll(damageMaximum); }
public int Attack(DiceService diceService) { return diceService.Roll(DamageMaximum); }