Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Player {
- public int Id { get; }
- public string Username { get; }
- public Player (Message e) {
- if (e == null) throw new ArgumentNullException ();
- switch (e.Type) {
- case "init":
- Id = (int) e[5];
- Username = (string) e[13];
- break;
- case "add":
- Id = (int) e[0];
- Username = (string) e[1];
- break;
- default:
- throw new ArgumentException ("Invalid message type.");
- }
- }
- public Player (int id, string username) {
- if (string.IsNullOrEmpty (username)) throw new ArgumentNullException ();
- Id = id;
- Username = username;
- }
- public static Player FromId (IEnumerable<Player> players, int id) {
- if (players == null) throw new ArgumentNullException ();
- foreach (Player player in players) if (player.Id == id) return player;
- throw new ArgumentException ("No player contains the specified ID.");
- }
- public static Player FromUsername (IEnumerable<Player> players, string username) {
- if (players == null) throw new ArgumentNullException ();
- foreach (Player player in players) if (player.Username == username) return player;
- throw new ArgumentException ("No player contains the specified username.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement