Пример #1
0
        //public async Task<MoreOrEnoughGameView> MoreOrEnough(bool takeCard = false)
        //{
        //    bool isGameEnded = await IsGameEnded(takeCard);


        //    for (; isGameEnded == false;)
        //    {
        //        var isUserBusted = await IsUserBusted();
        //        if (takeCard && !isUserBusted)
        //        {
        //            await TakeCardIfNotEnough(takeCard);
        //            isGameEnded = await IsGameEnded(takeCard);
        //            isUserBusted = await IsUserBusted();
        //            if (!isUserBusted)
        //            {
        //                break;
        //            }

        //            takeCard = false;
        //        }

        //        if (!takeCard)
        //        {
        //            await TakeCardIfNotEnough(takeCard);
        //            isGameEnded = await IsGameEnded(takeCard);
        //        }
        //    }

        //    Dictionary<Player, List<Card>> playerCardsLastGame = await DefinePlayersFromLastGame();

        //    List<PlayerGameViewItem> playerViewItemList = new List<PlayerGameViewItem>();

        //    foreach (var player in playerCardsLastGame)
        //    {
        //        PlayerGameViewItem playerViewItem = new PlayerGameViewItem();
        //        playerViewItem.Id = player.Key.Id;
        //        playerViewItem.Name = player.Key.Name;
        //        playerViewItem.GameNumber = player.Key.GameNumber;
        //        playerViewItem.PlayerType = player.Key.PlayerType;
        //        playerViewItem.Score = player.Value.Sum(c=>c.Value);
        //        foreach (var card in player.Value)
        //        {
        //            playerViewItem.Cards.Add(new CardViewItem { Id = card.Id, Value = card.Value });
        //        }

        //        playerViewItemList.Add(playerViewItem);
        //    }

        //    CountSum(ref playerViewItemList);

        //    MoreOrEnoughGameView moreOrEnoughViewModel = new MoreOrEnoughGameView();
        //    moreOrEnoughViewModel.Players = playerViewItemList;

        //    return moreOrEnoughViewModel;
        //}


        /////////////////////////////////////////////////////////
        ///

        public async Task <MoreOrEnoughGameView> More()
        {
            bool isGameEnded = await IsGameEnded(false);

            if (!isGameEnded)
            {
                await TakeCardIfNotEnough(true);
            }
            var isUserBusted = await IsUserBusted();

            if (isUserBusted)
            {
                await Enough();
            }

            Dictionary <Player, List <Card> > playerCardsLastGame = await DefinePlayersFromLastGame();

            List <PlayerGameViewItem> playerViewItemList = new List <PlayerGameViewItem>();

            foreach (var player in playerCardsLastGame)
            {
                PlayerGameViewItem playerViewItem = new PlayerGameViewItem();
                playerViewItem.Id         = player.Key.Id;
                playerViewItem.Name       = player.Key.Name;
                playerViewItem.GameNumber = player.Key.GameNumber;
                playerViewItem.PlayerType = player.Key.PlayerType;
                playerViewItem.Score      = player.Value.Sum(c => c.Value);
                foreach (var card in player.Value)
                {
                    playerViewItem.Cards.Add(new CardViewItem {
                        Id = card.Id, Value = card.Value
                    });
                }

                playerViewItemList.Add(playerViewItem);
            }

            CountSum(ref playerViewItemList);

            MoreOrEnoughGameView moreOrEnoughViewModel = new MoreOrEnoughGameView();

            moreOrEnoughViewModel.Players = playerViewItemList;

            return(moreOrEnoughViewModel);
        }
        public async Task <ActionResult> Enough()
        {
            MoreOrEnoughGameView model = await _gameService.Enough();

            return(PartialView("MoreOrEnough", model.Players));
        }
Пример #3
0
        public async Task <ActionResult> PlayAgain(bool takeCard)
        {
            MoreOrEnoughGameView model = await _gameLogicService.MoreOrEnough(takeCard);

            return(PartialView("PlayAgain", model.Players));
        }