Beispiel #1
0
        private void notifyBetCommand()
        {
            String     playerTurn = model.getLastPlayerBet().getName();
            BetCommand lbc        = model.getLastBetCommand();

            foreach (string playerName in playerDispatcher.Keys)
            {
                playerDispatcher[playerName].dispatch(
                    new GameEvent(GameController.BET_COMMAND_EVENT_TYPE, playerTurn,
                                  new BetCommand(lbc.getType(), lbc.getChips())));
            }
        }
Beispiel #2
0
 public void betCommand(string playerName, BetCommand command)
 {
     if (instance != null && playerName.Equals(model.getPlayerTurnName()))
     {
         BetCommand betCommand = command;
         if (betCommand == null)
         {
             betCommand = new BetCommand(TexasHoldEmUtil.BetCommandType.ERROR);
         }
         model.getPlayerByName(playerName).setBetCommand(betCommand);
         execute();
     }
 }
        /// <summary>
        /// Make bet
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        public async Task <int> MakeBet(BetCommand command)
        {
            DateTime CurrentDate = DateTime.Now;
            int      BetId;
            string   sql = "insert into Bet(UserId,BetString,WonAmount,IpAddress,BetAmount,Status,CreateDate,IsActive,SpinId) values(@UserId,@BetString,@WonAmount,@IpAddress,@BetAmount,@Status,@CreateDate,@IsActive,@SpinId)";

            using (var db = _dbProvider.GetDBInstance())
            {
                db.Open();
                BetId = await db.ExecuteAsync(sql, new { UserId = command.UserId, BetString = command.BetString, WonAmount = command.WonAmount, IpAddress = command.IpAddress, BetAmount = command.BetAmount, Status = command.Status, CreateDate = command.CreateDate, IsActive = command.IsActive, SpinId = command.SpinId });

                db.Close();
            }
            return(BetId);
        }
Beispiel #4
0
        private Dictionary <String, IGameEventProcessor <IStrategy> .process> buildPlayerProcessors()
        {
            Dictionary <String, IGameEventProcessor <IStrategy> .process> ppm = new Dictionary <string, IGameEventProcessor <IStrategy> .process>();

            IGameEventProcessor <IStrategy> .process defaultProcessor = (s, e) => s.updateState((GameInfo <PlayerInfo>)e.getPayload());

            ppm.Add(INIT_HAND_EVENT_TYPE, defaultProcessor);
            ppm.Add(END_GAME_PLAYER_EVENT_TYPE, defaultProcessor);
            ppm.Add(BET_COMMAND_EVENT_TYPE, (s, e) => s.onPlayerCommand(e.getSource(), (BetCommand)e.getPayload()));
            ppm.Add(CHECK_PLAYER_EVENT_TYPE, (s, e) => s.check((List <Card>)e.getPayload()));
            ppm.Add(GET_COMMAND_PLAYER_EVENT_TYPE, (s, e) => {
                GameInfo <PlayerInfo> gi = (GameInfo <PlayerInfo>)e.getPayload();
                String playerTurn        = gi.getPlayers()[(gi.getPlayerTurn())].getName();
                BetCommand cmd           = s.GetCommand(gi);
                connectorDispatcher.dispatch(new GameEvent(BET_COMMAND_EVENT_TYPE, playerTurn, cmd));
            });

            return(ppm);
        }
Beispiel #5
0
        public bool execute(ModelContext model)
        {
            bool         result     = false;
            int          playerTurn = model.getPlayerTurn();
            PlayerEntity player     = model.getPlayer(playerTurn);
            BetCommand   command    = player.getBetCommand();

            if (command != null)
            {
                BetCommand resultCommand = command;
                player.setBetCommand(null);
                long           betChips    = 0;
                BetCommandType commandType = command.getType();
                if (CHECKERS[commandType](model, player, command))
                {
                    betChips = command.getChips();
                    player.setState(TexasHoldEmUtil.convert(command.getType()));
                }
                else
                {
                    commandType = BetCommandType.FOLD;
                    player.setState(PlayerState.FOLD);
                    if (command.getType() == BetCommandType.TIMEOUT)
                    {
                        resultCommand = new BetCommand(BetCommandType.TIMEOUT);
                    }
                    else
                    {
                        resultCommand = new BetCommand(BetCommandType.ERROR);
                    }
                    ModelUtil.incrementErrors(player, model.getSettings());
                }
                ModelUtil.playerBet(model, player, commandType, betChips);
                model.lastResultCommand(player, resultCommand);
                model.setPlayerTurn(ModelUtil.nextPalyer(model, playerTurn));
                result = true;
            }

            return(result);
        }
Beispiel #6
0
        /// <summary>
        /// Make bet
        /// </summary>
        /// <param name="request"> Request from User</param>
        /// <param name="UserId"> current user's Id</param>
        /// <param name="IpAddress">User's IP address</param>
        /// <returns></returns>
        public async Task <BetRow> MakeBet(BetRequest request, int UserId, string IpAddress)
        {
            GenerateSpin();
            int SpinId = await _queryrepository.GetActiveSpin();

            int UserBetPermisson = await _queryrepository.ChekUserBetPermission(SpinId, UserId);

            if (UserBetPermisson > 0)
            {
                throw new ArgumentException("You already have the bet on the current spin, please wait or generate new spin");
            }
            IsBetValidResponse ibvr = CheckBets.IsValid(Convert.ToString(request.BetString));

            if (!ibvr.getIsValid() || ibvr.getBetAmount() <= 0)
            {
                throw new IncorrectBetException("Bet is not in correct format");
            }
            else
            {
                BetRow     betRow  = new BetRow();
                BetCommand command = new BetCommand();
                command.SpinId     = SpinId;
                command.IpAddress  = IpAddress;
                command.UserId     = UserId;
                command.BetAmount  = ibvr.getBetAmount();
                command.WonAmount  = 0;
                command.Status     = BetStatus.Lose;
                command.IsActive   = true;
                command.CreateDate = DateTime.Now;
                command.BetString  = Convert.ToString(request.BetString);

                var UserBalance = await _queryrepository.GetUserBalance(UserId);

                if (UserBalance < command.BetAmount)
                {
                    throw new ArgumentException("you have not enough balance for bet");
                }
                else
                {
                    decimal JakpotAmount = await _queryrepository.CurrentJackpot();

                    int BetId = await _commandrepository.MakeBet(command);

                    JakpotAmount += (ibvr.getBetAmount() * 0.01M);
                    UserBalance  -= (int)command.BetAmount;
                    _commandrepository.UpdateJackpot(JakpotAmount);
                    _commandrepository.UpdateUserBalance(UserId, UserBalance);
                    Random rnd       = new Random();
                    int    WinNumber = rnd.Next(0, 36);
                    // _commandrepository.SetSpinWiningNumber(WinNumber);
                    _commandrepository.SetWinNumber(SpinId, WinNumber);
                    int WinMoney = CheckBets.EstimateWin(Convert.ToString(request.BetString), WinNumber);
                    if (WinMoney > 0)
                    {
                        _commandrepository.UpdateBet(BetId, WinMoney);
                        UserBalance += WinMoney;
                        _commandrepository.UpdateUserBalance(UserId, UserBalance);
                    }
                    betRow.SpinID     = SpinId;
                    betRow.Status     = "Bet accepted";
                    betRow.WInNumber  = WinNumber;
                    betRow.WonAmount  = WinMoney;
                    betRow.CreateDate = DateTime.Now;
                }
                return(betRow);
            }
        }
Beispiel #7
0
 public void setLastBetCommand(BetCommand _resultLastbetCommand)
 {
     this._lastBetCommand = _resultLastbetCommand;
 }
Beispiel #8
0
 public void lastResultCommand(PlayerEntity _player, BetCommand _resultCommand)
 {
     this._lastPlayerBet = _player;
     _lastBetCommand     = _resultCommand;
 }
Beispiel #9
0
 public void setBetCommand(BetCommand _betCommand)
 {
     this._betCommand = _betCommand;
 }