예제 #1
0
        private void PlayHigher(PlayData playData, ResultData resultData)
        {
            byte[] shuffledCards = ShuffleCardPile();
            int    openedCard    = Convert.ToInt32(playData.Deck);
            int    bet           = playData.BetAmount;

            // Pick the first 4 cards from the shuffled cards
            // If one of the picked cards is equal to the opened card, swap it with the 5th card from the deck
            int card1 = SwapCard(openedCard, shuffledCards[0], shuffledCards[4]);
            int card2 = SwapCard(openedCard, shuffledCards[1], shuffledCards[4]);
            int card3 = SwapCard(openedCard, shuffledCards[2], shuffledCards[4]);
            int card4 = SwapCard(openedCard, shuffledCards[3], shuffledCards[4]);

            switch (playData.Action)
            {
            case "1": resultData.WinState = GetHigherResult(openedCard, card1); break;

            case "2": resultData.WinState = GetHigherResult(openedCard, card2); break;

            case "3": resultData.WinState = GetHigherResult(openedCard, card3); break;

            case "4": resultData.WinState = GetHigherResult(openedCard, card4); break;
            }

            resultData.Result   = card1.ToString() + "-" + card2.ToString() + "-" + card3.ToString() + "-" + card4.ToString();
            resultData.Winnings = (resultData.WinState == "WIN") ? bet : (resultData.WinState == "LOSE") ? -bet : 0;
        }
예제 #2
0
        private void PlayHighLow(PlayData playData, ResultData resultData)
        {
            Random rnd  = new Random();
            int    card = rnd.Next(1, 53); // Generate a ramdom number between 1 and 52
            int    rank = GetRankFromValue(card);
            int    bet  = playData.BetAmount;

            if (rank == 7)
            {
                resultData.WinState = "DRAW";
            }
            else
            {
                if (playData.Action == "HIGH")
                {
                    resultData.WinState = (rank > 7) ? "WIN" : "LOSE";
                }
                else
                {
                    resultData.WinState = (rank < 7) ? "WIN" : "LOSE";
                }
            }

            resultData.Result   = "C" + card.ToString();
            resultData.Winnings = (resultData.WinState == "WIN") ? bet : (resultData.WinState == "LOSE") ? -bet : 0;
        }
예제 #3
0
        public async Task <IActionResult> Play([FromBody] PlayData playData)
        {
            User user = await this._userDataProvider.GetUser(Convert.ToInt32(playData.AcctId));

            ResultData resultData = new ResultData();

            if (user != null)
            {
                if (user.GameCredits >= playData.BetAmount)
                {
                    switch (playData.AppId)
                    {
                    case "2": PlayHigher(playData, resultData); break;

                    default: PlayHighLow(playData, resultData); break;
                    }
                }
                else
                {
                    return(BadRequest());
                }
            }
            else
            {
                return(NotFound());
            }

            if (resultData.WinState != "DRAW")
            {
                await this._userDataProvider.UpdateUserCredits(user.AcctId, resultData.Winnings, 0);
            }

            resultData.AcctId       = playData.AcctId;
            resultData.AppId        = playData.AppId;
            resultData.GameCredits  = user.GameCredits;
            resultData.GameCurrency = user.GameCurrency;

            return(Ok(resultData));
        }