Beispiel #1
0
        public void TestCalculateProfit_Example()
        {
            SlotMachineModel testSlotMachine = new SlotMachineModel();
            ImageEntity      row1            = new ImageEntity
            {
                LeftSource       = ConstantsClass.SymbolImageSources[1],
                LeftCoefficent   = ConstantsClass.SymbolCoefficients[1],
                MiddleSource     = ConstantsClass.SymbolImageSources[0],
                MiddleCoefficent = ConstantsClass.SymbolCoefficients[0],
                RightSource      = ConstantsClass.SymbolImageSources[0],
                RightCoefficent  = ConstantsClass.SymbolCoefficients[0]
            };

            testSlotMachine.Sources[0] = row1;

            ImageEntity row2 = new ImageEntity
            {
                LeftSource       = ConstantsClass.SymbolImageSources[0],
                LeftCoefficent   = ConstantsClass.SymbolCoefficients[0],
                MiddleSource     = ConstantsClass.SymbolImageSources[0],
                MiddleCoefficent = ConstantsClass.SymbolCoefficients[0],
                RightSource      = ConstantsClass.SymbolImageSources[0],
                RightCoefficent  = ConstantsClass.SymbolCoefficients[0]
            };

            testSlotMachine.Sources[1] = row2;

            ImageEntity row3 = new ImageEntity
            {
                LeftSource       = ConstantsClass.SymbolImageSources[0],
                LeftCoefficent   = ConstantsClass.SymbolCoefficients[0],
                MiddleSource     = ConstantsClass.SymbolImageSources[2],
                MiddleCoefficent = ConstantsClass.SymbolCoefficients[2],
                RightSource      = ConstantsClass.SymbolImageSources[1],
                RightCoefficent  = ConstantsClass.SymbolCoefficients[1]
            };

            testSlotMachine.Sources[2] = row3;

            ImageEntity row4 = new ImageEntity
            {
                LeftSource       = ConstantsClass.SymbolImageSources[2],
                LeftCoefficent   = ConstantsClass.SymbolCoefficients[2],
                MiddleSource     = ConstantsClass.SymbolImageSources[0],
                MiddleCoefficent = ConstantsClass.SymbolCoefficients[0],
                RightSource      = ConstantsClass.SymbolImageSources[0],
                RightCoefficent  = ConstantsClass.SymbolCoefficients[0]
            };

            testSlotMachine.Sources[3] = row4;

            testSlotMachine.Bet     = 10;
            testSlotMachine.Balance = 200;

            _slotmachine.CalculateProfit(ref testSlotMachine);

            Assert.Equal(20, testSlotMachine.Won);
        }
Beispiel #2
0
        /// <summary>
        /// CalculateBalance method
        /// </summary>
        /// <param name="model"></param>
        /// <param name="bet"></param>
        /// <returns></returns>
        private SlotMachineModel CalculateBalance(SlotMachineModel model, SlotMachineModel bet)
        {
            if (model.Bet != 0)
            {
                bet.Bet = model.Bet;

                _slotmachine.CalculateProfit(ref bet);

                bet.Balance       = ((model.Balance - model.Bet + bet.Won) >= 0) ? Math.Round((model.Balance - model.Bet + bet.Won), 2, MidpointRounding.AwayFromZero) : 0;
                bet.Bet           = (bet.Balance != 0) ? model.Bet : 0;
                bet.IsGameRunning = (bet.Balance != 0) ? model.IsGameRunning : false;
                bet.IsGameOver    = (bet.Balance == 0) ? true : false;
            }

            return(bet);
        }