public IActionResult AttackCharacter(AttackCharacterRequest request)
        {
            var attacker = _chars.GetById(request.AttackerId);
            var victim   = _chars.GetById(request.VictimId);

            if (attacker == null || victim == null)
            {
                return(NotFound());
            }

            if (!victim.CanTakeDamage(attacker.HitPoints))
            {
                return(ValidationProblem("The victim can't take this much damage :("));
            }

            victim.TakeDamage(attacker.HitPoints);
            _chars.Update(victim);

            return(Ok(
                       new {
                Message = "Attack Successful!",
                Attacker = _mapper.Map <CharacterResponse>(attacker),
                Victim = _mapper.Map <CharacterResponse>(victim)
            }
                       ));
        }
Exemplo n.º 2
0
        public ActionResult <object> DeleteCharacter(int id)
        {
            var character = _chars.GetById(id);

            if (character == null)
            {
                return(NotFound());
            }

            _chars.Delete(character);

            return(Ok(
                       new { Message = "Deleted successfully!" }
                       ));
        }
Exemplo n.º 3
0
        public IActionResult LoadMap(int characterID)
        {
            if (HttpContext.Session.GetString("Username") == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            var tempItemList = new List <ItemViewModel>();

            foreach (Item item in _ir.GetAllItems(0))
            {
                tempItemList.Add(ItemToItemVM.ToItemVM(item));
            }
            var mvm = new MapViewModel
            {
                character = CharacterToCharacterVM.ToCharVM(_cr.GetById(characterID)),
                allitems  = tempItemList
            };

            return(View("Game", mvm));
        }
Exemplo n.º 4
0
        public void TestLoadingGame()
        {
            //Arrange
            CharacterCreationViewModel ccvm = new CharacterCreationViewModel();
            ICharacterContext          _Icc = new TestCharacterContext();
            IItemContext  _IIc         = new TestItemContext();
            CharacterRepo _cr          = new CharacterRepo(_Icc);
            ItemRepo      _ir          = new ItemRepo(_IIc);
            var           mvm          = new MapViewModel();
            var           tempItemList = new List <ItemViewModel>();

            //Act

            mvm.character = CharacterToCharacterVM.ToCharVM(_cr.GetById(5));
            foreach (Item item in _ir.GetAllItems(0))
            {
                tempItemList.Add(ItemToItemVM.ToItemVM(item));
            }
            mvm.allitems = tempItemList;
            //Assert
            Assert.IsTrue(mvm.character != null && mvm.character.CharacterModel != "");
            Assert.IsTrue(mvm.allitems.Count > 0);
        }
Exemplo n.º 5
0
        public IActionResult Play(int Id)
        {
            var character = _cr.GetById(Id);

            return(RedirectToAction("LoadMap", "Map", new { characterID = Id }));
        }