-
-
Save xjncx/b1a5028c7b6372b39150a3c350e41d37 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace Homework | |
{ | |
class SecondHomeWork | |
{ | |
static void Main(string[] args) | |
{ | |
List<Player> dotaPlayers = new List<Player>(); | |
Player papich = new Player(1, "Папич", 10, false); | |
Player travoman = new Player(2, "Травоман", 10, false); | |
PlayersDatabase dotaPlayersDatabase = new PlayersDatabase(dotaPlayers); | |
dotaPlayersDatabase.AddPlayer(papich); | |
dotaPlayersDatabase.AddPlayer(travoman); | |
dotaPlayersDatabase.ShowPlayers(dotaPlayers); | |
Console.WriteLine("Ща удалим папича"); | |
dotaPlayersDatabase.DeletePlayer(dotaPlayers); | |
dotaPlayersDatabase.ShowPlayers(dotaPlayers); | |
} | |
} | |
class Player | |
{ | |
public int Id { get; private set; } | |
public string Name { get; private set; } | |
public int Level { get; private set; } | |
public bool IsBanned { get; protected set; } | |
public Player(int id, string name, int level, bool isBanned) | |
{ | |
Id = id; | |
Name = name; | |
Level = level; | |
IsBanned = isBanned; | |
} | |
public void ShowPlayerInfo(Player player) | |
{ | |
Console.WriteLine($"Id - {player.Id} Имя - {player.Name} уровень - {player.Level} Забанен - {player.IsBanned}"); | |
} | |
public void BanPlayer(List<Player> players) | |
{ | |
PlayersDatabase playersDataBase = new PlayersDatabase(players); | |
int idPlayerToBan; | |
idPlayerToBan = playersDataBase.FindPlayerById(players); | |
if (idPlayerToBan != 0) | |
{ | |
for (int i = 0; i < players.Count; i++) | |
{ | |
if (i == idPlayerToBan) | |
{ | |
players[i].IsBanned = true; | |
} | |
} | |
} | |
} | |
public void UnBanPlayer(List<Player> players) | |
{ | |
PlayersDatabase playersDataBase = new PlayersDatabase(players); | |
int idPlayerToUnBan; | |
idPlayerToUnBan = playersDataBase.FindPlayerById(players); | |
if (idPlayerToUnBan != 0) | |
{ | |
for (int i = 0; i < players.Count; i++) | |
{ | |
if (i == idPlayerToUnBan) | |
{ | |
players[i].IsBanned = false; | |
} | |
} | |
} | |
} | |
} | |
class PlayersDatabase | |
{ | |
public List<Player> Players { get; private set; } | |
public PlayersDatabase(List<Player> players) | |
{ | |
Players = players; | |
} | |
public void AddPlayer(Player newPlayer) | |
{ | |
Players.Add(newPlayer); | |
} | |
public void DeletePlayer(List<Player> players) | |
{ | |
int idPlayerToDelete; | |
idPlayerToDelete = FindPlayerById(players); | |
for (int i = 0; i < players.Count; i++) | |
{ | |
if(idPlayerToDelete == i) | |
{ | |
players.Remove(players[i]); | |
} | |
} | |
} | |
public void ShowPlayers(List<Player> players) | |
{ | |
for (int i = 0; i < players.Count; i++) | |
{ | |
players[i].ShowPlayerInfo(players[i]); | |
} | |
} | |
public int FindPlayerById(List<Player> players) | |
{ | |
int playersId; | |
string usersInput; | |
bool isParseSuccessed; | |
Console.WriteLine("Введите Id игрока"); | |
usersInput = Console.ReadLine(); | |
isParseSuccessed = int.TryParse(usersInput, out playersId); | |
if (isParseSuccessed == true) | |
{ | |
for (int i = 0; i < players.Count; i++) | |
{ | |
if (players[i].Id == playersId) | |
{ | |
return players[i].Id; | |
} | |
else | |
{ | |
Console.WriteLine("Такого игрока нет"); | |
return 0; | |
} | |
} | |
} | |
else | |
{ | |
Console.WriteLine("Это не число"); | |
} | |
return 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment