Ejemplo n.º 1
0
        public GameForm()
        {
            Width           = 1000;
            Height          = Game.Height;
            DoubleBuffered  = true;
            WindowState     = FormWindowState.Maximized;
            Game.ShotsLimit = 3;

            var canvas = new CustomPanel()
            {
                Width                 = Game.Width,
                Height                = Game.Height,
                BackgroundImage       = Textures.Collection["corusant_state1"],
                Dock                  = DockStyle.Fill,
                BackgroundImageLayout = ImageLayout.Stretch
            };

            canvas.Paint += (sender, args) =>
            {
                Drawer.PaintStartScreen(args.Graphics, canvas);
                Drawer.PaintScore(args.Graphics, Game);
                Drawer.PaintPlayer(args.Graphics, Game.Player);
                Drawer.PaintObstacles(args.Graphics, Game);
                Drawer.PaintBlasts(args.Graphics, Game.Blasts);
                Drawer.PaintEnemies(args.Graphics);
                Drawer.PaintDeathScreen(args.Graphics, canvas);
            };
            KeyDown += KeyBoardHandler;

            Controls.Add(canvas);

            var bgCounter    = 1;
            var planeCounter = 1;

            timer.Tick += (sender, args) =>
            {
                Tools.SetCanvasFlickering(canvas, ref bgCounter, 30);
                Tools.SetPlaneFlickering(Game, ref planeCounter, 10);

                foreach (var obs in Game.Obstacles)
                {
                    obs.SetLocation(obs.X - 10, obs.Y);

                    if (obs.IntersectsWithPlayer(Game.Player))
                    {
                        explosionSound.Play();
                        PlayerCurrentStructure = Textures.Collection["xwing_destroyed"];
                        Game.Finish();
                        timer.Stop();
                    }
                }

                var blastsToRemove  = new HashSet <Blast>();
                var enemiesToRemove = new HashSet <Enemy>();

                foreach (var blast in Game.Blasts)
                {
                    var obsToRemove = new HashSet <Obstacle>();
                    blast.Move(MoveDirection.Right);

                    if (blast.X > Game.Width)
                    {
                        blastsToRemove.Add(blast);
                    }

                    foreach (var obs in Game.Obstacles)
                    {
                        if (blast.IntersectsWithObstacle(obs))
                        {
                            blastsToRemove.Add(blast);
                            obsToRemove.Add(obs);
                            Game.Score++;
                        }
                    }

                    foreach (var enemy in Game.Enemies)
                    {
                        if (blast.IntersectsWithEnemy(enemy))
                        {
                            blastsToRemove.Add(blast);
                            enemiesToRemove.Add(enemy);
                            Game.Score *= 2;
                        }
                    }

                    foreach (var enemy in enemiesToRemove)
                    {
                        Game.Enemies.Remove(enemy);
                    }

                    foreach (var obs in obsToRemove)
                    {
                        Game.Obstacles.Remove(obs);
                        Game.Obstacles.Add(Game.GenerateObstacles(1).First());
                    }
                }

                foreach (var blast in blastsToRemove)
                {
                    Game.Blasts.Remove(blast);
                }

                canvas.Invalidate();
            };
        }
Ejemplo n.º 2
0
        private void RunnerSponsor_Load(object sender, EventArgs e)
        {
            this.DoubleBuffered = true;

            mainThread = new Thread(() =>
            {
                while (true)
                {
                    DateTime eTime;
                    DateTime.TryParse(s_GlobalMarathonDate, out eTime);
                    var resultTime = eTime.Subtract(DateTime.Now);
                    if (lbEndTime.InvokeRequired && !lbEndTime.IsDisposed)
                    {
                        if (resultTime > TimeSpan.Zero)
                        {
                            lbEndTime.BeginInvoke((MethodInvoker)(() => lbEndTime.Text = getTime(resultTime)));
                        }

                        lbEndTime.BeginInvoke((MethodInvoker)(() => lbEndTime.Location = new Point((this.Size.Width - lbEndTime.Size.Width) / 2, 16)));
                    }
                    Thread.Sleep(1000);
                }
            })
            {
                IsBackground = true,
                Priority     = ThreadPriority.Lowest
            };
            mainThread.Start();

            if (string.IsNullOrEmpty(m_pRunnerId))
            {
                MessageBox.Show(this, "Fatal Error", "Err", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            new Thread(() =>
            {
                using (var m_mainISqlDat = new SqlDataAdapter($@"SELECT dbo.Charity.CharityName, dbo.Charity.CharityLogo, dbo.Charity.CharityDescription, dbo.Sponsorship.SponsorName, dbo.Sponsorship.Amount, dbo.Runner.Email
                         FROM dbo.Event INNER JOIN
                         dbo.Marathon ON dbo.Event.MarathonId = dbo.Marathon.MarathonId INNER JOIN
                         dbo.RegistrationEvent ON dbo.Event.EventId = dbo.RegistrationEvent.EventId INNER JOIN
                         dbo.Sponsorship INNER JOIN
                         dbo.Registration ON dbo.Sponsorship.RegistrationId = dbo.Registration.RegistrationId INNER JOIN
                         dbo.Charity ON dbo.Registration.CharityId = dbo.Charity.CharityId INNER JOIN
                         dbo.Runner ON dbo.Registration.RunnerId = dbo.Runner.RunnerId INNER JOIN
                         dbo.[User] ON dbo.Runner.Email = dbo.[User].Email ON dbo.RegistrationEvent.RegistrationId = dbo.Registration.RegistrationId
                         WHERE (dbo.Marathon.MarathonName = '{s_GlobalMarathonName}') AND (dbo.Runner.Email = '{m_pRunnerId}')", sqlConnection))
                {
                    var dt = new DataTable();
                    m_mainISqlDat.Fill(dt);

                    if (dt.Rows.Count == 0)
                    {
                        this.Invoke(new MethodInvoker(() =>
                        {
                            lbCharityName.Visible = imgCharity.Visible = lbdesc.Visible = label1.Visible = label4.Visible = splitter.Visible = lbAmount.Visible = false;
                            MessageBox.Show(this, "Спонсоры отсутствуют!", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }));
                        return;
                    }

                    CustomPanel cPanel = new CustomPanel();
                    cPanel.Location    = new Point(564, 275);
                    cPanel.AutoScroll  = true;
                    cPanel.Size        = new Size(359, 235);
                    this.Invoke(new MethodInvoker(() => this.Controls.Add(cPanel)));

                    lbCharityName.Invoke(new MethodInvoker(() =>
                    {
                        lbCharityName.Text     = dt.Rows[0][0].ToString();
                        lbCharityName.Location = new Point((imgCharity.Size.Width / 2) - (lbCharityName.Size.Width / 2) + 65, 230);
                    }));

                    imgCharity.Invoke(new MethodInvoker(() =>
                    {
                        imgCharity.BackgroundImage = Image.FromFile(string.Concat(g_PathCharityFolder, @"\\", dt.Rows[0][1].ToString()));
                        WinAPI.SetWindowRgn(imgCharity.Handle, WinAPI.CreateEllipticRgn(0, 0, imgCharity.Width, imgCharity.Height), true);
                    }));

                    lbdesc.Invoke(new MethodInvoker(() =>
                    {
                        lbdesc.Location = new Point(36, 520);
                        lbdesc.Size     = new Size(323, 145);
                        lbdesc.Text     = dt.Rows[0][2].ToString().Length > 170 ? dt.Rows[0][2].ToString().Remove(170) + "..." : dt.Rows[0][2].ToString();
                    }));

                    int AutoYReserveLabel = 16;
                    cPanel.Invoke(new MethodInvoker(() =>
                    {
                        cPanel.AutoScrollMinSize = new Size(0, dt.Rows.Count * 20);

                        cPanel.Scroll += (__o, __p) => cPanel.Invalidate();
                        cPanel.Paint  += (__o, __p) =>
                        {
                            AutoYReserveLabel = 16;

                            decimal i_amountref = 0;
                            for (int i = 0; i < dt.Rows.Count; i++)
                            {
                                __p.Graphics.DrawString(dt.Rows[i][3].ToString().Length > 25 ? dt.Rows[i][3].ToString().Remove(22) + "..." : dt.Rows[i][3].ToString(), new Font("Arial", 12), Brushes.Black, 9, AutoYReserveLabel);
                                __p.Graphics.DrawString(string.Concat("$", dt.Rows[i][4].ToString()), new Font("Arial", 12), Brushes.Black, 260, AutoYReserveLabel);

                                AutoYReserveLabel += 38;
                                i_amountref       += Convert.ToDecimal(dt.Rows[i][4].ToString());
                            }

                            lbAmount.Invoke(new MethodInvoker(() =>
                            {
                                lbAmount.Visible  = true;
                                lbAmount.Text     = string.Concat("Всего $", i_amountref.ToString());
                                lbAmount.Location = new Point(splitter.Location.X + (splitter.Size.Width - lbAmount.Size.Width), 537);
                            }));
                        };
                        cPanel.Invalidate();
                    }));
                }
                Thread.CurrentThread.Abort();
            })
            {
                IsBackground = true,
                Priority     = ThreadPriority.Highest
            }.Start();
        }