示例#1
0
 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;
 }
示例#2
0
 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;
 }
示例#3
0
 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;
 }
示例#4
0
 private static int performTraining(Hero hero, DiceService diceService)
 {
   var trainingImprovement = diceService.Roll(10);
   hero.TrainingLevel += trainingImprovement;
   hero.Credits -= 1;
   hero.MovesRemaining -= 1;
   return trainingImprovement;
 }
 public static bool Validate(Hero hero, int minimumGoldRequired, out string failureMessage)
 {
   failureMessage = "";
   if (hero.MovesRemaining <= 0)
   {
     failureMessage = "Not enough moves remaining.  You must wait until the top of the hour.";
     return false;
   }
   if (hero.Credits >= minimumGoldRequired)
   {
     return true;
   }
   failureMessage = "<p class='text-danger'>Not enough Credits to perform action.</p>";
   return false;
 }
示例#6
0
        protected void CreateUser_Click(object sender, EventArgs e)
        {
            var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();

            //var user = new ApplicationUser() { UserName = Email.Text, Email = Email.Text };
            
            var user = new ApplicationUser
            {
                UserName = EmailTextBox.Text,
                Email = EmailTextBox.Text
            };

          IdentityResult result = manager.Create(user, Password.Text);
            if (result.Succeeded)
            {
                // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                //string code = manager.GenerateEmailConfirmationToken(user.Id);
                //string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request);
                //manager.SendEmail(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>.");

              using (var heroContext = new HeroContext())
              {
                var hero = new Hero
                {
                  UserId = user.Id,
                  Name = HeroNameTextbox.Text,
                  MovesRemaining = 25,
                  Credits = 10,
                  Health = 50,
                  TrainingLevel = 0,
                  ArmorBonus = 0,
                  WeaponBonus = 0,
                  Wins = 0,
                  Losses = 0
                };
                heroContext.Heroes.Add(hero);
                heroContext.SaveChanges();
              }
                IdentityHelper.SignIn(manager, user, isPersistent: false);
                IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
            }
            else 
            {
                ErrorMessage.Text = result.Errors.FirstOrDefault();
            }
        }
示例#7
0
    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;
    }
示例#8
0
 public int Attack(Hero hero, DiceService diceService)
 {
   var damageMaximum = DamageMaximum - hero.ArmorBonus;
   damageMaximum = (damageMaximum > 10 ? damageMaximum : 10);
   return diceService.Roll(damageMaximum);
 }
        private void CreateAndLoginUser()
        {
            if (!IsValid)
            {
                return;
            }
            var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
            //var user = new ApplicationUser() { UserName = email.Text, Email = email.Text };

            var user = new ApplicationUser
            {
              UserName = EmailTextBox.Text,
              Email = EmailTextBox.Text
            };

          
          IdentityResult result = manager.Create(user);
            if (result.Succeeded)
            {
                var loginInfo = Context.GetOwinContext().Authentication.GetExternalLoginInfo();
                if (loginInfo == null)
                {
                    RedirectOnFail();
                    return;
                }
                result = manager.AddLogin(user.Id, loginInfo.Login);
                if (result.Succeeded)
                {

                  using (var heroContext = new HeroContext())
                  {
                    var hero = new Hero
                    {
                      UserId = user.Id,
                      Name = HeroNameTextbox.Text,
                      MovesRemaining = 25,
                      Credits = 10,
                      Health = 50,
                      TrainingLevel = 0,
                      ArmorBonus = 0,
                      WeaponBonus = 0,
                      Wins = 0,
                      Losses = 0
                    };
                    heroContext.Heroes.Add(hero);
                    heroContext.SaveChanges();
                  }

                    IdentityHelper.SignIn(manager, user, isPersistent: false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // var code = manager.GenerateEmailConfirmationToken(user.Id);
                    // Send this link via email: IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id)

                    IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
                    return;
                }
            }
            AddErrors(result);
        }
示例#10
0
 private void updateStatistics(Hero hero)
 {
   heroLiteral.Text = hero.Name;
   healthLiteral.Text = hero.Health.ToString();
   winsLiteral.Text = hero.Wins.ToString();
   lossesLiteral.Text = hero.Losses.ToString();
   movesLiteral.Text = hero.MovesRemaining.ToString();
   trainingLiteral.Text = hero.TrainingLevel.ToString();
   goldLiteral.Text = hero.Credits.ToString();
   WeaponLiteral.Text = hero.WeaponBonus.ToString();
   armorLiteral.Text = hero.ArmorBonus.ToString();
 }