Пример #1
0
        public IActionResult Index()
        {
            CharactersViewModel model = new CharactersViewModel();

            //Get the names of the players that won this game
            using (var context = new EFCoreGameWebContext())
            {
                model.scoreboard = context.ScoreBoards.ToList();
            }

            model.hero = new HeroModel();

            return(View(model));
        }
Пример #2
0
        public IActionResult Index()
        {
            CharactersViewModel model = new CharactersViewModel();

            using (var context = new EFCoreGameWebContext())
            {
                model.scoreBoard = context.ScoreBoards.ToList();
            }

            model.hero = new HeroModel();



            return(View(model));
        }
Пример #3
0
        public JsonResult FightEnemy(CharactersViewModel model)
        {
            /*
             * Now I can capture the weapon value and the enemy.
             * based on the name of the enemy, I can reduce it's health
             * based on the points.
             */


            int points = Convert.ToInt32(model.selectedWeapon);

            switch (model.selectedWeapon)
            {
            case "1000":
                points = Convert.ToInt32(model.selectedWeapon);
                model.alien.healthPoints = model.alien.healthPoints - points;

                model.hero.heroLives = model.alien.healthPoints > 0 ? model.hero.heroLives - 1 : model.hero.heroLives + 1;
                break;

            case "500":
                points = Convert.ToInt32(model.selectedWeapon);
                model.alien.healthPoints = model.alien.healthPoints + points;

                model.hero.heroLives = model.alien.healthPoints > 0 ? model.hero.heroLives - 1 : model.hero.heroLives + 1;
                break;

            case "100":
                points = Convert.ToInt32(model.selectedWeapon);

                model.alien.healthPoints = model.alien.healthPoints - points;
                model.hero.heroLives     = model.alien.healthPoints > 0 ? model.hero.heroLives - 1 : model.hero.heroLives + 1;
                break;
            }

            if (model.hero.heroLives <= 0)
            {
                model.gameStatus = string.Format("Dude! You just died!");
                return(Json(model));
                //return View(model);
            }
            else
            {
                model = ChangeEnemy(model);
                if (model.alien.alienName != "End")
                {
                    //return View("Characters", ChangeEnemy(model));
                    return(Json(ChangeEnemy(model)));
                }
                else
                {
                    //Save the name of the player that just won
                    ScoreBoard scoreBoardModel = new ScoreBoard();
                    scoreBoardModel.name = model.hero.heroName;

                    using (var context = new EFCoreGameWebContext())
                    {
                        context.Add(scoreBoardModel);
                        context.SaveChanges();
                    }

                    model.gameStatus = string.Format("Dude! You just won!");
                    //return View(model);
                    return(Json(model));
                }
            }

            return(Json("{name: 'value1'}"));
        }