Exemplo n.º 1
0
    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;
    }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 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;
 }
Exemplo n.º 5
0
    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;
    }
Exemplo n.º 6
0
    public int AwardBonusMoves(DiceService diceService, RobotDifficulty difficulty)
    {
      if (difficulty != RobotDifficulty.Difficult) return 0; 

      var bonusMoves = diceService.Roll(3);
      MovesRemaining = MovesRemaining + bonusMoves;
      return bonusMoves;
    }
Exemplo n.º 7
0
        public int AwardBonusMoves(DiceService diceService, RobotDifficulty difficulty)
        {
            if (difficulty != RobotDifficulty.Difficult)
            {
                return(0);
            }

            var bonusMoves = diceService.Roll(3);

            MovesRemaining = MovesRemaining + bonusMoves;
            return(bonusMoves);
        }
Exemplo n.º 8
0
 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);
     }
 }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
 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);
   }
 }