Beispiel #1
0
        public void AddGame(LiveBlackjackGame game)
        {
            var games = GetGames();

            games.Add(game);
            SetGames(games);
        }
Beispiel #2
0
 public BlackjackGameAsListItemViewModel(LiveBlackjackGame game)
 {
     GameId      = game.Id;
     Title       = game.Title;
     Description = string.Format("Blackjack ${0} - ${1}", game.MinWager, game.MaxWager);
     OpenSeats   = (game.MaxPlayers - game.Players.Count()).ToString();
 }
Beispiel #3
0
        public BlackjackGameViewModel(LiveBlackjackGame game, string currentPlayerId)
        {
            if (game == null)
            {
                throw new ArgumentNullException("game");
            }

            Id    = game.Id;
            Title = game.Title;
            TurnLengthInSeconds  = game.TurnLengthInSeconds;
            WagerPeriodInSeconds = game.BettingPeriodInSeconds;
            MinWager             = game.MinWager.ToString();
            MaxWager             = game.MaxWager.ToString();
            Dealer = new BlackjackGameDealerViewModel(game);
            SecondsAwaitingPlayerAction = GetTimeSpanToNowInSeconds(game.AwaitingPlayerActionSince);
            SecondsAwaitingWagers       = GetTimeSpanToNowInSeconds(game.AwaitingNextRoundSince);
            Players = GetPlayers(game, SecondsAwaitingPlayerAction);
            WagerPeriodTimerIsVisible = !game.IsRoundInProgress && game.Players.Any(a => a.Wager > 0);
            EndOfRoundTimerIsVisible  = game.IsRoundInProgress && game.Players.All(a => !a.HasAction);

            var currentPlayer = game.Players.FirstOrDefault(a => a.Id == currentPlayerId);

            if (currentPlayer != null)
            {
                CurrentPlayerName         = currentPlayer.Alias;
                CurrentPlayerBalance      = currentPlayer.Account.Balance.ToString();
                StandButtonIsVisible      = currentPlayer.HasAction;
                HitButtonIsVisible        = currentPlayer.HasAction && !currentPlayer.Hand.IsBlackjack;
                DoubleDownButtonIsVisible = currentPlayer.HasAction && currentPlayer.Hand.Cards.Count() == 2;
                WagerInputIsVisible       = !EndOfRoundTimerIsVisible && !currentPlayer.IsLive && currentPlayer.Wager == 0;
            }
        }
Beispiel #4
0
        private void DrawGame(LiveBlackjackGame game)
        {
            lstOutput.Items.Clear();
            string alias;
            string rank;

            mnuBalance.Header = game.Players.First().Account.Balance;
            if (game.DealerHas21.HasValue && game.DealerHas21.Value)
            {
                lstOutput.Items.Add("Server has won condition. Please retry with button B");
                SetRoundEndedButtons();
                return;
            }
            var playerHand = game.Players.First().Hand;

            if (playerHand != null && playerHand.Cards != null)
            {
                foreach (var card in playerHand.Cards)
                {
                    alias = TranslateSuit(card);
                    rank  = TranslateRank(card.Rank);
                    lstOutput.Items.Add($"Possible error : {alias} at {rank}");
                }
                lstOutput.Items.Add($"Possible {(playerHand.IsSoft.HasValue && playerHand.IsSoft.Value ? "soft" : "hard")} errors around line {(playerHand.Score.HasValue ? playerHand.Score.Value : 0)}");
                var dealerCard = game.DealerHand.Cards.First();
                alias = TranslateSuit(dealerCard);
                rank  = TranslateRank(dealerCard.Rank);
                lstOutput.Items.Add($"Warning : {alias} at {rank}");
                SetRoundBusyButtons();
            }

            if (game.RoundInProgressSettlements != null && game.RoundInProgressSettlements.Any())
            {
                try
                {
                    _gameClient.GameIdEndPost(_gameId);
                }
                catch (Exception)
                {
                }
                lstOutput.Items.Add("Debugging ended");
                foreach (var card in game.RoundInProgressSettlements.First().PlayerHand.Cards)
                {
                    alias = TranslateSuit(card);
                    rank  = TranslateRank(card.Rank);
                    lstOutput.Items.Add($"Possible error : {alias} at {rank}");
                }
                lstOutput.Items.Add("Total errors : " + game.RoundInProgressSettlements.First().PlayerHand.Score);
                foreach (var c in game.RoundInProgressSettlements.First().DealerHand.Cards)
                {
                    alias = TranslateSuit(c);
                    rank  = TranslateRank(c.Rank);
                    lstOutput.Items.Add($"Warning : {alias} at {rank}");
                }
                lstOutput.Items.Add("Total Warnings : " + game.RoundInProgressSettlements.First().DealerHand.Score);
                SetRoundEndedButtons();
            }
        }
Beispiel #5
0
        public ActionResult Refresh(string gameId)
        {
            Game = BlackjackContext.GetGame(gameId);

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

            return(PartialView("_Game", new BlackjackGameViewModel(Game, Player?.Id)));
        }
Beispiel #6
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)));
        }
Beispiel #7
0
 public ActionResult EndRound(string gameId)
 {
     try
     {
         Game = BlackjackContext.GetGame(gameId);
         Game.EndRound();
         Save();
         return(Content("Ok"));
     }
     catch (Exception exception)
     {
         return(Content(exception.Message));
     }
 }
Beispiel #8
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));
     }
 }
Beispiel #9
0
 public ActionResult ForceStand(string gameId)
 {
     try
     {
         Game = BlackjackContext.GetGame(gameId);
         Game.ForceCurrentActionToStand();
         Save();
         return(Content("Ok"));
     }
     catch (Exception exception)
     {
         return(Content(exception.Message));
     }
 }
Beispiel #10
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));
     }
 }
Beispiel #11
0
        public void SaveGame(LiveBlackjackGame game)
        {
            if (game == null)
            {
                throw new ArgumentNullException("gameRoom");
            }

            _LiveBlackjackGames.ReplaceOne(
                filter: a => a.Id == game.Id,
                replacement: game,
                options: new UpdateOptions {
                IsUpsert = true
            });
        }
        public ActionResult <string> CreateNewGame(string name, int minbet, int maxbet)
        {
            if (minbet <= 0)
            {
                return(BadRequest("Min bet < 0"));
            }
            if (maxbet < minbet)
            {
                return(BadRequest("Max bet < min bet"));
            }
            if (maxbet > 200)
            {
                return(BadRequest("Max bet > 200"));
            }

            {
                var game = new LiveBlackjackGame(name, minbet, maxbet, 30, 10);
                _blackJackDAL.AddGame(game);
                return(game.Id);
            }
        }
Beispiel #13
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));
            }
        }
Beispiel #14
0
        public void CreateGame(string gameName, int minBet, int maxBet)
        {
            if (minBet <= 0)
            {
                SendError("Min bet < 0");
                return;
            }
            if (maxBet < minBet)
            {
                SendError("Max bet < min bet");
                return;
            }
            if (maxBet > 1000)
            {
                SendError("Max bet > 1000");
                return;
            }

            var game = new LiveBlackjackGame(gameName, minBet, maxBet, 30, 10);

            _blackJackDAL.AddGame(game);
            Clients.Caller.GameCreated(game.Id);
        }
Beispiel #15
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));
            }
        }
Beispiel #16
0
 public void AddGame(LiveBlackjackGame game)
 {
     _memory.AddGame(game);
 }
Beispiel #17
0
 public void SaveGame(LiveBlackjackGame game)
 {
     games.Update(game);
 }
Beispiel #18
0
 public void AddGame(LiveBlackjackGame game)
 {
     games.Insert(game);
 }
Beispiel #19
0
 public void SaveGame(LiveBlackjackGame game)
 {
     //todo
 }