Example #1
0
 public Spinner(
     IElementsMatrix machineSlots,
     IRandomElementPicker randomElementPicker,
     IWinCalculator winCalculator)
 {
     this.machineSlots        = machineSlots;
     this.randomElementPicker = randomElementPicker;
     this.winCalculator       = winCalculator;
 }
Example #2
0
        public decimal Calculate(IElementsMatrix slotElementsMatrix, decimal bet)
        {
            decimal winAmount = 0;

            foreach (var winningCombination in this.winningCombinations)
            {
                winAmount += winningCombination.CalculateWinAmount(slotElementsMatrix, bet);
            }

            return(winAmount);
        }
        public decimal CalculateWinAmount(IElementsMatrix matrix, decimal bet)
        {
            decimal winAmount = 0;

            for (int row = 0; row < matrix.Rows; row++)
            {
                int         startColIdx      = 0;
                SlotElement comparingElement = null;

                //Get first non wildcard element and its position
                while (startColIdx < matrix.Columns)
                {
                    if (matrix.Slots[row, startColIdx].Symbol != _wildcard)
                    {
                        comparingElement = matrix.Slots[row, startColIdx];
                        break;
                    }
                    startColIdx++;
                }

                // Iterate to the end of the row to see if all elements are the same
                // and to sum up their coeficient.
                double coeficientSum = comparingElement?.Coeficient ?? 0;
                bool   winningLine   = true;
                for (int col = startColIdx + 1; col < matrix.Columns; col++)
                {
                    SlotElement current = matrix.Slots[row, col];

                    if (comparingElement.Symbol != current.Symbol &&
                        current.Symbol != _wildcard)
                    {
                        winningLine = false;
                        break;
                    }
                    coeficientSum += current.Coeficient;
                }

                if (winningLine)
                {
                    winAmount += (decimal)coeficientSum * bet;
                }
            }

            return(Math.Round(winAmount, 1));
        }
Example #4
0
 public UserInterface(IElementsMatrix machineSlots)
 {
     this.machineSlots = machineSlots;
 }