public static Schip PlaatsContainers(List <Container> containers, Schip _schip) { List <Container> waardevolContainers = new List <Container>(); List <Container> gekoeldContainers = new List <Container>(); List <Container> standaardContainers = new List <Container>(); foreach (var container in containers) { if (container.Waardevol) { waardevolContainers.Add(container); } else if (container.Gekoeld) { gekoeldContainers.Add(container); } else { standaardContainers.Add(container); } } for (int i = 0; i < 6; i++) { if (waardevolContainers.Count > 0) { if (i != 2 && i != 3) { _schip.Plaatsen[i].containers.Add(waardevolContainers.First()); _schip.Plaatsen[i].Gewicht += waardevolContainers.First().Gewicht; waardevolContainers.Remove(waardevolContainers.First()); } } } //plaatsen[1, 3, 5] zijn links en nu gevuld met de eventuele waardevolle containers die nu het gewicht voor de linkse kant zorgen _schip.GewichtLinks += _schip.Plaatsen[1].Gewicht + _schip.Plaatsen[3].Gewicht + _schip.Plaatsen[5].Gewicht; //plaatsen[0, 2, 4] zijn rechts en nu gevuld met de eventuele waardevolle containers die nu het gewicht voor de rechtse kant zorgen _schip.GewichtRechts += _schip.Plaatsen[0].Gewicht + _schip.Plaatsen[2].Gewicht + _schip.Plaatsen[4].Gewicht; //TODO checken if (gekoeldContainers.Count < 0) { foreach (var gekoeldContainer in gekoeldContainers) { if (_schip.GewichtLinks > _schip.GewichtRechts) { _schip.Plaatsen[0].containers.Add(gekoeldContainer); _schip.GewichtRechts += gekoeldContainer.Gewicht; } else { _schip.Plaatsen[1].containers.Add(gekoeldContainer); _schip.GewichtLinks += gekoeldContainer.Gewicht; } } } return(_schip); }
private void btnStartVerdeling_Click(object sender, EventArgs e) { schip = Schip.PlaatsContainers(Containers, schip); lBContainer1.DataSource = schip.Plaatsen[0].containers; lBContainer2.DataSource = schip.Plaatsen[1].containers; lBContainer3.DataSource = schip.Plaatsen[2].containers; lBContainer4.DataSource = schip.Plaatsen[3].containers; lBContainer5.DataSource = schip.Plaatsen[4].containers; lBContainer6.DataSource = schip.Plaatsen[5].containers; }
private void btnSchipGewicht_Click(object sender, EventArgs e) { var maxGewicht = Convert.ToInt32(upDownSchipGewicht.Value); var minGewicht = Schip.BerekenMinGewicht(maxGewicht); var plaatsen = new List <Plaats>(); for (int i = 0; i < 6; i++) { plaatsen.Add(new Plaats()); } schip = new Schip(maxGewicht, minGewicht, 0, 0, plaatsen); lblGewichtContainers.Text = "0"; lblAantalContainers.Text = "0"; lblMaxGewicht.Text = Convert.ToString(maxGewicht); lblMinGewicht.Text = Convert.ToString(minGewicht); btnSchipGewicht.Enabled = false; btnVoegContainerToe.Enabled = true; }