private void CreateData()
 {
     Wins.Clear();
     Wins.Add(new WinData()
     {
         Name = "X",
         Wins = 0
     });
     Wins.Add(new WinData()
     {
         Name = "O",
         Wins = 0
     });
     Wins.Add(new WinData()
     {
         Name = "Tie",
         Wins = 0
     });
     lock (collisionLock)
     {
         database.Insert(Wins[0]);
         database.Insert(Wins[1]);
         database.Insert(Wins[2]);
     }
 }
        private void ReDraw()
        {
            if (this.Wins == null)
            {
                this.Wins = new List <PictureBox>();
                foreach (var screen in Screen.AllScreens)
                {
                    var pic = new PictureBox()
                    {
                        Image    = this.Selected.DeviceName == screen.DeviceName ? Resources.win_sel : Resources.win,
                        SizeMode = PictureBoxSizeMode.StretchImage,
                        Tag      = screen
                    };
                    pic.Click += (sender, e) =>
                    {
                        this.Selected = (Screen)((Control)sender).Tag;
                        foreach (var p in Wins)
                        {
                            p.Image = ((Screen)p.Tag).DeviceName == this.Selected.DeviceName ? Resources.win_sel : Resources.win;
                        }
                    };

                    Wins.Add(pic);
                    Canvas.Controls.Add(pic);
                }
            }

            var screens = Wins.Select(p => (Screen)p.Tag).ToArray();

            var minTop   = screens.Select(p => p.Bounds.Top).Min();
            var maxBot   = screens.Select(p => p.Bounds.Bottom).Max();
            var minLeft  = screens.Select(p => p.Bounds.Left).Min();
            var maxRight = screens.Select(p => p.Bounds.Right).Max();

            var hRate = 1d * (Canvas.Width - 20) / (maxRight - minLeft);
            var vRate = 1d * (Canvas.Height - 20) / (maxBot - minTop);

            var rate = Math.Min(hRate, vRate);

            var totalW = (maxRight - minLeft) * rate;
            var totalH = (maxBot - minTop) * rate;

            var offsetX = -(minLeft * rate) + ((Canvas.Width - totalW) / 2);
            var offsetY = -(minTop * rate) + ((Canvas.Height - totalH) / 2);

            foreach (var pic in Wins)
            {
                var screen = (Screen)pic.Tag;
                var x      = Convert.ToInt32(offsetX + (screen.Bounds.Left * rate));
                var y      = Convert.ToInt32(offsetY + (screen.Bounds.Top * rate));

                var w = Convert.ToInt32(screen.Bounds.Width * rate);
                var h = Convert.ToInt32(screen.Bounds.Height * rate);
                pic.Location = new Point(x, y);
                pic.Size     = new Size(w, h);
            }
        }
Beispiel #3
0
        private void CalculateWinsAndLosses(HearthStatsDbContext context, Expression <Func <GameResult, bool> > filter)
        {
            var   games    = context.Games;
            float total    = games.Where(filter).Count();
            float winsC    = games.Where(filter).Count(x => x.Victory && !x.GoFirst);
            float lossesC  = games.Where(filter).Count(x => !x.Victory && !x.GoFirst);
            float winsNC   = games.Where(filter).Count(x => x.Victory && x.GoFirst);
            float lossesNC = games.Where(filter).Count(x => !x.Victory && x.GoFirst);
            var   wins     = winsC + winsNC;
            var   losses   = lossesC + lossesNC;

            WinsAndLosses.Clear();
            Wins.Clear();
            Losses.Clear();
            WithCoin.Clear();
            WithoutCoin.Clear();
            if (total <= 0)
            {
                WinsAndLosses.Add(new StatModel("Wins", 0));
                WinsAndLosses.Add(new StatModel("Losses", 0));
                Wins.Add(new StatModel("Coin", 0));
                Wins.Add(new StatModel("No coin", 0));
                Losses.Add(new StatModel("Coin", 0));
                Losses.Add(new StatModel("No coin", 0));
                WithCoin.Add(new StatModel("Losses", 0));
                WithCoin.Add(new StatModel("Losses", 0));
                WithoutCoin.Add(new StatModel("Losses", 0));
                WithoutCoin.Add(new StatModel("Losses", 0));

                return;
            }

            WinsAndLosses.Add(new StatModel(string.Format("Wins: {0}", wins), wins / total * 100));
            WinsAndLosses.Add(new StatModel(string.Format("Losses: {0}", losses), losses / total * 100));

            Wins.Add(new StatModel(string.Format("Coin: {0}", winsC), winsC / wins * 100));
            Wins.Add(new StatModel(string.Format("No coin: {0}", winsNC), winsNC / wins * 100));

            Losses.Add(new StatModel(string.Format("Coin: {0}", lossesC), lossesC / losses * 100));
            Losses.Add(new StatModel(string.Format("No coin: {0}", lossesNC), lossesNC / losses * 100));

            WithCoin.Add(new StatModel(string.Format("Wins: {0}", winsC), winsC / (winsC + lossesC) * 100));
            WithCoin.Add(new StatModel(string.Format("Losses: {0}", lossesC), lossesC / (winsC + lossesC) * 100));

            WithoutCoin.Add(new StatModel(string.Format("Wins: {0}", winsNC), winsNC / (winsNC + lossesNC) * 100));
            WithoutCoin.Add(new StatModel(string.Format("Losses: {0}", lossesNC), lossesNC / (winsNC + lossesNC) * 100));
        }