private async Task <RoundGameView> MappingToViewModel(List <Round> rounds)
        {
            var result         = rounds.GroupBy(p => p.Player.Name);
            var roundViewModel = new RoundGameView();

            foreach (var round in result)
            {
                var userModel = new PlayerNextRoundViewItem();
                userModel.UserName = round.Key;

                foreach (var item in round)
                {
                    var         cardViewModel = new CardGameViewItem();
                    PlayerGames playerGames   = await GetPlayerStatus(item.PlayerId, item.GameId);

                    userModel.PlayerId     = item.PlayerId;
                    userModel.GameId       = item.GameId;
                    userModel.PlayerRole   = (PlayerRoleEnumView)item.Player.PlayerRole;
                    userModel.PlayerStatus = (PlayerStatusEnumView)playerGames.Status;

                    cardViewModel.Rank  = item.Card.Rank.ToString();
                    cardViewModel.Suit  = item.Card.Suit.ToString();
                    cardViewModel.Value = item.Card.Value;
                    userModel.CardSum  += item.Card.Value;

                    userModel.Cards.Add(cardViewModel);
                }
                roundViewModel.Users.Add(userModel);
            }
            roundViewModel.GameId = rounds[0].GameId;

            return(roundViewModel);
        }
        public async Task <List <DetailHistoryView> > Details(int gameId)
        {
            var rounds = await GetAllRoundsFromParticularGame(gameId);

            var result      = rounds.GroupBy(p => p.Player.Name);
            var playersGame = new PlayerGames();

            var userModelList = new List <DetailHistoryView>();

            foreach (var round in result)
            {
                var userModel = new DetailHistoryView();
                userModel.UserName = round.Key;

                foreach (var item in round)
                {
                    var cardViewModel = new CardHistoryViewItem();

                    cardViewModel.Rank = item.Card.Rank.ToString();
                    cardViewModel.Suit = item.Card.Suit.ToString();
                    userModel.CardSum += item.Card.Value;
                    playersGame        = await GetStatusInParticularGame(item.PlayerId, item.GameId);

                    userModel.Cards.Add(cardViewModel);
                }
                userModel.Status = playersGame.Status.ToString();
                userModelList.Add(userModel);
            }
            return(userModelList);
        }
Exemple #3
0
 public BoxScore()
 {
     Game        = new Game();
     Innings     = new Innings();
     PlayerGames = new PlayerGames();
     TeamGames   = new TeamGames();
 }
Exemple #4
0
    /* request the number of games for each player in database for a client query */
    public void getPlayersGamesNum(bool delay)
    {
        ICallBack channel = OperationContext.Current.GetCallbackChannel <ICallBack>();

        if (delay)
        {
            ManualResetEvent delayEvent = new ManualResetEvent(false);
            ThreadPool.QueueUserWorkItem(new WaitCallback((_) =>
            {
                sleep();
                delayEvent.Set();
            }));
            delayEvent.WaitOne();
        }

        using (var db = new TTTDataClassesDataContext())
        {
            PlayerGames[] playersGames = new PlayerGames[db.Players.Count() - 1];
            int           i            = 0;
            foreach (var p in db.Players)
            {
                if (p.Id != SERVER)
                {
                    playersGames[i]      = new PlayerGames();
                    playersGames[i].Name = p.Id + " : " + p.FirstName;
                    var x = db.Games.Where(g => g.Player1 == p.Id || g.Player2 == p.Id);
                    playersGames[i++].NumberOfGames = x.Count();
                }
            }
            channel.sendPlayersGamesNum(playersGames);
        }
    }
Exemple #5
0
        public ActionResult PlayGames(string id)
        {
            var playerService  = new PlayerService();
            var gameService    = new GameService();
            var player1        = playerService.GetById(id);
            var availableGames = gameService.List(100, 0).ToList();
            var playergames    = new PlayerGames()
            {
                Player         = player1,
                AvailableGames = availableGames
            };

            return(View(playergames));
        }
Exemple #6
0
        //
        // GET: /Player/PlayGames/514b46581cbfe31ad86ec630

        public ActionResult PlayGames(string id)
        {
            var playerService  = new PlayerService();
            var player         = playerService.GetById(id);
            var gameService    = new GameService();
            var availableGames = gameService.GetGamesDetails(100, 0);

            var playerGames = new PlayerGames()
            {
                Player         = player,
                AvailableGames = new List <Game>(availableGames)
            };

            return(View(playerGames));
        }
        private async Task <IEnumerable <ShowGamesHistoryView> > CreateGameHistoryViewModel(IEnumerable <Game> games)
        {
            var listOfViewModel = new List <ShowGamesHistoryView>();

            foreach (var game in games)
            {
                PlayerGames playerGames = await GetDetailsFromGame(game.Id);

                var gameViewModel = new ShowGamesHistoryView();
                gameViewModel.HumanName    = playerGames.Player.Name;
                gameViewModel.GameCreation = playerGames.Game.Date;
                gameViewModel.GameId       = game.Id;
                listOfViewModel.Add(gameViewModel);
            }

            return(listOfViewModel);
        }
 public bool IsConfirmed()
 {
     return(PlayerGames.All(x => x.IsConfirmed));
 }
Exemple #9
0
    /* request the number of games for each player in database for a client query */
    public void getPlayersGamesNum(bool delay)
    {
        ICallBack channel = OperationContext.Current.GetCallbackChannel<ICallBack>();

        if (delay)
        {
            ManualResetEvent delayEvent = new ManualResetEvent(false);
            ThreadPool.QueueUserWorkItem(new WaitCallback((_) =>
            {
                sleep();
                delayEvent.Set();
            }));
            delayEvent.WaitOne();
        }

        using (var db = new TTTDataClassesDataContext())
        {
            PlayerGames[] playersGames = new PlayerGames[db.Players.Count()-1];
            int i = 0;
            foreach (var p in db.Players)
            {
                if (p.Id != SERVER)
                {
                    playersGames[i] = new PlayerGames();
                    playersGames[i].Name = p.Id + " : " + p.FirstName;
                    var x = db.Games.Where(g => g.Player1 == p.Id || g.Player2 == p.Id);
                    playersGames[i++].NumberOfGames = x.Count();
                }
            }
            channel.sendPlayersGamesNum(playersGames);
        }
    }
Exemple #10
0
 public void AddPlayerGame(PlayerGame playerGame)
 {
     PlayerGames.Add(playerGame);
 }
        //
        // GET: /Player/PlayGames/514b46581cbfe31ad86ec630
        public ActionResult PlayGames(string id)
        {
            var playerService = new PlayerService();
            var player = playerService.GetById(id);
            var gameService = new GameService();
            var availableGames = gameService.GetGamesDetails(100, 0);

            var playerGames = new PlayerGames()
            {
                Player = player,
                AvailableGames = new List<Game>(availableGames)
            };

            return View(playerGames);
        }
 public void setPlayersGamesNum(PlayerGames[] playersGames)
 {
     this.queryObjects = playersGames;
     string[] titles = { "Name", "NumberOfGames" };
     string[] types = { "char", "int" };
     bool[] readOnly = { true, true };
     bool[] nullable = { false, false };
     ctrl = new QueryControl(queryObjects, titles, types, readOnly, nullable);
     tableElementHost.Child = ctrl;
     ctrl.setSelectionType(cbDelType.SelectedIndex == 1);
 }
 public void sendPlayersGamesNum(PlayerGames[] playersGames)
 {
     if (mainForm.queriesForm != null)
         mainForm.queriesForm.setPlayersGamesNum(playersGames);
 }