示例#1
0
        private bool IsGameEligibleForLogging(DataAccess.Game game)
        {
            // Not logging single games.
            if (game.GameTeams.Count() < 2)
            {
                return(false);
            }

            // Games must have at least MinimumNumberOfPlayersPerTeam players on each side that have played for more than 5 minutes.
            bool hadEnoughEligiblePlayers = true;

            foreach (DataAccess.GameTeam team in game.GameTeams)
            {
                if (team.GameTeamMembers.Where(p => p.GameTeamMemberDuration / 60 >= 5).Count() < MinimumNumberOfPlayersPerTeam)
                {
                    hadEnoughEligiblePlayers = false;
                    break;
                }
            }

            if (hadEnoughEligiblePlayers == false)
            {
                return(false);
            }

            return(true);
        }
示例#2
0
 public static Library.Game Map(DataAccess.Game game) => new Library.Game
 {
     GameId      = game.GameId,
     Name        = game.Name,
     Price       = game.Price,
     Description = game.Description,
     DeveloperId = game.DeveloperId,
     Image       = game.Image,
     Trailer     = game.Trailer,
 };
示例#3
0
        private bool IsDrawGame(DataAccess.Game game)
        {
            bool isDrawGame = true;

            foreach (DataAccess.GameTeam team in game.GameTeams)
            {
                if (team.GameTeamWinner == true)
                {
                    isDrawGame = false;
                    break;
                }
            }

            return(isDrawGame);
        }
示例#4
0
        /// <summary>
        /// Ends the game in an ingame environment.
        /// </summary>
        /// <param name="guidGame">Game global unique identifier</param>
        public void EndGame(string guidGame)
        {
            if (!gamesClients.ContainsKey(guidGame))
            {
                return;
            }
            var game = GameService.ActiveGames.Find(activeGame => activeGame.ActiveGameGuid == guidGame);

            if (game == null)
            {
                return;
            }
            using (DostDatabase db = new DostDatabase()) {
                var newGame = new DataAccess.Game {
                    date  = game.Date,
                    round = game.Round
                };
                db.Game.Add(newGame);
                if (db.SaveChanges() == 0)
                {
                    return;
                }
                game.Players.ForEach(player => {
                    newGame.Player.Add(new DataAccess.Player {
                        idaccount = player.Account.Id,
                        idgame    = newGame.idgame,
                        isHost    = player.IsHost ? 1 : 0,
                        score     = player.Score
                    });
                });
                if (db.SaveChanges() == 0)
                {
                    return;
                }
                game.GameCategories.ForEach(category => {
                    var newCategory = new DataAccess.GameCategory {
                        idgame = newGame.idgame,
                        name   = category.Name
                    };
                    newGame.GameCategory.Add(newCategory);
                    newGame.Player.ToList().ForEach(player => {
                        var playerCategoryAnswers = category.CategoryPlayerAnswer.Where(categoryAnswer => categoryAnswer.Player.Account.Id == player.idaccount).ToList();
                        playerCategoryAnswers.ForEach(categoryAnswer => {
                            newCategory.CategoryPlayerAnswer.Add(new DataAccess.CategoryPlayerAnswer {
                                idcategory = newCategory.idcategory,
                                idplayer   = player.idplayer,
                                answer     = categoryAnswer.Answer,
                                round      = categoryAnswer.Round
                            });
                        });
                    });
                });
                var playerPlaces = game.Players.ToList();
                playerPlaces = playerPlaces.OrderBy(playerPlace => playerPlace.Score).ToList();
                for (int index = 0; index < playerPlaces.Count; index++)
                {
                    db.Account.Find(playerPlaces[index].Account.Id).coins += GameService.MAX_COINS_PER_GAME_WIN / (index + 1);
                }
                if (db.SaveChanges() == 0)
                {
                    return;
                }
            }
            foreach (var player in gamesClients[guidGame])
            {
                player.Value.EndGame(guidGame);
            }
            System.Threading.Thread.Sleep(2000);
            gamesClients.Remove(guidGame);
        }