コード例 #1
0
ファイル: Game.cs プロジェクト: jkissinger/GmailGameNarrator
 private bool ValidTeam(Team team, Role role, bool thisTeam)
 {
     //Whether or not any team is allowed
     bool anyTeam = team == null;
     bool teamIsValid = true;
     if (!anyTeam)
     {
         //Any team is not allowed; check that the team is valid
         teamIsValid = role.Team.Equals(team) && thisTeam || !role.Team.Equals(team) && !thisTeam;
     }
     return teamIsValid;
 }
コード例 #2
0
ファイル: Game.cs プロジェクト: jkissinger/GmailGameNarrator
 public int GetCountOfPlayersWithRole(Role role)
 {
     int count = 0;
     foreach (Player p in Players)
     {
         if (p.Role != null && p.Role.Equals(role)) count++;
     }
     return count;
 }
コード例 #3
0
ファイル: Game.cs プロジェクト: jkissinger/GmailGameNarrator
 /// <summary>
 /// Implements the properties <see cref="Role.MaxPercentage"/> and <see cref="Role.MaxPlayers"/>.
 /// </summary>
 /// <param name="role"></param>
 /// <returns>True if either property is exceeded, false otherwise.</returns>
 public bool MaxPlayersForRoleReached(Role role)
 {
     int playerCount = GetCountOfPlayersWithRole(role) + 1;
     int maxPercent = MathX.Percent(Players.Count, role.MaxPercentage);
     //1 player is okay for any role
     if (playerCount == 1) return false;
     if (playerCount >= maxPercent)
     {
         return true;
     }
     return false;
 }
コード例 #4
0
 /// <summary>
 /// Returns true if the attack succeeds, false otherwise.
 /// </summary>
 /// <param name="attackerRole">The role of the player making the attack</param>
 /// <param name="isDeadly">Whether or not the attack will kill the player</param>
 /// <returns>True if the attack succeeds, false otherwise.</returns>
 public bool Attack(Role attackerRole, bool isDeadly, bool indefensible)
 {
     if (!IsProtected || indefensible)
     {
         if (isDeadly)
         {
             Role.KilledBy = attackerRole;
             IsAlive = false;
         }
         return true;
     }
     return false;
 }