当前位置: 首页>>代码示例>>C#>>正文


C# IDatabase.GetGameByKey方法代码示例

本文整理汇总了C#中IDatabase.GetGameByKey方法的典型用法代码示例。如果您正苦于以下问题:C# IDatabase.GetGameByKey方法的具体用法?C# IDatabase.GetGameByKey怎么用?C# IDatabase.GetGameByKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDatabase的用法示例。


在下文中一共展示了IDatabase.GetGameByKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GameModule

        protected GameModule( IDatabase database )
            : base("{gameKey}/")
        {
            Before.AddItemToStartOfPipeline( context =>
            {
                var gameKey = (string)context.Parameters.gameKey;

                game = database.GetGameByKey( gameKey );

                context.ViewBag[ViewBagKeys.CurrentGame] = game;

                return null;
            } );
        }
开发者ID:Breeto,项目名称:MatchMaker,代码行数:14,代码来源:GameModule.cs

示例2: MatchupModule

        public MatchupModule( IDatabase database, Settings settings, IEnumerable<IMatchupProposer> proposers )
            : base(database)
        {
            this.proposers = proposers.ToArray();

            Get[Route.FindTeams] = o =>
            {
                var model = new FindTeamsModel()
                {
                    Game = game,
                    AvailablePlayers = database.GetPlayersForGame( game.Id ).OrderBy( player => player.Name ).ToArray(),
                    AlgorithmName = App.MatchupProposer.GetType().Name,
                };

                return View[Route.FindTeams, model];
            };

            Get[Route.SetMatchupProposer] = o =>
            {
                var model = new SetMatchupProposerViewModel( proposers, App.MatchupProposer );

                return View[Route.SetMatchupProposer, model];
            };

            Post[Route.SetMatchupProposer] = o =>
            {
                var request = this.Bind<SetMatchupProposerRequest>();

                var matchupProposer = GetAlgorithm( request.SelectedAlgorithmTypeName );

                App.MatchupProposer = matchupProposer;

                return Response.AsRedirect( Route.FindTeams );
            };

            Get[Route.GetProposedMatchups] = o =>
            {
                var request = this.Bind<GetProposedMatchupsRequest>();

                var proposer = App.MatchupProposer;

                var response = new GetProposedMatchupsResponse();

                try
                {
                    var gameKey = (string)o.gameKey;
                    var game = database.GetGameByKey( gameKey );

                    if ( null == request.PlayerIds || request.PlayerIds.Count < 2 )
                    {
                        throw new Exception( "Two or more players must be selected" );
                    }
                    var players = request.PlayerIds.Select( database.GetUserById ).ToArray();

                    var proposedMatchups = proposer.GetMatchups( game, players ).OrderBy( matchup => matchup.Imbalance ).ToArray();
                    proposedMatchups = CleanUp( proposedMatchups );

                    response.ProposedMatchups = proposedMatchups;
                }
                catch ( Exception e )
                {
                    response.ErrorMessage = e.Message;
                }

                return View[Route.GetProposedMatchups, response];
            };

            Post[Route.PresentMatchupForSaving] = o =>
            {
                var json = (string)Request.Form.matchup;
                var matchup = json.FromJson<ProposedMatchup>();

                return View[Route.SaveMatchupResult, new SaveMatchupResultViewModel(matchup, database.GetMaps(matchup.Game.Id))];
            };

            Post[Route.SaveMatchupResult] = o =>
            {
                var result = this.Bind<MatchupResult>();
                database.SaveMatchupResult( result );

                return Response.AsRedirect( Route.ViewResults );
            };

            Get[Route.ViewResults] = o =>
            {
                var game = database.GetGameByKey( o.gameKey );
                var matchupResults = database.GetMatchupResultsByGame( game.Id );
                var userMap = new IdentityMap<User>( database.GetUserById );

                var model = new List<MatchupResultViewModel>();
                foreach ( var matchupResult in matchupResults )
                {
                    var map = database.GetMapById(matchupResult.MapId);
                    model.Add(new MatchupResultViewModel(matchupResult, userMap, map));
                }

                return View[Route.ViewResults, model];
            };

            Get[Route.SelectPlayers] = o =>
//.........这里部分代码省略.........
开发者ID:Breeto,项目名称:MatchMaker,代码行数:101,代码来源:MatchupModule.cs


注:本文中的IDatabase.GetGameByKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。