Exemplo n.º 1
0
        public Game.Session JoinGameSession(Game.Player joiner, Game.Type gameType, int target)
        {
            var gamesOfType = m_matchingSessions.Where((gs) => { return(gs.m_gameType == gameType); });

            int bestTarget = int.MaxValue;

            Game.Session fallbackSession = null;

            var matched = gamesOfType.Where((gs) =>
            {
                int score = gs.MatchScore(joiner);
                if (score <= target)
                {
                    return(true);
                }
                else if (score < bestTarget)
                {
                    bestTarget      = score;
                    fallbackSession = gs;
                }
                return(false);
            });

            if (matched.Count() >= 0)
            {
                return(matched.ElementAt(0));
            }
            return(fallbackSession);
        }
Exemplo n.º 2
0
        public Game.Session HostGameSession(Game.Player host, Game.Type gameType, Func <Game.Session> gameSessionFactory)
        {
            // TODO: make sure host is not already in another game session
            var gs = gameSessionFactory();

            gs.m_gameType = gameType;
            gs.m_host     = host;
            gs.m_players.Add(host);

            m_matchingSessions.Add(gs);
            return(gs);
        }