Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- public class Program
- {
- public static void Main()
- {
- PlayersController controller = new PlayersController();
- controller.Add("Aboba", 54, false);
- controller.Add("Adoba", 24, false);
- controller.Add("boba", 14, false);
- controller.Add("Abofa", 14, false);
- Console.WriteLine(controller);
- controller.Ban(2);
- Console.WriteLine(controller);
- controller.Remove(1);
- controller.Add("Abofda", 131, false);
- controller.Add("Aboda", 11, false);
- controller.Ban(2);
- Console.WriteLine(controller);
- }
- }
- public class PlayersController
- {
- private List<Player> _players;
- private int _id;
- public PlayersController()
- {
- _players = new List<Player>();
- _id = 0;
- }
- private bool SearchElement(int id, out int index)
- {
- index = 0;
- for (int i = 0; i < _players.Count; ++i)
- {
- if (_players[i].Id == id)
- {
- index = i;
- return true;
- }
- }
- return false;
- }
- public void Add(string name, int level, bool isBanned)
- {
- Player player = new Player(_id, name, level, isBanned);
- Add(player);
- }
- public void Add(Player player)
- {
- _players.Add(player);
- ++_id;
- }
- public void Remove(int id)
- {
- int index;
- if(SearchElement(id, out index))
- _players.RemoveAt(index);
- }
- public void Ban(int id)
- {
- int index;
- if (SearchElement(id, out index))
- _players[index].Ban();
- }
- public void Unban(int id)
- {
- int index;
- if (SearchElement(id, out index))
- _players[index].Unban();
- }
- public override string ToString()
- {
- string output = "";
- foreach (Player player in _players)
- output += String.Format("{0}. {1} - {2} {3}\n",
- player.Id, player.Name, player.Level, player.IsBanned);
- return output;
- }
- }
- public class Player
- {
- public int Id { get; private set; }
- public string Name { get; private set; }
- public int Level { get; private set; }
- public bool IsBanned { get; private set; }
- public Player(int id, string name, int level, bool isBanned)
- {
- Id = id;
- Name = name;
- Level = level;
- IsBanned = isBanned;
- }
- public void Ban()
- {
- IsBanned = true;
- }
- public void Unban()
- {
- IsBanned = false;
- }
- }
Add Comment
Please, Sign In to add comment