Since I got the day off and I wasn't busy, I was just having a play with your little idea. I imagines it was a football game or something to that effect :
public class SetTeam : Players
{
public enum Team
{
Team1 = 1, Team2 = 2
}
public enum Team1Players
{
Player1 = 1, Player2 = 2, Player3 = 3, Player4 = 4, Player5 = 5
}
public enum Team2Players
{
Player1 = 1, Player2 = 2, Player3 = 3, Player4 = 4, Player5 = 5
}
private Dictionary<Team, List<Players>> MyTeam = new Dictionary<Team, List<Players>>();
public SetTeam(Dictionary<Team, List<Players>> myTeam)
{
MyTeam = myTeam;
}
}
public class Players
{
private protected List<Player> List_OfTeam1Players = new List<Player>();
private protected List<Player> List_OfTeam2Players = new List<Player>();
public List<Player>[] Add_Players(List<Enum>[] Teams)
{
if (Teams[0].Count > 0 && Teams[0].Count <= 5 || Teams[1].Count > 0 && Teams[1].Count <= 5)
{
Dictionary<Enum, List<Player>> setTeams = new Dictionary<Enum, List<Player>>();
Teams[0].ToList().ForEach((Enum player) =>
{
dynamic dynamic_Player = new ExpandoObject();
{
dynamic_Player.Location = 20;
dynamic_Player.PlayerNumber = Convert.ChangeType(player, player.GetTypeCode());
dynamic_Player.Name = player.ToString();
List_OfTeam1Players.Add(new Player(dynamic_Player));
}
});
Teams[1].ToList().ForEach((Enum player) =>
{
dynamic dynamic_Player = new ExpandoObject();
{
dynamic_Player.Location = 20;
dynamic_Player.PlayerNumber = Convert.ChangeType(player, player.GetTypeCode());
dynamic_Player.Name = player.ToString();
List_OfTeam1Players.Add(new Player(dynamic_Player));
}
});
return new List<Player>[]
{
List_OfTeam1Players,
List_OfTeam2Players
};
}
return new List<Player>[]
{
List_OfTeam1Players,
List_OfTeam2Players
};
}
}
public class Player
{
public Player(dynamic this_Player)
{
Player_Location = this_Player.Location;
Player_Number = this_Player.PlayerNumber;
Player_Name = this_Player.Name;
}
public string Player_Name { get; set; }
public int Player_Number { get; set; }
public double Player_Location { get; set; }
}
You can call it by putting this into a button or whoever other method you want to use to call the code :
SetTeam game = new SetTeam(new Dictionary<SetTeam.Team, List<Players>>());
List<Enum> TeamOne_Players = new List<Enum> { SetTeam.Team1Players.Player1, SetTeam.Team1Players.Player2, SetTeam.Team1Players.Player3,
SetTeam.Team1Players.Player4, SetTeam.Team1Players.Player5 };
List<Enum> TeamTwo_Players = new List<Enum> { SetTeam.Team2Players.Player1, SetTeam.Team2Players.Player2, SetTeam.Team2Players.Player3,
SetTeam.Team2Players.Player4, SetTeam.Team2Players.Player5 };
List<Enum>[] teams = { TeamOne_Players, TeamTwo_Players };
foreach (var player in from List<Player> Of_Player
in game.Add_Players(teams)
from Player player in Of_Player
select player)
{
Debug.WriteLine($"{player.Player_Name.PadRight(1)} (player number {player.Player_Number}) is at grid location {player.Player_Location} on the map. ");
}
Outputs :
Player1 (player number 1) is at grid location 20 on the map.
Player2 (player number 2) is at grid location 20 on the map.
Player3 (player number 3) is at grid location 20 on the map.
Player4 (player number 4) is at grid location 20 on the map.
Player5 (player number 5) is at grid location 20 on the map.
Player1 (player number 1) is at grid location 20 on the map.
Player2 (player number 2) is at grid location 20 on the map.
Player3 (player number 3) is at grid location 20 on the map.
Player4 (player number 4) is at grid location 20 on the map.
Player5 (player number 5) is at grid location 20 on the map.
So if you have a 5 a side game, the first five are output from the first team, and then second five are from the second team. You can change that here :
if (Teams[0].Count > 0 && Teams[0].Count <= 5 || Teams[1].Count > 0 && Teams[1].Count <= 5)
and by adding more players to your Enums. Its rough, and lot of room for editing, and improving, including removing some inline variables etc. But it will get you started. I do suggest debugging it and stepping through the code so you can see what it's doing, and how it works. If you got stuck, or need to know something, ask me, or if you spot any mistakes, feel free to point any out.
Hope it helps