Exemplo n.º 1
0
        public ActionResult Simulate(string mode = "easy")
        {
            AspNetUser user = CSharpDbDAL.GetContextUser(User.Identity.Name);

            if (TempData["Monstars"] is null)
            {
                //Generate monstars based on Easy, Normal, or Hard
                TempData["Monstars"] = GenerateMonstarByMode(mode);
            }

            if (TempData["MyTeam"] is null)
            {
                TempData["MyTeam"] = CSharpDbDAL.GetTeamAsUserPlayer(user.Id);
            }

            List <UserPlayer> myTeam = (List <UserPlayer>)TempData["MyTeam"];

            if (myTeam.Count < 5)
            {
                string noun = (5 - myTeam.Count) > 1 ? "players" : "player";
                TempData["Message"] = $"You need {5 - myTeam.Count} more {noun} before you battle the Monstars";
                return(View("Battle"));
            }

            var match = Arena();

            CSharpDbDAL.UpdateTeamStats(user.Id, match.Item1);

            ViewBag.Message = match.Item2;

            return(View());
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    Session["CurrentUser"] = CSharpDbDAL.GetContextUser(User.Identity.Name);
                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }

                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
                Session["CurrentUser"] = CSharpDbDAL.GetContextUser(model.Email);
                return(RedirectToLocal(returnUrl));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }
Exemplo n.º 4
0
        public ActionResult PlayerStats(string playerId)
        {
            AspNetUser currentUser = CSharpDbDAL.GetContextUser(User.Identity.Name);
            Player     player      = CSharpDbDAL.GetUserPlayer(currentUser.Id, playerId);

            return(View(player));
        }
Exemplo n.º 5
0
        public ActionResult TeamManagement()
        {
            AspNetUser currentUser = CSharpDbDAL.GetContextUser(User.Identity.Name);
            Team       team        = CSharpDbDAL.GetTeam(currentUser.Id);

            return(View(team));
        }
Exemplo n.º 6
0
        public ActionResult Index()
        {
            // create their team
            AspNetUser currentUser = CSharpDbDAL.GetContextUser(User.Identity.Name);

            if (currentUser != null)
            {
                Team currentUserTeam = CSharpDbDAL.GetTeam(currentUser.Id);

                if (currentUserTeam == null)
                {
                    currentUserTeam = new Team()
                    {
                        Name     = $"Team {currentUser.Email.Split('@')[0]}",
                        OwnerId  = currentUser.Id,
                        Location = "Earth"
                    };

                    if (!CSharpDbDAL.AddTeam(currentUserTeam))
                    {
                        Console.WriteLine("Failed to add team");
                    }
                }
            }

            return(View());
        }
Exemplo n.º 7
0
        public ActionResult Battle()
        {
            TempData["Message"]  = "";
            TempData["Monstars"] = CSharpDbDAL.GetTeamAsUserPlayer(MONSTAR_OWNER_ID);
            AspNetUser user = CSharpDbDAL.GetContextUser(User.Identity.Name);

            TempData["MyTeam"] = CSharpDbDAL.GetTeamAsUserPlayer(user.Id);
            return(View());
        }
Exemplo n.º 8
0
        public ActionResult RemovePlayer(string playerId)
        {
            Player player = CSharpDbDAL.GetPlayer(playerId,
                                                  CSharpDbDAL.GetContextUser(User.Identity.Name).Id);

            if (player != null)
            {
                CSharpDbDAL.DeletePlayer(player);
            }

            return(RedirectToAction("TeamManagement"));
        }
Exemplo n.º 9
0
        public Tuple <bool, string> Arena()
        {
            AspNetUser currentUser = CSharpDbDAL.GetContextUser(User.Identity.Name);

            List <UserPlayer> monstarsDown = new List <UserPlayer>();
            List <UserPlayer> monstars     = CSharpDbDAL.GetTeamAsUserPlayer(MONSTAR_OWNER_ID);

            List <UserPlayer> myTeam     = CSharpDbDAL.GetTeamAsUserPlayer(currentUser.Id);
            List <UserPlayer> myTeamDown = new List <UserPlayer>();

            List <UserPlayer> HeadToHead = new List <UserPlayer>();

            while (myTeam.Count >= 1 && monstars.Count >= 1)
            {
                //Players are picked at random from each team to go against each other
                int myTeamIndex  = new Random().Next(0, myTeam.Count);
                int monstarIndex = new Random().Next(0, monstars.Count);

                HeadToHead = new List <UserPlayer>
                {
                    myTeam[myTeamIndex],
                    monstars[monstarIndex]
                };

                //One player from each team goes against each other
                MatchUp(HeadToHead);

                //If my team player has no health
                if (HeadToHead[0].Health <= 0)
                {
                    RemoveDownedPlayer(myTeam, myTeamDown, myTeamIndex);
                }

                //If monstar player is downed
                if (HeadToHead[1].Health <= 0)
                {
                    RemoveDownedPlayer(monstars, monstarsDown, monstarIndex);
                }
            }

            if (myTeam.Count >= 1)
            {
                return(Tuple.Create(true, $"You won {myTeam.Count}-{monstars.Count}"));
            }

            string message = $"The Monstars won {monstars.Count}-{myTeam.Count}";

            //Tuple to return win as bool and a custom message
            return(Tuple.Create(false, message));
        }
Exemplo n.º 10
0
        public ActionResult AddTeam(Team team)
        {
            team.Draw = team.Lost = team.Win = 0;

            if (Session["CurrentUser"] is null)
            {
                Session["CurrentUser"] = CSharpDbDAL.GetContextUser(User.Identity.Name);
            }

            AspNetUser user = (AspNetUser)Session["CurrentUser"];

            team.OwnerId = user.Id;
            CSharpDbDAL.AddTeam(team);
            ViewBag.Message = $"Team {team.Name} added successfully!";

            return(View());
        }