Пример #1
0
        public async Task <IActionResult> Create([FromServices] DalItemOnGame dalItemOnGame, [FromServices] DalEnemy dalEnemy, [FromServices] DalAvatar dalAvatar, Hero newHero)
        {
            if (ModelState.IsValid)
            {
                //Instance game parameters with Enemies
                GameViewModel game = new GameViewModel(await dalEnemy.GetAll());

                //Create hero
                Hero hero = new Hero(newHero.Name, newHero.Health, newHero.Attack, newHero.Race);

                //save myHero to game parameters
                game.Hero = hero;

                //Get image avatar and save to game parameters
                Avatar avatar = await dalAvatar.GetByRace(hero.Race);

                game.HeroImage = avatar.Image;

                //Game Items from database to game parameters
                game.ItemOnGame = new List <ItemOnGame>();
                game.ItemOnGame = await dalItemOnGame.GetAll();

                //save game parameters to session
                HttpContext.Session.SetComplexObject("Game", game);

                return(RedirectToAction("Play", "Game", new { id = 1 }));
            }

            //send List of Avatar for selecting a hero type
            this.ViewBag.ListOfAvatars = await dalAvatar.GetAll();

            return(View(newHero));
        }
Пример #2
0
 public ItemOnGamesController(DalItemOnGame context)
 {
     _dalItemOnGame = context;
 }