Ejemplo n.º 1
0
        public Response Spin(int playerId, decimal betAmount)
        {
            var slots = new string[3, 5];

            WheelSpin();

            var winnings  = new List <Winnings>();
            var winAmount = 0.00m;
            var win       = false;

            do
            {
                Cascade(winnings);

                for (var line = 0; line < 3; line++)
                {
                    for (var wheel = 0; wheel < 5; wheel++)
                    {
                        var index  = _wheels.Wheel[wheel].Skip(2 - line).First();                //get symbol index
                        var symbol = _reel.GetReelWheel(wheel).First(r => r.Key == index).Value; //get symbol base on the index

                        slots[line, wheel] = symbol;                                             // assign / reassign the slot symbol
                    }
                }

                winnings = CheckPlayerWin(slots);

                if (winnings.Any())
                {
                    win = true;
                }

                winAmount += _win.ComputeWinnings(winnings, betAmount);
            } while (winnings.Any());

            var str = string.Join(",", slots.OfType <string>()
                                  .Select((value, index) => new { value, index })
                                  .GroupBy(x => x.index / slots.GetLength(1))
                                  .Select(x => $"{{{string.Join(",", x.Select(y => y.value))}}}"));

            return(new Response()
            {
                SlotResult = str,
                WinAmount = winAmount,
                Transaction = win ? "Win" : "Lose"
            });
        }
Ejemplo n.º 2
0
        public string[,] Spin(int playerId, decimal betAmount)
        {
            var gameId = GenerateGameId();

            var activeSlotDimensionArray = new string[3, 5];

            WheelSpin();

            var stillWinning = false;

            CheckIfPlayerHasBonusSpin(ref betAmount, playerId);

            do
            {
                // Populate the slots based on the spin per wheel...
                //
                // If still winning, (Winning symbols were deleted in the 'CheckIfPlayerHasWinningCombinations' function.)
                // Wheel[i] array were re-arrange because we deleted some items (winning symbol)
                // Get the indices in the array (top 3)
                // Repopulate the slots array with the new symbols / retain the not winning symbol (Cascade)
                #region Example
                // As we spin the array will move base on the roll.
                // example: wheel1 array is { 8, 7, 6, 5, 4... }
                // get the top 3 as line in array [0,0], [1,0] [2,0] = (6, 7, 8)
                // let say the winning line is '1' a straight line (array [1,0], [1,1], [1,2], [1,3], [1,4])
                // in our wheel1 the winning line is index 7. compute the win amount in CheckIfPlayerHasWinningCombinations function and we will delete the index 7 in wheel1 array.
                // remaining wheel1 array will be { 8, 6, 5, 4, 3... }
                // repopulate the slot array, in wheel1 will be { 5, 6, 8 } -(cascaded symbols)
                #endregion
                for (var line = 0; line < 3; line++)
                {
                    for (var wheel = 0; wheel < 5; wheel++)
                    {
                        var index  = _wheels.Wheel[wheel].Skip(2 - line).First();                //get symbol index
                        var symbol = _reel.GetReelWheel(wheel).First(r => r.Id == index).Symbol; //get symbol base on the index

                        activeSlotDimensionArray[line, wheel] = symbol;                          // assign / reassign the slot symbol
                    }
                }

                stillWinning = CheckIfPlayerHasWinningCombinations(activeSlotDimensionArray, playerId, stillWinning, betAmount, gameId); //Check if the slot combination has winning combinations
            } while (stillWinning);

            return(activeSlotDimensionArray);
        }