public void TestInitialize()
        {
            var mockSlotMachine = new Mock<ISlotMachine>();

            creditCalculator = new CreditCalculator(mockSlotMachine.Object, SPIN_COST, 4);

            player = new Player { TotalCredits = TOTAL_CREDITS };
        }
Ejemplo n.º 2
0
        public void DeductSpinCost(Player player)
        {
            if (player == null) throw new ArgumentNullException("player");

            player.TotalCredits -= SpinCost;

            if (player.TotalCredits < 0) player.TotalCredits = 0;
        }
        public void TestInitialize()
        {
            mockSlotMachine = new Mock<ISlotMachine>();

            creditCalculator = new CreditCalculator(mockSlotMachine.Object, 1, WIN_MULTIPLIER);

            player = new Player { TotalCredits = TOTAL_CREDITS };
        }
Ejemplo n.º 4
0
        public void AddWinnings(Player player)
        {
            if (player == null) throw new ArgumentNullException("player");

            var matchingValue = SlotMachine.MatchingValue;

            if(matchingValue > 0)
                player.TotalCredits += matchingValue * WinMultiplier;
        }
Ejemplo n.º 5
0
        public ActionResult Index(SlotMachineModel model)
        {
            var user = UserManager.FindById(User.Identity.GetUserId());

            if (user != null)
            {
                var creditCalc = new CreditCalculator(SlotMachine, AppSettingsConfig.SpinCost, AppSettingsConfig.WinMultiplier);
                var player = new Player { Name = user.UserName, TotalCredits = user.TotalCredits };

                creditCalc.DeductSpinCost(player);
                SlotMachine.Spin();
                creditCalc.AddWinnings(player);

                if (player.TotalCredits == 0)
                {
                    return RedirectToAction("GameOver", "Home");
                }

                user.TotalCredits = player.TotalCredits;
                UserManager.Update(user);

                model = LoadSlotMachineModel(player.TotalCredits);

                return View(model);
            }

            return RedirectToAction("Login", "Account");
        }