I'm having trouble implementing a depth chart for my football simulator program. The way my program is structured, I have a Player class, a Team class, and a League class--the core classes. The depthchart would group players by their position and, by each position, sort by OVR (integer) in descending order (but only if their injury status is "false"--governed by a CanPlay method in my Player class; otherwise, they are not eligible for the depthchart). Position is a PlayerPosition type and PlayerPosition is enumerated as such:
This is in my Team class:Code:public enum PlayerPosition { QB, HB, WR, TE, LT, LG, C, RG, RT, DE, DT, OLB, MLB, CB, FS, SS }
These are in my Main() method: two attempts to obtain information from the depth chart.Code:public List<Player> depthChart { get; set; } public List<Player>[] DepthChart { get { var result = new List<Player>[Enum.GetValues(typeof(PlayerPosition)).Length]; foreach (PlayerPosition pos in Enum.GetValues(typeof(PlayerPosition))) { result[(int)pos] = this.Players.Where(pl => pl.position == pos && pl.CanPlay).OrderByDescending(pl => pl.OVR).ToList(); } return result; }
Method 1:
Method 2:Code:Team t = league.Teams[0]; var depthChart = t.DepthChart; Console.WriteLine(depthChart);
For method 1, I get on the console readout: System.Collections.Generic.List`1[FranchiseSim.Player][]Code:foreach (PlayerPosition pos in Enum.GetValues(typeof(PlayerPosition))) { Console.Write(pos.ToString() + ':'); depthChart[(int)pos].ForEach(p => Console.Write(' ' + p.lastName)); Console.WriteLine(); }
For method 2, I get on the console readout only the proper position strings (like QB, RB, etc.) and the colon (but nothing from the depth chart.




but nothing from the depth chart.
Reply With Quote