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 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); }
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 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 int AwardBonusMoves(DiceService diceService, RobotDifficulty difficulty) { if (difficulty != RobotDifficulty.Difficult) return 0; var bonusMoves = diceService.Roll(3); MovesRemaining = MovesRemaining + bonusMoves; return bonusMoves; }
public int AwardBonusMoves(DiceService diceService, RobotDifficulty difficulty) { if (difficulty != RobotDifficulty.Difficult) { return(0); } var bonusMoves = diceService.Roll(3); MovesRemaining = MovesRemaining + bonusMoves; return(bonusMoves); }
private void fight(RobotDifficulty difficulty) { try { var battleResult = BattleService.PerformBattle(_userId, difficulty); var str = formatBattleResult(battleResult); resultLabel.Text = str; BattleService.RecordBattle(_userId, str); updateStatistics(battleResult.Hero); } catch (Exception exception) { resultLabel.Text = formatErrorMessage(exception.Message); } }
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); }
private void fight(RobotDifficulty difficulty) { try { var battleResult = BattleService.PerformBattle(_userId, difficulty); var str = formatBattleResult(battleResult); resultLabel.Text = str; BattleService.RecordBattle(_userId, str); updateStatistics(battleResult.Hero); } catch (Exception exception) { resultLabel.Text = formatErrorMessage(exception.Message); } }