public GamePlayerViewModel ContinueOrDeny(GamePlayer player, PlayingCard card)
        {
            GamePlayerViewModel playerModel = new GamePlayerViewModel();

            if (player.Name == "You" && player.Score < 21 && player.Status != "Stop")
            {
                Console.WriteLine("Take or no? y/n");
                string yesOrNo = Console.ReadLine();
                if (yesOrNo == "y")
                {
                    playerModel = TakeCard(player, card);
                }
                if (yesOrNo == "n")
                {
                    player.Status = "Stop";
                    _repository.GamePlayerRepository.Update(player);
                }
            }
            if (player.Name == "You" && player.Score >= 21)
            {
                player.Status = "Stop";
                _repository.GamePlayerRepository.Update(player);
            }
            if (player.Name != "You" && player.Score < 17)
            {
                playerModel = TakeCard(player, card);
                _repository.GamePlayerRepository.Update(player);
            }
            if (player.Name != "You" && player.Score >= 17)
            {
                player.Status = "Stop";
                _repository.GamePlayerRepository.Update(player);
            }
            return(playerModel);
        }
Exemple #2
0
 public GamePlayerView Load(GamePlayerViewModel vm)
 {
     Portrait.SetCurrentValue(Image.SourceProperty, vm.Portrait);
     Division.SetCurrentValue(Image.SourceProperty, vm.DivisionMedal);
     Name.Text = vm.Name;
     return(this);
 }
Exemple #3
0
        public async Task <List <GamePlayerViewModel> > PlayAgain(string yesOrNo)
        {
            List <GamePlayerViewModel> playerModelList = new List <GamePlayerViewModel>();

            if (yesOrNo == "n")
            {
                for (; ;)
                {
                    var playersList = (await _repository.genericGamePlayerRepository.Get() as List <GamePlayer>).ToList().Where(x => x.Status != "Stop").ToList();
                    if (playersList.Count <= 0)
                    {
                        break;
                    }
                    for (int j = 0; j < playersList.Count; j++)
                    {
                        PlayingCard         card        = _mapper.MappCardsViewModel(await DrawCard());
                        GamePlayerViewModel playerModel = await ContinueOrDeny((playersList)[j], card, yesOrNo);
                    }
                }
            }
            if (yesOrNo == "y")
            {
                var playersList = (await _repository.genericGamePlayerRepository.Get()).ToList().Where(x => x.Status != "Stop").ToList();
                for (int j = 0; j < playersList.Count; j++)
                {
                    PlayingCard         card        = _mapper.MappCardsViewModel(await DrawCard());
                    GamePlayerViewModel playerModel = await ContinueOrDeny((playersList)[j], card, yesOrNo);
                }
            }

            playerModelList = _mapper.MappPlayers((await _repository.genericGamePlayerRepository.Get() as List <GamePlayer>));

            return(playerModelList);
        }
Exemple #4
0
 public PlayerPage(string gameId, ObservableCollection <PlayerDto> players)
 {
     InitializeComponent();
     _vm            = App.IOC.GamePlayer;
     _vm.Players    = players;
     _vm.GameId     = gameId;
     BindingContext = _vm;
 }
Exemple #5
0
        public ActionResult Edit(GamePlayerViewModel gameView)

        {
            if (ModelState.IsValid)
            {
                gameView.game.GameName = Convert.ToString(TempData["currentGame"]);
                db.Entry(gameView.game.GameName).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index", "GamesController"));
            }
            return(RedirectToAction("Index", "Games"));
        }
Exemple #6
0
        public GamePlayerViewModel MappPlayers(GamePlayer gamePlayers)
        {
            var player = new GamePlayerViewModel();

            player.Name         = gamePlayers.Name;
            player.Score        = gamePlayers.Score;
            player.PlayingCards = gamePlayers.PlayerCards;
            //player.PlayingCards = gamePlayers.PlayingCards;
            player.Status      = gamePlayers.Status;
            player.WinsNumbers = gamePlayers.WinsNumbers;

            return(player);
        }
Exemple #7
0
        public async Task <GamePlayerViewModel> TakeCard(GamePlayer player, PlayingCard playingCard)
        {
            GamePlayer gamePlayer = await _repository.genericGamePlayerRepository.GetById(player.Id);

            gamePlayer.Score += playingCard.CardValue;

            gamePlayer.PlayerCards.Add(playingCard);

            GamePlayerViewModel playerModel = _mapper.MappPlayers(gamePlayer);
            await _repository.genericGamePlayerRepository.Save();

            return(playerModel);
        }
Exemple #8
0
        // GET: Games/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GamePlayerViewModel gameViewModel = new GamePlayerViewModel();
            var listPlayers = db.Players.Where(Player => Player.PlayerGameID == id);

            gameViewModel.game    = db.Games.Find(id);
            gameViewModel.players = listPlayers.ToList();
            if (gameViewModel == null)
            {
                return(HttpNotFound());
            }
            return(View(gameViewModel));
        }
Exemple #9
0
        public List <GamePlayerViewModel> MappPlayers(List <GamePlayer> gamePlayers)
        {
            var playersViewModelList = new List <GamePlayerViewModel>();

            for (int i = 0; i < gamePlayers.Count; i++)
            {
                var player = new GamePlayerViewModel();
                player.Id           = gamePlayers[i].Id;
                player.Name         = gamePlayers[i].Name;
                player.Score        = gamePlayers[i].Score;
                player.PlayingCards = gamePlayers[i].PlayerCards;
                //player.PlayingCards = gamePlayers[i].PlayingCards;
                player.Status      = gamePlayers[i].Status;
                player.WinsNumbers = gamePlayers[i].WinsNumbers;
                playersViewModelList.Add(player);
            }

            return(playersViewModelList);
        }
        public List <GamePlayerViewModel> HandOverCards()
        {
            List <GamePlayerViewModel> playerModelList = null;
            int handOutCardsFirstTime = 2;

            for (int i = 0; i < handOutCardsFirstTime; i++)
            {
                GamePlayerViewModel playerModel = null;
                playerModelList = new List <GamePlayerViewModel>();
                foreach (var item in _repository.GamePlayerRepository.GetGamePlayer())
                {
                    if (item.Score < 17)
                    {
                        PlayingCard card = _mapper.MappCardsViewModel(DrawCard());
                        playerModel = TakeCard(item, card);
                        playerModelList.Add(playerModel);
                        Thread.Sleep(200);
                    }
                }
            }
            return(playerModelList);
        }
Exemple #11
0
        public async Task <GamePlayerViewModel> ContinueOrDeny(GamePlayer player, PlayingCard card, string yesNo)
        {
            GamePlayerViewModel playerModel = new GamePlayerViewModel();

            if (player.Name == "You" && player.Score < 21 && player.Status != "Stop")
            {
                string yesOrNo = yesNo;
                if (yesOrNo == "y")
                {
                    playerModel = await TakeCard(player, card);
                }
                if (yesOrNo == "n")
                {
                    player.Status = "Stop";
                    await _repository.genericGamePlayerRepository.Update(player);
                }
            }
            if (player.Name == "You" && player.Score >= 21)
            {
                var playerTmp = await _repository.genericGamePlayerRepository.GetById(player.Id);

                playerTmp.Status = "Stop";
                await _repository.genericGamePlayerRepository.Save();
            }
            if (player.Name != "You" && player.Score < 17)
            {
                playerModel = await TakeCard(player, card);
            }
            if (player.Name != "You" && player.Score >= 17)
            {
                var playerTmp = await _repository.genericGamePlayerRepository.GetById(player.Id);

                playerTmp.Status = "Stop";

                await _repository.genericGamePlayerRepository.Save();
            }

            return(playerModel);
        }
Exemple #12
0
        public ActionResult GetGameParticipants(int id, bool ed = true)
        {
            // ed - Editable
            ViewBag.Editable = ed;
            var game      = DataContext.Games.Single(x => x.Id == id);
            var partic    = DataContext.GameParticipants.Where(x => x.GameId == id).ToList();
            var particips = partic.Select(x => x.ParticipantId);

            if (game.Sport.IsTeamSport)
            {
                var teams = DataContext.Teams.Where(x => particips.Contains(x.Id)).ToList();
                var res   = GameTeamViewModel.GetModels(partic, teams, DataContext);
                return(PartialView("_GameTeams", res));
            }
            else
            {
                var players = DataContext.Players.Where(x => particips.Contains(x.Id)).ToList();
                var res     = GamePlayerViewModel.GetModels(partic, players);
                ViewBag.IsDeleteEnabled = true; // можно удалять только если не командный вид спорта
                return(PartialView("_GamePlayers", res));
            }
        }