I have two classes. One is called Component and the second one is called PipeLine.
*Component Class*
string id;
int flow;
List<PipeLine> ConnectedPipeLines;
void ChangeFlow(int flow);
void CalculateFlow();
*PipeLine Class*
int flow;
Component startComponent;
Component endComponent;
void RecalculateFlow();
A component can have multiple pipelines but a pipeline can only connect to two components. One at the start and one at the end.
The pipeline gets its flow from the startComponent, and the endComponent gets its flow from the pipeline.Flow.
public Pipeline(Component startComponent, Component endComponent);
When a pipeline is created the pipeline gets added to the list of ConnectedPipelines for the start and end component.
So ConnectedPipeLines.Add(p); gets executed.
I have a function that can change the flow of any component, and I would like to go through every component and execute component.CalculateFlow() and with that then I can execute pipeline.CalculateFlow() to recalculate the flow of the pipeline, because the endComponent gets its flow from the pipelines flow.
This is the way I am doing it, but if I debug it to find out which two components are being connected in the current pipe that I am looping through it it only recalculates the first level (Component A1 and AB) but not Component A10 and Component A11. Where am I going wrong?
foreach(var pipe in pump.Output.StartComponent.ConnectedPipeLines) {
pipe.EndComponent.CalculateFlow();
foreach(var p in pipe.EndComponent.ConnectedPipeLines) {
p.EndComponent.CalculateFlow();
foreach(var item in p.EndComponent.ConnectedPipeLines) {
item.EndComponent.CalculateFlow()
}
}
}
