Exemplo n.º 1
0
        /***
         * Spin Action - Game Play
         **/
        public IActionResult SpinIt(SpinViewModel spinvm) //TODO: replace the parameter with a ViewModel
        {
            _        = spinvm.Luck;
            spinvm.A = random.Next(1, 10);
            spinvm.B = random.Next(1, 10);
            spinvm.C = random.Next(1, 10);


            spinvm.IsWinning = (spinvm.A == spinvm.Luck || spinvm.B == spinvm.Luck || spinvm.C == spinvm.Luck);

            //Add to Spin Repository

            _repository.AddSpin(spin);


            //TODO: Clean up ViewBag using a SpinIt ViewModel instead
            if (spinvm.IsWinning)
            {
                Display = "block";
            }
            else
            {
                Display = "none";
            }


            return(View("SpinIt", spinvm));
        }
Exemplo n.º 2
0
        public ResultDto StartUser(SpinViewModel model, User user)
        {
            user.Credits -= model.Bet;
            var casinoInfo = _context.CasinoInfo.FirstOrDefault(c => c.Id == Constants.CasinoId);

            casinoInfo.CasinoCash += model.Bet;
            SpinDto result;
            int     win;

            do
            {
                result = Spin();
                win    = ToWin(result, model);
            } while (casinoInfo.CasinoCash - win < Constants.CasinoMoneylim);

            _transactionService.AddTransaction(user.UserName, model.Bet, win);
            if (win > 0)
            {
                user.Credits          += win;
                casinoInfo.CasinoCash -= win;
                if (user.RefUserName != null)
                {
                    ReferralReward(win, user.RefUserName);
                }

                if (win > user.BestScore)
                {
                    user.BestScore = win;
                }
            }

            _context.Update(user);
            _context.SaveChangesAsync();
            return(new ResultDto(result, win, user));
        }
        public async Task <IActionResult> Start(SpinViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new
                {
                    status = false,
                    statusMessage = HttpUtility.JavaScriptStringEncode("Bad Model", false)
                }));
            }
            if (model.Credits < model.Bet)
            {
                return(Json(new
                {
                    status = false,
                    statusMessage = HttpUtility.JavaScriptStringEncode("You need more credits for this bet!", false)
                }));
            }

            if (!_signInManager.IsSignedIn(HttpContext.User))
            {
                return(Json(_spinService.StartGuest(model)));
            }
            if (_userManager.GetUserAsync(User).Result.Credits < model.Bet)
            {
                return(Json(new
                {
                    status = false,
                    statusMessage = HttpUtility.JavaScriptStringEncode("You need more credits for this bet!", false)
                }));
            }
            var user = await _userManager.GetUserAsync(User);

            return(Json(_spinService.StartUser(model, user)));
        }
Exemplo n.º 4
0
        /***
         * Spin Action
         **/

        public IActionResult Spin() //Start a Spin WITHOUT data
        {
            //CHARGE
            // TODO: Load Player balance from the repoService
            decimal balance;

            //TODO: Charge $0.50 to spin


            //SPIN
            //TODO: Complete adding data to a new SpinViewModel to gather items for the View
            SpinViewModel spinVM = new SpinViewModel
            {
                //CurrentBalance = string.Format(new CultureInfo("en-SG", false), "{0:C2}", balance),
            };

            //GAMEPLAY
            //TODO: Check the Balance to see if the game is over

            //TODO: Pay $1.00 if Winning


            //UPDATE DATA STORE
            //TODO: Save balance to repoService


            //TODO: Use the repoService to add a spin to the repository


            return(View("Spin", spinVM));
        }
Exemplo n.º 5
0
        public ActionResult Spin(SpinViewModel mySpin)
        {
            //Get the current player from the Database
            int    id            = Convert.ToInt32(Session["PlayerId"]);
            Player currentPlayer = dbc.Players.Single(p => p.PlayerID == id);

            //TODO: Update the Spin ViewModel with current player's lucky number

            mySpin.Number = currentPlayer.Number;

            //Game Play - Spin
            if (currentPlayer.Balance > 0)
            {
                currentPlayer.Balance -= 1; //charge for a spin
                mySpin.spin();
            }
            //Game Play - Check Winning
            if (mySpin.isWinner)
            {
                currentPlayer.Balance += 2; //collect winnings
            }

            //TODO: Update the Spin ViewModel with the cuurent player's new balance
            mySpin.Balance = currentPlayer.Balance;

            //TODO: Update Database
            dbc.SaveChanges();

            return(View(mySpin));
        }
Exemplo n.º 6
0
        /***
         * Spin Action - Game Play
         **/
        public IActionResult SpinIt(SpinViewModel spinVM) //TODO: replace the parameter with a ViewModel
        {
            if (_repository._player.ChargeSpin())
            {
                SpinViewModel spin = new SpinViewModel
                {
                    Luck = spinVM.Luck,
                    A    = random.Next(1, 10),
                    B    = random.Next(1, 10),
                    C    = random.Next(1, 10)
                };

                //Add to Spin Repository
                _repository.AddSpin(spin);

                spin.Winner = (spin.A == spin.Luck || spin.B == spin.Luck || spin.C == spin.Luck);
                if (spin.Winner)
                {
                    _repository._player.CollectWinnings();
                }

                //TODO: Clean up ViewBag using a SpinIt ViewModel instead
                ViewBag.ImgDisplay = (spin.Winner) ? "block" : "none";
                ViewBag.FirstName  = spinVM.FirstName;
                ViewBag.Balance    = _repository._player.Balance;
                return(View("SpinIt", spin));
            }
            else
            {
                return(RedirectToAction("LuckList"));
            }
        }
Exemplo n.º 7
0
 private int ToWin(SpinDto spin, SpinViewModel model)
 {
     return(spin.WinType switch
     {
         1 => (int)Math.Pow(4, 2) * (model.Bet - 1) + 4,
         2 => (int)Math.Pow(2, 2) * (model.Bet - 1) + 2,
         _ => - model.Bet
     });
Exemplo n.º 8
0
 public ResultDto(SpinDto spin, int win, SpinViewModel model)
 {
     A            = spin.A;
     B            = spin.B;
     C            = spin.C;
     D            = spin.D;
     NewBestScore = model.BestScore;
     NewCredits   = model.Credits;
     WinValue     = win;
 }
        /***
         * SpinIt Action
         **/

        public IActionResult SpinIt(int id) //change parameter to receive players Id
        {
            //Get the player with the given Id using the Players DbSet Find(Id) method
            var currentPlayer = _dbc.Players.Include(p => p.Spins).Single(p => p.Id == id);

            if (currentPlayer == null)
            {
                return(View("Index"));
            }

            //Build a new SpinItViewModel object with data from the Player and spin
            SpinViewModel spinVM = new SpinViewModel()
            {
                FirstName = currentPlayer.FirstName,
                Balance   = currentPlayer.Balance,
                Luck      = currentPlayer.Luck,
                A         = random.Next(1, 10),
                B         = random.Next(1, 10),
                C         = random.Next(1, 10)
            };

            spinVM.IsWinning = (spinVM.A == spinVM.Luck || spinVM.B == spinVM.Luck || spinVM.C == spinVM.Luck);

            //TODO : Add LuckySpin Game Logic (review flow chart for details)


            //Prepare the ViewBag
            if (spinVM.IsWinning)
            {
                ViewBag.Display = "block";
            }
            else
            {
                ViewBag.Display = "none";
            }
            //Use current player id for the link to LinkList
            //   (see the <a href> for "Current Balance" in the SpinIt.cshtml file)
            ViewBag.PlayerId = id;

            //Add the new Spin to the __current player's__ Spins collection
            var spin = new Spin {
                IsWinning = spinVM.IsWinning
            };

            currentPlayer.Spins.Add(spin);

            //Update the database - only done once after all changes stored in Entities
            _dbc.SaveChanges();

            return(View("SpinIt", spinVM));
        }
Exemplo n.º 10
0
        public ResultDto StartGuest(SpinViewModel model)
        {
            var result = Spin();
            var win    = ToWin(result, model);

            if (win <= 0)
            {
                return(new ResultDto(result, win, model));
            }
            if (win > model.BestScore)
            {
                model.BestScore = win;
            }

            return(new ResultDto(result, win, model));
        }
Exemplo n.º 11
0
        public ActionResult Spin()
        {
            //Get the current player from the Database
            int    id            = Convert.ToInt32(Session["PlayerId"]);
            Player currentPlayer = dbc.Players.Single(p => p.PlayerID == id);

            //TODO: Create a new Spin ViewModel instance to send to the View
            // (Fill in its data with info from the Player)

            SpinViewModel spinvm = new SpinViewModel()
            {
                Number  = currentPlayer.Number,
                Balance = currentPlayer.Balance
            };

            return(View(spinvm));
        }
        public IActionResult Index(Player player)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            // TODO: Add the Player to the Repository
            _repository.currentPlayer = player;

            // TODO: Build a new SpinItViewModel object with data from the Player and pass it to the View
            SpinViewModel spinvm = new SpinViewModel()
            {
                FirstName = player.FirstName,
                Balance   = player.Balance
            };

            return(RedirectToAction("SpinIt", player)); //player
        }
        /***
         * SpinIt Action
         **/

        public IActionResult SpinIt()  //TODO: add an int parameter to receive the id
        {
            //TODO: Use the _dbc and the given id to get the current player object
            //       from Players, and Include her Spins (use Lamda expressions)
            var currentPlayer = _dbc.Players
            ;                   //The above is incomplete

            //TODO: Add the properties to this SpinItViewModel object with data from the currentPlayer
            SpinViewModel spinVM = new SpinViewModel()
            {
                A = random.Next(1, 10),
                B = random.Next(1, 10),
                C = random.Next(1, 10),
                //Luck = currentPlayer.Luck,
                //Balance = currentPlayer.Balance,
                //FirstName = currentPlayer.FirstName,
            };

            spinVM.IsWinning = (spinVM.A == spinVM.Luck || spinVM.B == spinVM.Luck || spinVM.C == spinVM.Luck);

            //Use the ViewBag to handle items just needed for display
            if (spinVM.IsWinning)
            {
                ViewBag.Display = "block";
            }
            else
            {
                ViewBag.Display = "none";
            }
            //TODO Assign a ViewBag.PlayerId item used to assigns a link its route_id in SpinIt View
            //      (see the <a href> for "Current Balance" in the SpinIt.cshtml file)


            //TODO Compare DB records when adding a generic Spin, as shown below,
            //     with adding a new Spin to the current player's Spins list
            _dbc.Spins.Add(new Spin {
                IsWinning = spinVM.IsWinning
            });
            _dbc.SaveChanges();

            return(View("SpinIt", spinVM));
        }
        public IActionResult Index(Player player)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            //Repository repository = new Repository();
            // TODO: Add the Player to the Repository - CHECK
            repository.player = player; // pulls from the parameter

            // TODO: Build a new SpinItViewModel object with data from the Player and pass it to the View - CHECK
            SpinViewModel spinViewModel = new SpinViewModel();

            spinViewModel.FirstName = player.FirstName;
            spinViewModel.Balance   = player.Balance;
            spinViewModel.Luck      = player.Luck;

            return(RedirectToAction("SpinIt", spinViewModel));
        }
Exemplo n.º 15
0
        public IActionResult Index(Player player)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            // TODO: Add the Player to the Repository
            _repository._player = player;

            // TODO: Build a new SpinItViewModel object with data from the Player and pass it to the View
            SpinViewModel spinVM = new SpinViewModel();

            spinVM.FirstName            = _repository._player.FirstName;
            spinVM.CurrentBalance       = _repository._player.StartingBalance;
            spinVM.Luck                 = _repository._player.Luck;
            _repository._player.Balance = spinVM.CurrentBalance;
            _repository.ResetSpin();

            return(RedirectToAction("SpinIt", spinVM));
        }
        /***
         * Spin Action - Game Play
         **/
        public IActionResult SpinIt(SpinViewModel spinViewModel)  //TODO: replace the parameter with a ViewModel - CHECK
        {
            Spin spin = new Spin
            {
                Luck = spinViewModel.Luck,
                A    = random.Next(1, 10),
                B    = random.Next(1, 10),
                C    = random.Next(1, 10)
            };

            spin.IsWinning = (spin.A == spin.Luck || spin.B == spin.Luck || spin.C == spin.Luck);

            //Add to Spin Repository
            repository.AddSpin(spin);

            //TODO: Clean up ViewBag using a SpinIt ViewModel instead
            ViewBag.ImgDisplay = (spin.IsWinning) ? "block" : "none";
            ViewBag.FirstName  = spinViewModel.FirstName;
            ViewBag.Balance    = spinViewModel.Balance;

            return(View("SpinIt", spinViewModel));
        }
        /***
         * SpinIt Action
         **/
        public IActionResult SpinIt(int idNum)
        {
            var currentPlayer = _dbc.Players.Include(x => x.Spins)
                                .Single(x => x.Id == idNum);

            SpinViewModel spinVM = new SpinViewModel()
            {
                A         = random.Next(1, 10),
                B         = random.Next(1, 10),
                C         = random.Next(1, 10),
                Luck      = currentPlayer.Luck,
                Balance   = currentPlayer.Balance,
                FirstName = currentPlayer.FirstName,
            };

            spinVM.IsWinning = (spinVM.A == spinVM.Luck || spinVM.B == spinVM.Luck || spinVM.C == spinVM.Luck);

            //Use the ViewBag to handle items just needed for display
            if (spinVM.IsWinning)
            {
                ViewBag.Display = "block";
            }
            else
            {
                ViewBag.Display = "none";
            }
            //TODO Assign a ViewBag.PlayerId item used to assigns a link its route_id in SpinIt View
            //      (see the <a href> for "Current Balance" in the SpinIt.cshtml file)


            _dbc.Spins.Add(new Spin {
                IsWinning = spinVM.IsWinning
            });
            _dbc.SaveChanges();

            return(View("SpinIt", spinVM));
        }
Exemplo n.º 18
0
 //Access method
 public void AddSpin(SpinViewModel s)
 {
     spins.Add(s);
 }
Exemplo n.º 19
0
        public IActionResult Spin(int creditAmount)
        {
            var spinResult = _spinningService.Spin(creditAmount);

            return(Ok(SpinViewModel.Create(spinResult)));
        }