Ejemplo n.º 1
0
        private bool IsValidBet(BetInfo betInfo)
        {
            bool      isValid        = false;
            const int MAX_BET_AMOUNT = 10000;

            if (betInfo != null)
            {
                bool isValidAmount   = betInfo.StakeAmount > 0 && betInfo.StakeAmount <= MAX_BET_AMOUNT;
                bool isNumericBet    = int.TryParse(betInfo.ExpectedValue, out int bettedNumber);
                bool isValidBetValue = isNumericBet ? bettedNumber >= Roulette.MIN_NUMBER && bettedNumber <= Roulette.MAX_NUMBER : betInfo.ExpectedValue.Equals(Roulette.RED_COLOR_VALUE) || betInfo.ExpectedValue.Equals(Roulette.BLACK_COLOR_VALUE);
                isValid = isValidAmount && isValidBetValue;
            }
            return(isValid);
        }
Ejemplo n.º 2
0
 private void CheckBet(BetInfo bet)
 {
     if (bet != null && this.WinningNumber >= 0)
     {
         bool  isNumericBet = int.TryParse(bet.ExpectedValue, out int bettedNumber);
         bool  isWinnerBet  = isNumericBet ? bettedNumber.Equals(this.WinningNumber) : bet.ExpectedValue.Equals(this.WinningColor);
         float winFactor    = 0;
         if (isWinnerBet)
         {
             winFactor = isNumericBet ? NUMERIC_BET_WIN_FACTOR : COLOR_BET_WIN_FACTOR;
         }
         bet.WinnedValue = bet.StakeAmount * winFactor;
     }
 }
Ejemplo n.º 3
0
        public void MakeBet(BetInfo betInfo, int rouletteId, string userId)
        {
            Roulette rouletteInfo = this.RouletteRepository.GetById(rouletteId: rouletteId);

            if (rouletteInfo != null && rouletteInfo.IsOpen)
            {
                var  rouletteOwner      = rouletteInfo.UserId;
                bool isSameRouletteUser = rouletteOwner.Equals(userId);
                if (isSameRouletteUser)
                {
                    if (this.IsValidBet(betInfo))
                    {
                        rouletteInfo.MakeBet(betInfo);
                        this.RouletteRepository.SaveBets(roulette: rouletteInfo);
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public void MakeBet(BetInfo betInfo)
 {
     betInfo.RouletteId = this.RouletteId;
     this.Bets.Add(betInfo);
 }