本文整理汇总了C#中IDatabase.GetPlayersForGame方法的典型用法代码示例。如果您正苦于以下问题:C# IDatabase.GetPlayersForGame方法的具体用法?C# IDatabase.GetPlayersForGame怎么用?C# IDatabase.GetPlayersForGame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDatabase
的用法示例。
在下文中一共展示了IDatabase.GetPlayersForGame方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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 =>
//.........这里部分代码省略.........
示例2: PlayerRatingsModule
public PlayerRatingsModule( IDatabase database )
: base(database)
{
this.database = database;
ratingsHelper = new RatingsHelper(database, App.Settings);
Get[Route.RatePlayers] = o =>
{
this.RequiresAuthentication();
// TODO: If player doesn't currently play this game, set them as actively playing this game?
var model = new RatePlayersViewModel
{
GameId = game.Id,
UserId = ( (UserIdentity)Context.CurrentUser ).UserId
};
var players = database.GetPlayersForGame( game.Id ).OrderBy(user => user.Name);
foreach ( var player in players )
{
var rating = database.GetMostRecentPlayerRating( game.Id, player.Id, model.UserId );
model.Players.Add(new RatePlayerViewModel()
{
CurrentRating = null != rating && rating.Rating.HasValue ? rating.Rating.Value : 0,
LastUpdate = null != rating ? rating.Timestamp : (DateTime?)null,
PlayerId = player.Id,
PlayerName = player.Name,
});
}
return View[Route.RatePlayers, model];
};
Get[Route.AddPlayerRating] = o =>
{
this.RequiresAuthentication();
try
{
var playerRating = this.Bind<PlayerRating>();
playerRating.GameId = game.Id;
playerRating.Rating = playerRating.Rating == 0 ? null : playerRating.Rating;
database.AddPlayerRating( playerRating );
return HttpStatusCode.OK;
}
catch ( Exception exception )
{
var response = new StringResponse(exception.Message);
response.StatusCode = HttpStatusCode.InternalServerError;
return response;
}
};
Get[Route.ViewPlayerRatings] = o =>
{
var model = new ViewPlayerRatingsViewModel();
var gameId = game.Id;
var players = database.GetPlayersForGame( gameId );
foreach ( var player in players )
{
var ratings = database.GetPlayerRatings( gameId, player.Id );
var average = ratingsHelper.CalculateAverageRating( ratings, DateTime.Now );
var winLossRecord = GetWinLossRecord( player.Id );
model.PlayerAverageRatings.Add( new PlayerAverageRating()
{
PlayerName = player.Name,
AverageRating = average,
RatingHistory = GetRatingHistory(gameId, player.Id),
WinLossRecord = winLossRecord,
});
}
var linkProposer = new LinkMatchupProposer(database);
model.LinkedPlayers = linkProposer.GetAllLinks(gameId);
return View[Route.ViewPlayerRatings, model];
};
Get["getlinkedplayers"] = o =>
{
var linkProposer = new LinkMatchupProposer(database);
var stream = new MemoryStream();
var serializer = new DataContractJsonSerializer(typeof (List<LinkedPlayer>));
serializer.WriteObject(stream, linkProposer.GetAllLinks(game.Id));
stream.Position = 0;
var reader = new StreamReader(stream);
var json = reader.ReadToEnd();
//.........这里部分代码省略.........