Esempio n. 1
0
        private void PolygonPanel2_Commited(object sender, System.EventArgs e)
        {
            polygon2.Dispose();
            polygon2 = polygonPanel2.Polygon;

            Reset();
        }
Esempio n. 2
0
        private void MainForm_Shown(object sender, System.EventArgs e)
        {
            polygonPanel1.Commit();
            polygonPanel2.Commit();

            polygon1 = polygonPanel1.Polygon;
            polygon2 = polygonPanel2.Polygon;
            collided = null;

            polygonPanel1.Commited += PolygonPanel1_Commited;
            polygonPanel2.Commited += PolygonPanel2_Commited;

            maxTime       = System.Math.Min(polygon1.StepsAmount, polygon2.StepsAmount);
            timeCounter   = 0;
            currentSquare = 0;

            timer.Start();
        }
Esempio n. 3
0
        // PAINTING
        private void displayPb_Paint(object sender, PaintEventArgs e)
        {
            graphics.Clear(Color.LightGray);
            try
            {
                // check for collision
                collided?.Dispose();
                Classes.CollisionOption collisionOption = Classes.Polygon.Collided(polygon1, polygon2);
                if (collisionOption.Collided == true)
                {
                    // collision point
                    foreach (var item in collisionOption.Points)
                    {
                        graphics.FillEllipse(Brushes.Red, item.X - 2, item.Y - 2, 4, 4);
                    }
                    // collision area
                    collided      = Classes.Polygon.CollidedZone(collisionOption.Points);
                    currentSquare = collided.S;
                    MaxSquare     = currentSquare;
                }
                else
                {
                    collided      = null;
                    currentSquare = 0;
                }

                // showing all
                polygon1?.Show(graphics);
                polygon2?.Show(graphics);
                collided?.Show(graphics);
                // text
                graphics.DrawString(string.Format(TIME_MESSAGE_FORMAT, timeCounter), this.Font, Brushes.Black, 15, 10);
                graphics.DrawString(string.Format(SQUARE_MESSAGE_FORMAT, currentSquare), this.Font, Brushes.Black, 15, 30);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, ex.TargetSite.Name, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                timer.Stop();
                timeCounter = 0;
                return;
            }
        }