this slowpoke moves

Draw Traffic Light Simulation

var
  Form1: TForm1;
  zaehler:integer;
  
//

procedure TForm1.Button1Click(Sender: TObject);
begin
  Timer1.Enabled:=false;
  Timer2.Enabled:=false;
  Shape2.Brush.Color:=ClRed;
  Shape3.Brush.Color:=ClBtnShadow;
  Shape4.Brush.Color:=ClBtnShadow;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Timer1.Enabled:=false;
  Timer2.Enabled:=false;
  Shape3.Brush.Color:=ClYellow;
  Shape2.Brush.Color:=ClBtnShadow;
  Shape4.Brush.Color:=ClBtnShadow;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  Timer1.Enabled:=false;
  Timer2.Enabled:=false;
  Shape4.Brush.Color:=ClLime;
  Shape2.Brush.Color:=ClBtnShadow;
  Shape3.Brush.Color:=ClBtnShadow;
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
  Timer1.Enabled:=false;
  Timer2.Enabled:=false;
  Shape2.Brush.Color:=ClBtnShadow;
  Shape3.Brush.Color:=ClBtnShadow;
  Shape4.Brush.Color:=ClBtnShadow;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  zaehler:=0;
  Timer1.Enabled:=true;
  Timer2.Enabled:=false;
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
  zaehler:=0;
  Timer1.Enabled:=false;
  Timer2.Enabled:=true;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  zaehler:=zaehler+1;
  if zaehler>2 then zaehler:=1;
  if zaehler=1 then begin
  Shape3.brush.color:=ClYellow;
  Shape2.brush.color:=ClBtnShadow;
  Shape4.brush.color:=ClBtnShadow;
end;

  if zaehler=2 then begin
    Shape3.brush.color:=ClBtnShadow;
    Shape2.brush.color:=ClBtnShadow;
    Shape4.brush.color:=ClBtnShadow;
  end;
end;

procedure TForm1.Timer2Timer(Sender: TObject);
begin
  zaehler:=zaehler+1;

  if zaehler>4 then zaehler:=1;
    if zaehler=1 then begin
      Shape2.brush.color:=ClRed;
      Shape3.brush.color:=ClBtnShadow;
      Shape4.brush.color:=ClBtnShadow;
    end;

    if (zaehler=2) or (zaehler=4) then begin
      if zaehler=2 then Shape2.brush.color:=ClRed
    else Shape2.brush.color:=ClBtnShadow;
    Shape3.brush.color:=ClYellow;
    Shape4.brush.color:=ClBtnShadow;
    end;

    if zaehler=3 then begin
    Shape2.brush.color:=ClBtnShadow;
    Shape3.brush.color:=ClBtnShadow;
    Shape4.brush.color:=ClLime;
end;

end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate