简体   繁体   中英

How to use bool operator in

My main problem is, how do I send the index to my bool operator? I tried doing int = 0; and then this player.GetPlayer(i++).KA in my PlayerContainer class, but i = 0 all the time.
player.GetPlayer(i).KA is player's Kills+Assists, if that makes it more understandable.

This code is PlayerContainer.cs class.

class PlayerContainer {
 public Player[] Players;
 public int Count {
  get;
  set;
 }
 public int cycle {
  get;
  set;
 }
 public DateTime date {
  get;
  set;
 }


 public PlayerContainer(int size) {
  Players = new Player[size];
 }
 public void AddPlayer(Player player) {
  Players[Count++] = player;
 }
 public void AddPlayer(Player player, int index) {
  Players[index] = player;
 }
 public Player GetPlayer(int index) {
  return Players[index];
 }
 public static bool operator < (int max, PlayerContainer player) {
  if (max < player.GetPlayer(i++).KA) {
   return true;
  } else
   return false;
 }
 public static bool operator > (int max, PlayerContainer player) {
  int i = 0;
  if (max < player.GetPlayer(i++).KA)
   return true;
  else
   return false;
 }

This is in a Method BestPlayer in my Program.cs class

Player BestPlayer(PlayerContainer AllPlayers) {
 Player player = AllPlayers.GetPlayer(0);
 int max = AllPlayers.GetPlayer(0).KA;
 for (int i = 0; i < AllPlayers.Count; i++) {
  if (max < AllPlayers) {
   max = AllPlayers.GetPlayer(i).KA;
   player = AllPlayers.GetPlayer(i);
  }
 }
 return player;
}
Player BestPlayer(PlayerContainer AllPlayers)
{
    Player player;
    int max = AllPlayers.GetPlayer(0).KA;
    Player best = AllPlayers.GetPlayer(0);
    int tmp;
    for (int i = 1; i < AllPlayers.Count; i++)
    {
        tmp = AllPlayers.GetPlayer(i).KA;
        player = AllPlayers.GetPlayer(i);
        if (tmp > AllPlayers)
        {
             max = tmp;
             best = player;
        }
    }
    return best;
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM