public void ShowEndGameView()
        {
            EndGameView endView = new EndGameView(Game);

            endView.Render();
            Console.ReadLine();
        }
Exemplo n.º 2
0
 public ViewInitializer(BonusView bonusView, ButtonView buttonView, HealthView healthView, KeyView keyView,
                        EndGameView endGameView)
 {
     _bonusView   = bonusView;
     _buttonView  = buttonView;
     _healthView  = healthView;
     _keyView     = keyView;
     _endGameView = endGameView;
 }
Exemplo n.º 3
0
        public void CreateNewView(IGameField gamefield, string message = null)
        {
            EndGameView view = new EndGameView()
            {
                DataContext = new EndGameViewModel(gamefield, message)
            };

            view.Show();
        }
 public EndPlayGameState( GameStateMachine stateMachine )
     : base(stateMachine)
 {
     foreach( UIView v in UIManager.Instance.Views )
     {
         if( v is EndGameView )
         {
             view = v as EndGameView;
         }
     }
 }
Exemplo n.º 5
0
        public async Task <EndGameView> End(string userId)
        {
            var activeGameOfUser = await _playerInGameRepository.GetActiveByUserId(userId);

            if (activeGameOfUser == null)
            {
                throw new CustomServiceException("Active game is doesn`t exist");
            }
            var activeGame          = activeGameOfUser.Game;
            var gameId              = activeGame.Id;
            var playerInGameExisted = await _playerInGameRepository.GetByGameId(gameId);

            if (playerInGameExisted.Count == 0)
            {
                throw new CustomServiceException("Player in game doesn`t exist!");
            }
            var deck = await _cardRepository.GetByGameId(gameId);

            if (deck.Count == 0)
            {
                throw new CustomServiceException("Deck doesn`t exist!");
            }
            var playerStepExisted = await _playerStepRepository.GetByGameId(gameId);

            if (playerStepExisted.Count == 0)
            {
                throw new CustomServiceException("Player and steps doesn`t exist!");
            }
            var botStepExisted = await _botStepRepository.GetByGameId(gameId);

            if (botStepExisted.Count == 0)
            {
                throw new CustomServiceException("Bot and steps doesn`t exist!");
            }
            var botInGameExisted = await _botInGameRepository.GetByGameId(gameId);

            if (botInGameExisted.Count == 0)
            {
                throw new CustomServiceException("Bot in game doesn`t exist!");
            }

            var status      = StatusType.End;
            var winner      = activeGame.Winner;
            var player      = playerInGameExisted.Select(x => x.Player).FirstOrDefault();
            var playerScore = playerInGameExisted
                              .Select(x => x.Score)
                              .Sum();
            var botList = botStepExisted
                          .GroupBy(x => x.BotId)
                          .Select(x => x.First().Bot)
                          .ToList();
            var botInGame = new List <BotInGame>();
            var scoredBotExistedPoints = GetCalculatedBotExistingPoint(botInGame, botInGameExisted, gameId);
            var botsScore   = GetCalculatedScoreBotPoints(scoredBotExistedPoints, gameId);
            var maxBotScore = botsScore.Max(x => x.Score);

            if (maxBotScore < 16)
            {
                var botsCards = GetCardsOfBots(botList, deck);
                var botsSteps = GetBotSteps(botList, botsCards, gameId);
                botInGame = botsSteps
                            .Select(x => new BotInGame()
                {
                    GameId = gameId,
                    BotId  = x.BotId,
                    Score  = GetCardValue(x.Rank)
                })
                            .ToList();
                var clearCards = await _cardRepository.GetByGameId(gameId);

                if (clearCards.Count == 0)
                {
                    throw new CustomServiceException("Cards doesn`t exist!");
                }
                await _cardRepository.RemoveRange(clearCards);

                var cardsOfGame = deck
                                  .Select(x => new Card()
                {
                    GameId = gameId,
                    Rank   = x.Rank,
                    Suit   = x.Suit
                })
                                  .ToList();
                scoredBotExistedPoints.AddRange(botInGame);
                botsScore = GetCalculatedScoreBotPoints(scoredBotExistedPoints, gameId);
                botStepExisted.AddRange(botsSteps);
                await _botStepRepository.CreateRange(botsSteps);

                await _cardRepository.CreateRange(cardsOfGame);

                await _botInGameRepository.CreateRange(botInGame);
            }
            activeGame = GetWinner(botsScore, botList, status, winner, playerScore, player, activeGame, gameId);
            var groupedBotSteps = botStepExisted.GroupBy(x => x.BotId);
            var response        = new EndGameView()
            {
                Status = activeGame.Status,
                Winner = activeGame.Winner,
                Player = new PlayerEndGameView()
                {
                    Name  = player.Name,
                    Cards = playerStepExisted
                            .Select(cardEndGameViewItem => new CardEndGameViewItem()
                    {
                        Rank = cardEndGameViewItem.Rank,
                        Suit = cardEndGameViewItem.Suit
                    })
                            .ToList()
                },
                Bots = groupedBotSteps
                       .Select(botEndGameViewItem => new BotEndGameViewItem
                {
                    Name  = botList.FirstOrDefault(bot => bot.Id == botEndGameViewItem.Key).Name,
                    Cards = botEndGameViewItem
                            .Select(cardEndGameViewItem => new CardEndGameViewItem()
                    {
                        Rank = cardEndGameViewItem.Rank,
                        Suit = cardEndGameViewItem.Suit
                    })
                            .ToList()
                })
                       .ToList()
            };
            await _gameRepository.Update(activeGame);

            return(response);
        }