本文整理汇总了C#中IPlayer.TakeTurn方法的典型用法代码示例。如果您正苦于以下问题:C# IPlayer.TakeTurn方法的具体用法?C# IPlayer.TakeTurn怎么用?C# IPlayer.TakeTurn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPlayer
的用法示例。
在下文中一共展示了IPlayer.TakeTurn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TakeTurn
public void TakeTurn(IPlayer player, int roll)
{
if (player.Cash > 0)
{
player.TakeTurn(roll);
EvaluateTurnOutcome(player);
PrintTurnSummary(player);
}
}
示例2: InvokePlayer
/// <summary>
/// Invokes the specified player.
/// </summary>
/// <param name="player">The player.</param>
private void InvokePlayer(IPlayer player)
{
#region Implementation
PlayerProgress progress = GetPlayerProgress(player);
//increment the index every time a player is invoked
_currentPlayerIndex++;
//only invoke the player if they still have remaining attempts
if (progress.IsInPlay)
{
//call the player to have another crack
string guess = player.TakeTurn(progress.CurrentPhrase);
if (!string.IsNullOrWhiteSpace(guess))
{
bool isGoodGuess = false;
//if the player returns a single letter, then they're just eliminating that letter
//rather than guessing the entire word
if (guess.Length == 1)
{
Trace.WriteLine(string.Format("Player '{0}' has guessed the letter '{1}'", player.TeamName, guess));
if (CurrentPhrase.Contains(guess, StringComparison.OrdinalIgnoreCase))
{
//if the phrase contains the letter update the player's progress
progress.CurrentPhrase = UpdateWord(progress.CurrentPhrase, guess);
isGoodGuess = true;
Trace.WriteLine(string.Format("Player '{0}'s phrase has now been updated to '{1}'",
player.TeamName, progress.CurrentPhrase));
}
guess = progress.CurrentPhrase;
}
else
{
Trace.WriteLine(string.Format("Player '{0}' has guessed the phrase '{1}'", player.TeamName, guess));
}
//Has the player guessed the complete word
if (CurrentPhrase.Equals(guess, StringComparison.OrdinalIgnoreCase))
{
progress.HasCompletedChallenge = true;
Trace.WriteLine(string.Format("Player '{0}' has correctly guessed the phrase!", player.TeamName));
}
else
{
//if not increment the number of attempts if and
//disqualify them if they've exceeded the max chances
if (!isGoodGuess)
{
progress.Attempts++;
progress.IsInPlay = progress.Attempts < MaxNumberOfChances;
if (progress.IsInPlay)
{
Trace.WriteLine(string.Format("Player '{0}' now has {1} chance(s) remaining",
player.TeamName, (MaxNumberOfChances - progress.Attempts)));
}
else
{
Trace.WriteLine(string.Format("Player '{0}' has run out of chances - for you the war is over!", player.TeamName));
}
}
}
}
else
{
//a player that returns nothing is disqualified
progress.IsInPlay = false;
Trace.WriteLine(string.Format("Player '{0}' returned an invalid result and has been disqualified", player.TeamName));
}
Trace.WriteLine(Environment.NewLine);
}
#endregion
}