Exemplo n.º 1
0
        public async Task <IActionResult> Choose(string id, Player player)
        {
            var game    = GetGame(id);
            var choices = await _choiceProvider.GetAll();

            var playerId = game.GetPlayerId(player);

            var playerInstance = await _playerProvider.GetPlayer(playerId);

            var viewablePlayerInstace = playerInstance as IViewablePlayer;

            await viewablePlayerInstace.SetContext(HttpContext);

            if (!await viewablePlayerInstace.Validate(game.GameState, choices, player))
            {
                return(await viewablePlayerInstace.View(game.GameState, choices, PlayerHelper.CreateRedirectUrl(this.Url, game.GameState, player), player));
            }
            var choice = await playerInstance.GetChoice(player, game.GameState, choices);

            game.SetChoice(player, choice);
            _gameStateStorage.Save(game.GameState);

            return(new RedirectToActionResult("Round", null, new { id = game.GameState.Id }));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Round(string id)
        {
            var game    = GetGame(id);
            var choices = await _choiceProvider.GetAll();

            var player = game.GetUnchocenPlayer();

            while (player != Player.None)
            {
                var playerId       = game.GetPlayerId(player);
                var playerInstance = await _playerProvider.GetPlayer(playerId);

                var viewablePlayerInstance = playerInstance as IViewablePlayer;
                if (viewablePlayerInstance != null)
                {
                    var view = await viewablePlayerInstance.View(game.GameState, choices, PlayerHelper.CreateRedirectUrl(this.Url, game.GameState, player), player);

                    return(view);
                }
                var choice = await playerInstance.GetChoice(player, game.GameState, choices);

                game.SetChoice(player, choice);
                _gameStateStorage.Save(game.GameState);
                player = game.GetUnchocenPlayer();
            }

            var winner = game.CalculateRoundWinner(choices);

            _gameStateStorage.Save(game.GameState);

            var round = game.GetCurrentRound();
            var model = new RoundEndViewModel()
            {
                Choices   = choices,
                GameState = game.GameState,
                Round     = round,
                RoundNo   = game.GameState.Rounds.Count,
                Winner    = winner
            };

            return(View("RoundEnd", model));
        }