예제 #1
0
        public SlotMachineSpinResultDto Spin(decimal stakeAmount)
        {
            var    rowsOfSymbols = new List <List <Symbol> >();
            double coefficient   = 0;
            ISymbolCoefficientProvider symbolCoefficientProvider = _symbolCoefficientProviderFactory.Create();

            for (int i = 0; i < Rows; i++)
            {
                List <Symbol> symbols = _randomSymbolGenerator.Generate(NumberOfSymbolsOnARow);
                rowsOfSymbols.Add(symbols);
                coefficient += symbolCoefficientProvider.GetCoefficient(symbols);
            }

            decimal winAmount = (decimal)coefficient * stakeAmount;

            _player.Balance += winAmount;

            return(new SlotMachineSpinResultDto
            {
                PlayerBalance = _player.Balance,
                Symbols = rowsOfSymbols,
                WinAmount = winAmount,
                IsSuccess = true
            });
        }
예제 #2
0
        private Symbol[,] GenerateReels()
        {
            var machine = new Symbol[_reelSymbolsCount, _reelsCount];

            for (int symbolIndex = 0; symbolIndex < _reelSymbolsCount; symbolIndex++)
            {
                for (int reelIndex = 0; reelIndex < _reelsCount; reelIndex++)
                {
                    var symbol = _randomSymbolGenerator.Generate(_symbolsProvider.GetSymbols());
                    machine[symbolIndex, reelIndex] = symbol;
                }
            }

            return(machine);
        }
        public void WhenNonWinningCombinationIsGeneratedAndSteakIsEqualToBalanceThenBalanceShouldBe0()
        {
            const decimal depositAmount = 100;

            var nonWiningCombination = new Queue <Symbol>
                                       (
                new Symbol[]
            {
                _apple, _banana, _pineapple,
                _apple, _banana, _pineapple,
                _apple, _banana, _pineapple,
                _apple, _banana, _pineapple
            }
                                       );

            _randomSymbolGenerator.Generate(Arg.Any <IReadOnlyCollection <Symbol> >())
            .Returns(_ => nonWiningCombination.Dequeue());
            _slotMachine.Deposit(depositAmount);
            var spinResult = _slotMachine.Spin(depositAmount);

            Assert.That(_slotMachine.Balance, Is.EqualTo(0));
            Assert.That(spinResult.AmountWon, Is.Zero);
        }