Zur Themenübersicht        

Autos und Ampeln Aufg.5

Aufgabe 5: zwei Ampeln

Das Auto soll nun vor beiden Ampeln stoppen. Sie sind synchron geschaltet.

 

Lösung als Struktogramm



Erläuterungen:
Im Quellcode müssen die Ortsabfragen nun mit ODER auch die zweite Ampel einbeziehen

Wir ersetzen also:
  if (Auto1.xPosVorne > Ampel1.xPos - 1) and
     (Auto1.xPosVorne <= Ampel1.xPos)    then
durch:
   if ((Auto1.xPosVorne > Ampel1.xPos - 1) and
      (Auto1.xPosVorne <= Ampel1.xPos))
      or
      ((Auto1.xPosVorne > Ampel2.xPos - 1) and
      (Auto1.xPosVorne <= Ampel2.xPos))
   then

 

und analog

ersetzen wir:
  if (Auto1.xPosVorne >  Ampel1.xPos - 100) and
     (Auto1.xPosVorne <= Ampel1.xPos - 1)    then
durch:
   if ((Auto1.xPosVorne > Ampel1.xPos - 100) and
      (Auto1.xPosVorne <= Ampel1.xPos - 1))
      or
      ((Auto1.xPosVorne > Ampel2.xPos - 100) and
      (Auto1.xPosVorne <= Ampel2.xPos - 1))
   then