예제 #1
0
        private void refreshLapsAndInfo()
        {
            if (lbDrivers.SelectedIndex != -1)
            {
                lbLaps.Items.Clear();
                Driver driver = (Driver)lbDrivers.SelectedItem;
                if (driver.Laps.Count != 0)
                {
                    foreach (Lap lap in driver.Laps)
                    {
                        if (lap.lapToSeconds() >= (int)numericUpDown3.Value)
                        {
                            lbLaps.Items.Add(lap);
                        }
                    }

                    Lap bestLap = driver.bestLap();
                    if (bestLap != null)
                    {
                        textBox1.Text = driver.bestLap().ToString();
                    }
                    else
                    {
                        textBox1.Clear();
                    }
                }
            }
        }
        public Lap bestLap()
        {
            Lap fastestLap = Laps.ElementAt(0);

            foreach (Lap lap in Laps)
            {
                if (lap.lapToSeconds() < fastestLap.lapToSeconds())
                {
                    fastestLap = lap;
                }
            }

            return(fastestLap);
        }
예제 #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (lbDrivers.SelectedIndex != -1)
            {
                int minutes;
                int.TryParse(numericUpDown1.Value.ToString(), out minutes);

                int seconds;
                int.TryParse(numericUpDown2.Value.ToString(), out seconds);

                Lap    lap    = new Lap(seconds, minutes);
                Driver driver = (Driver)lbDrivers.SelectedItem;
                driver.addLap(lap);
                textBox1.Text = driver.bestLap().ToString();
                refreshLapsAndInfo();
            }
            else
            {
                MessageBox.Show("Select a driver first!");
            }
        }
 public void removeLap(Lap lap)
 {
     Laps.Remove(lap);
 }
 public void addLap(Lap lap)
 {
     Laps.Add(lap);
 }