コード例 #1
0
        public void UpgradePersonage()
        {
            bool x = personagerepo.UpgradePersonage(1, 1500, 1, 22);
            bool y = personagerepo.UpgradePersonage(0, 1500, 1, 22);
            bool z = personagerepo.UpgradePersonage(1, 500, 1, 22);
            bool w = personagerepo.UpgradePersonage(1, 1500, 0, 22);

            Assert.AreEqual(true, x);
            Assert.AreEqual(false, y);
            Assert.AreEqual(false, z);
            Assert.AreEqual(false, w);
        }
コード例 #2
0
        public IActionResult UpgradePersonage(int id)
        {
            int       userId    = Convert.ToInt32(HttpContext.Session.GetInt32("CurrentUserID"));
            Speler    speler    = spelerrepo.GetSpelerByID(userId);
            Personage personage = personagerepo.GetPersonageById(id);

            if (personage.ID == personage.ID && speler.XP == speler.XP && personage.Prijs == personage.Prijs && speler.ID == speler.ID)
            {
                if (speler.XP < personage.Prijs)
                {
                    HttpContext.Session.SetInt32("XP", 1);
                }
                else
                {
                    speler.XP -= personage.Prijs;
                    personagerepo.UpgradePersonage(personage.ID, speler.XP, speler.ID, personage.HP);
                }
            }
            else
            {
                TempData["Error"] = "Ongeldige waarden upgrade Personage";
            }
            return(RedirectToAction("Personage"));
        }