//GamePlay public double PlayGame(int id, double betAmt, bool highRoller, BetType bType = BetType.pass, string playerSelection = "0") { double amount = 0; var game = new GameService(_userId); string gameName = game.GetGameById(id).GameName; double payout = 0; //game bet limits var min = game.GetGameById(id).MinBet; var max = game.GetGameById(id).MaxBet; if (gameName.ToLower() == "russian roulette") { min = PlayerBalance(_userId); max = min; } if (betAmt < min || betAmt > max) { return(0); } else if (!highRoller == game.GetGameById(id).IsHighStakes) { return(0); } else if (playerSelection.Count(x => x == ',') > 10) { return(0); } else { switch (gameName.ToLower()) { case "baccarat": payout = game.Baccarat(); break; case "blackjack": payout = game.Blackjack(); break; case "craps": payout = game.Craps(bType); break; case "roulette": List <int> value = betValue(id, bType, playerSelection); payout = game.Roulette(bType, value); break; case "keno": //List<int> from "player selection" range = 1-80; up to 20 #'s selected - let's use 10 #'s List <int> playerNums = betValue(id, bType, playerSelection); payout = game.Keno(playerNums); break; case "russian roulette": double amt = PlayerBalance(_userId); payout = game.RussianRoulette(); //Get player bank balance break; default: //switch on gameType var type = GetGameById(id).TypeOfGame; switch (type.ToString().ToLower()) { case "dice": payout = game.baseDice(); break; case "wheel": payout = game.baseWheel(); break; case "random_num": int numPick = r.Next(1, 10); //player selects num payout = game.baseRandNum(numPick); break; default: payout = baseGame(); break; } payout = game.baseGame(); break; } if (payout > 0) { amount = payout * betAmt; } else if (payout < 0 && gameName.ToLower() == "russian roulette") { amount = 12345; } //accountDelete else if (payout == 0 && gameName.ToLower() == "russian roulette") { amount = 45678; } else { amount = -1 * betAmt; } return(amount); } }
public BetResult CreateBet(BetCreate model) { double payout; var hasAccess = CheckPlayerAccess(); // Brought _gameSim play game mechanics outside, and captured result as variable. // That result will be fed into added helper method (in gamesimulation.cs) to derive win/loss bool. // Now both PayoutAmount and PlayerWonGame derived // from _gameSim. if (model.GameId == 11) { _gameService = new GameService(_playerGuid); } if (!model.TypeOfBet.HasValue) { payout = _gameService.PlayGame(model.GameId, model.BetAmount, hasAccess, GameService.BetType.pass, model.ValueOfBet); } else { payout = _gameService.PlayGame(model.GameId, model.BetAmount, hasAccess, (GameService.BetType)model.TypeOfBet, model.ValueOfBet); } if (payout == 0) { return(null); //if playing keno or roulette postman needs a list of int. Keno up to 10 int(1-80). roulette } if (payout == 12345) { DeletePlayer(_playerGuid); return(new BetResult { TimeOfBet = DateTime.Now.ToString(), BetId = 000, GameId = 11, GameName = "Russian Roulette", BetAmount = model.BetAmount, PlayerWonGame = false, PayoutAmount = -model.BetAmount, PlayerBankBalance = 0, Message = "Sorry! Game Over! You lost at Russian Roulette!" }); } if (payout == 45678) { return(new BetResult { TimeOfBet = DateTime.Now.ToString(), BetId = 000, GameId = 11, GameName = "Russian Roulette", BetAmount = model.BetAmount, PlayerWonGame = true, PayoutAmount = 0, PlayerBankBalance = model.BetAmount, Message = "You survived. Do you wish to play again!" }); } var entity = new Bet() { PlayerId = _playerGuid, GameId = model.GameId, BetAmount = model.BetAmount, PayoutAmount = payout, PlayerWonGame = _gameSim.GameWinOutcome(payout), DateTimeOfBet = DateTimeOffset.Now, }; using (var ctx = new ApplicationDbContext()) { ctx.Bets.Add(entity); if (ctx.SaveChanges() != 0 && UpdatePlayerBankBalance(_playerGuid, entity.PayoutAmount) && UpdateHouseBankBalance(entity.PayoutAmount * (-1))) { return(GetBetResult(entity.BetId)); } return(null); } }