Ejemplo n.º 1
0
        private void InitializeFromSelectedPlayer()
        {
            // From selected player
            GameStatisticsByPlayer byPlayer = SelectedGameStatistics.Players.FirstOrDefault(x => x.PlayerName == SelectedPlayer);

            if (byPlayer?.SpecialsUsed == null)
            {
                SpecialsFromSelectedPlayerGrid = null;
            }
            else
            {
                List <DynamicColumn> columns = byPlayer.SpecialsUsed.SelectMany(kv => kv.Value).Select(x => x.Key).Distinct().Select(x => new DynamicColumn
                {
                    Name        = x,
                    DisplayName = x,
                    Type        = typeof(string),
                    IsReadOnly  = true,
                }).ToList();
                List <SpecialStatisticsRow> rows = new List <SpecialStatisticsRow>();
                foreach (KeyValuePair <Specials, Dictionary <string, int> > specials in byPlayer.SpecialsUsed.OrderBy(kv => kv.Key))
                {
                    SpecialStatisticsRow row = new SpecialStatisticsRow
                    {
                        Special = specials.Key
                    };
                    foreach (DynamicColumn column in columns)
                    {
                        KeyValuePair <string, int> kv = specials.Value.FirstOrDefault(x => x.Key == column.Name);
                        int value = kv.Equals(default(KeyValuePair <string, int>)) ? 0 : kv.Value;
                        row.TryAddProperty(column.Name, value);
                    }
                    rows.Add(row);
                }
                SpecialsFromSelectedPlayerGrid = new DynamicGrid <SpecialStatisticsRow, DynamicColumn>(rows, columns);
            }
        }
Ejemplo n.º 2
0
        public GameStatisticsViewModelDesignData()
        {
            GameStatisticsHistory = new ObservableCollection <GameStatistics>
            {
                new GameStatistics
                {
                    GameStarted  = DateTime.Now.AddMinutes(-10),
                    GameFinished = DateTime.Now.AddMinutes(-5),
                    Players      = new List <GameStatisticsByPlayer>
                    {
                        new GameStatisticsByPlayer
                        {
                            PlayerName  = "Player1",
                            SingleCount = 4,
                            DoubleCount = 3,
                            TripleCount = 2,
                            TetrisCount = 1,
                        },
                        new GameStatisticsByPlayer
                        {
                            PlayerName  = "Player2",
                            SingleCount = 8,
                            DoubleCount = 6,
                            TripleCount = 4,
                            TetrisCount = 0,
                        },
                        new GameStatisticsByPlayer
                        {
                            PlayerName  = "Player3",
                            SingleCount = 1,
                            DoubleCount = 1,
                            TripleCount = 0,
                            TetrisCount = 0,
                        },
                        new GameStatisticsByPlayer
                        {
                            PlayerName  = "Player4",
                            SingleCount = 0,
                            DoubleCount = 0,
                            TripleCount = 0,
                            TetrisCount = 1,
                        },
                        new GameStatisticsByPlayer
                        {
                            PlayerName  = "Player5",
                            SingleCount = 12,
                            DoubleCount = 7,
                            TripleCount = 0,
                            TetrisCount = 0,
                        },
                        //new GameStatisticsByPlayer
                        //{
                        //    PlayerName = "Player6",
                        //    SingleCount = 20,
                        //    DoubleCount = 17,
                        //    TripleCount = 5,
                        //    TetrisCount = 2,
                        //},
                    }
                },
                new GameStatistics
                {
                    GameStarted  = DateTime.Now.AddMinutes(-20),
                    GameFinished = DateTime.Now.AddMinutes(-18),
                },
                new GameStatistics
                {
                    GameStarted  = DateTime.Now.AddMinutes(-30),
                    GameFinished = DateTime.Now.AddMinutes(-22),
                }
            };
            SelectedGameStatistics = GameStatisticsHistory[0];

            PlayerList = new List <string>
            {
                "Player1",
                "Player2withaverylongname",
                "Player3",
            };
            SelectedPlayer = PlayerList[2];
            List <DynamicColumn> columns = new List <DynamicColumn>
            {
                new DynamicColumn
                {
                    Name        = "Player1",
                    DisplayName = "Player1",
                    Type        = typeof(string),
                    IsReadOnly  = true,
                },
                new DynamicColumn
                {
                    Name        = "Player2withaverylongname",
                    DisplayName = "Player2withaverylongname",
                    Type        = typeof(string),
                    IsReadOnly  = true,
                },
                new DynamicColumn
                {
                    Name        = "Player3",
                    DisplayName = "Player3",
                    Type        = typeof(string),
                    IsReadOnly  = true,
                },
                new DynamicColumn
                {
                    Name        = "Player4",
                    DisplayName = "Player4",
                    Type        = typeof(string),
                    IsReadOnly  = true,
                },
                new DynamicColumn
                {
                    Name        = "Player5",
                    DisplayName = "Player5",
                    Type        = typeof(string),
                    IsReadOnly  = true,
                },
                new DynamicColumn
                {
                    Name        = "Player6",
                    DisplayName = "Player6",
                    Type        = typeof(string),
                    IsReadOnly  = true,
                },
            };
            List <SpecialStatisticsRow> rows = new List <SpecialStatisticsRow>();

            foreach (Specials special in EnumHelper.GetSpecials(b => b))
            {
                SpecialStatisticsRow row = new SpecialStatisticsRow
                {
                    Special = special
                };
                foreach (DynamicColumn column in columns)
                {
                    int value = Randomizer.Instance.Next(20);
                    row.TryAddProperty(column.Name, value);
                }
                rows.Add(row);
            }
            SpecialsFromSelectedPlayerGrid = new DynamicGrid <SpecialStatisticsRow, DynamicColumn>(rows, columns);
            SpecialsToSelectedPlayerGrid   = new DynamicGrid <SpecialStatisticsRow, DynamicColumn>(rows, columns);
        }