Exemplo n.º 1
0
        private void AccelerateClick(object sender, EventArgs e)
        {
            IAccelerate accelerate = (IAccelerate)objectComboBox.SelectedItem;

            accelerate.Accelerate(5);
            panel.GetChildAtPoint(new Point(0, 0)).Text = "Speed: " + accelerate.getSpeed();
        }
Exemplo n.º 2
0
        private void listOfAdded_SelectedIndexChanged(object sender, EventArgs e)
        {
            riseBox.Enabled = false;
            heightBox.Clear();

            accBox.Enabled = false;
            speedBx.Clear();

            deepBox.Enabled = false;
            depthBox.Clear();

            if (listOfAdded.SelectedItem is IAccelerate)
            {
                accBox.Enabled = true;

                heightBox.Clear();
                depthBox.Clear();

                IAccelerate sped = (IAccelerate)listOfAdded.SelectedItem;
                speedBx.Text = sped.getSpeed().ToString();
            }


            if (listOfAdded.SelectedItem is IDepth)
            {
                deepBox.Enabled = true;

                heightBox.Clear();

                IDepth depf = (IDepth)listOfAdded.SelectedItem;
                depthBox.Text = depf.getDepth().ToString();
            }

            if (listOfAdded.SelectedItem is IHeight)
            {
                riseBox.Enabled = true;

                depthBox.Clear();

                IHeight hajt = (IHeight)listOfAdded.SelectedItem;
                heightBox.Text = hajt.getHeight().ToString();
            }
        }
Exemplo n.º 3
0
        private void objectList_SelectedIndexChanged(object sender, EventArgs e)
        {
            label1.Text = objectComboBox.SelectedItem.GetType().Name;
            panel.Controls.Clear();
            panel2.Controls.Clear();

            Type   t            = objectComboBox.SelectedItem.GetType();
            Object selectedItem = objectComboBox.SelectedItem;

            var   interfaces  = t.GetInterfaces();
            int   x           = 0;
            int   y           = 0;
            Point labelPoint  = new Point(x, y);
            Point buttonPoint = new Point(x, y);

            bool isSpeedDisplayed = false;
            bool isHeighDisplayed = false;

            foreach (Type i in interfaces)
            {
                if (i.Equals(typeof(IAccelerate)))
                {
                    IAccelerate iAccelerate = (IAccelerate)selectedItem;

                    if (!isSpeedDisplayed)
                    {
                        CreateLabel("Speed: " + iAccelerate.getSpeed(), labelPoint);
                        isSpeedDisplayed = true;
                        labelPoint.Y    += 25;
                    }
                    Button accelerate = new Button();
                    accelerate.Click   += AccelerateClick;
                    accelerate.Text     = "Accelerate";
                    accelerate.Location = buttonPoint;
                    panel2.Controls.Add(accelerate);
                    buttonPoint.Y += 25;
                }
                else if (i.Equals(typeof(ISlowDown)))
                {
                    ISlowDown iSlowDown = (ISlowDown)selectedItem;
                    if (!isSpeedDisplayed)
                    {
                        CreateLabel("Speed: " + iSlowDown.getSpeed(), labelPoint);
                        isSpeedDisplayed = true;
                        labelPoint.Y    += 25;
                    }

                    Button slowDown = new Button();
                    slowDown.Click   += SlowDownClick;
                    slowDown.Text     = "SlowDown";
                    slowDown.Location = buttonPoint;
                    panel2.Controls.Add(slowDown);
                    buttonPoint.Y += 25;
                }
                else if (i.Equals(typeof(IRise)))
                {
                    IRise iRise = (IRise)selectedItem;
                    if (!isHeighDisplayed)
                    {
                        CreateLabel("Height: " + iRise.getHeight(), labelPoint);
                        isHeighDisplayed = true;
                        labelPoint.Y    += 25;
                    }

                    isHeighDisplayed = true;
                    Button rise = new Button();
                    rise.Click   += RiseClick;
                    rise.Text     = "Rise";
                    rise.Location = buttonPoint;
                    panel2.Controls.Add(rise);
                    buttonPoint.Y += 25;
                }
                else if (i.Equals(typeof(IDive)))
                {
                    IDive iDive = (IDive)selectedItem;
                    if (!isHeighDisplayed)
                    {
                        CreateLabel("Height: " + iDive.getHeight(), labelPoint);
                        isHeighDisplayed = true;
                        labelPoint.Y    += 25;
                    }

                    Button dive = new Button();
                    dive.Click   += DiveClick;
                    dive.Text     = "Dive";
                    dive.Location = buttonPoint;
                    panel2.Controls.Add(dive);
                    buttonPoint.Y += 25;
                }
            }
        }