Ejemplo n.º 1
0
        public ActionResult Index(string id)
        {
            Game = BlackjackContext.GetGame(id);

            if (Game == null)
            {
                return(RedirectToAction("index", "lobby"));
            }

            return(View("index", new BlackjackGameViewModel(Game, Player?.Id)));
        }
Ejemplo n.º 2
0
        public ActionResult Refresh(string gameId)
        {
            Game = BlackjackContext.GetGame(gameId);

            if (Game == null)
            {
                return(new EmptyResult());
            }

            return(PartialView("_Game", new BlackjackGameViewModel(Game, Player?.Id)));
        }
Ejemplo n.º 3
0
 public ActionResult RemoveGamePlayer(string gameId)
 {
     try
     {
         Game = BlackjackContext.GetGame(gameId);
         Game.RemovePlayer(Player);
         Save();
         return(Content("Ok"));
     }
     catch (Exception exception)
     {
         return(Content(exception.Message));
     }
 }
Ejemplo n.º 4
0
 public ActionResult EndRound(string gameId)
 {
     try
     {
         Game = BlackjackContext.GetGame(gameId);
         Game.EndRound();
         Save();
         return(Content("Ok"));
     }
     catch (Exception exception)
     {
         return(Content(exception.Message));
     }
 }
Ejemplo n.º 5
0
 public ActionResult PlayerActionRequest(string gameId, string request)
 {
     try
     {
         Game = BlackjackContext.GetGame(gameId);
         Game.PlayerActionRequest(Player, request);
         Save();
         return(Content("Ok"));
     }
     catch (Exception exception)
     {
         return(Content(exception.Message));
     }
 }
Ejemplo n.º 6
0
 public ActionResult ForceStand(string gameId)
 {
     try
     {
         Game = BlackjackContext.GetGame(gameId);
         Game.ForceCurrentActionToStand();
         Save();
         return(Content("Ok"));
     }
     catch (Exception exception)
     {
         return(Content(exception.Message));
     }
 }
Ejemplo n.º 7
0
        private void Save()
        {
            if (Game == null)
            {
                throw new InvalidOperationException("Cannot load game");
            }

            BlackjackContext.SaveGame(Game);

            if (Player != null)
            {
                HttpContext.Session["Balance"] = Player.Account.Balance;
            }

            GlobalHost.ConnectionManager
            .GetHubContext <BlackjackGameRoomHub>()?
            .Clients?
            .Group(Game.Id.ToString())?
            .refresh();
        }
Ejemplo n.º 8
0
        public ActionResult PlayerBetRequest(string gameId, string betAmount)
        {
            try
            {
                double bet = 0;
                if (!double.TryParse(betAmount, out bet))
                {
                    throw new Exception("Invalid bet");
                }

                Game = BlackjackContext.GetGame(gameId);
                Game.PlayerWagerRequest(Player, bet);
                Session["WagerAmount"] = bet;
                Save();
                return(Content("Ok"));
            }
            catch (Exception exception)
            {
                return(Content(exception.Message));
            }
        }
Ejemplo n.º 9
0
        public ActionResult PlayerJoinRequest(string gameId, string playerName, string _seatNo)
        {
            try
            {
                int seatNo = 0;
                if (!int.TryParse(_seatNo, out seatNo))
                {
                    throw new Exception("Invaid seat number");
                }

                Game = BlackjackContext.GetGame(gameId);

                double balance = 1000;
                if (HttpContext.Session["Balance"] == null || (double)HttpContext.Session["Balance"] <= 0)
                {
                    HttpContext.Session["Balance"] = balance;
                }
                else
                {
                    balance = (double)HttpContext.Session["Balance"];
                }

                var account = new PlayerAccount(
                    id: HttpContext.Session.SessionID,
                    startingBalance: balance);

                Game.AddPlayer(account, playerName, seatNo);

                Save();
                return(PartialView("_PlayerChatInput", seatNo));
            }
            catch (Exception exception)
            {
                return(Content(exception.Message));
            }
        }