Advertisement
HabboGame

EE Player Class

May 13th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. class Player {
  2.     public int Id { get; }
  3.     public string Username { get; }
  4.     public Player (Message e) {
  5.         if (e == null) throw new ArgumentNullException ();
  6.         switch (e.Type) {
  7.             case "init":
  8.                 Id = (int) e[5];
  9.                 Username = (string) e[13];
  10.                 break;
  11.             case "add":
  12.                 Id = (int) e[0];
  13.                 Username = (string) e[1];
  14.                 break;
  15.             default:
  16.                 throw new ArgumentException ("Invalid message type.");
  17.         }
  18.     }
  19.     public Player (int id, string username) {
  20.         if (string.IsNullOrEmpty (username)) throw new ArgumentNullException ();
  21.         Id = id;
  22.         Username = username;
  23.     }
  24.     public static Player FromId (IEnumerable<Player> players, int id) {
  25.         if (players == null) throw new ArgumentNullException ();
  26.         foreach (Player player in players) if (player.Id == id) return player;
  27.         throw new ArgumentException ("No player contains the specified ID.");
  28.     }
  29.     public static Player FromUsername (IEnumerable<Player> players, string username) {
  30.         if (players == null) throw new ArgumentNullException ();
  31.         foreach (Player player in players) if (player.Username == username) return player;
  32.         throw new ArgumentException ("No player contains the specified username.");
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement