![]() |
Re: ampel programmieren
Ich habe jetzt eine funktionierende ampel, aber verstehe nicht, wie ich es mit dem auto machen soll.
So hier meinen quelltext
Delphi-Quellcode:
unit Unit1;
interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) pnHintergrund: TPanel; btnSchaltung: TButton; Panel1: TPanel; Panel2: TPanel; Timer1: TTimer; pnGruen: TShape; pnGelb: TShape; pnRot: TShape; procedure btnRotClick(Sender: TObject); procedure btnGelbClick(Sender: TObject); procedure btnGruenClick(Sender: TObject); procedure btnGelb1Click(Sender: TObject); procedure btnSchaltungClick(Sender: TObject); procedure Timer1Timer(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.btnRotClick(Sender: TObject); begin pnRot.Brush.Color :=clred; pnGelb.Brush.color := clblack; pnGruen.Brush.color := clblack; end; procedure TForm1.btnGelbClick(Sender: TObject); begin pnGelb.Brush.color := clyellow; pnGruen.Brush.color := clblack; end; procedure TForm1.btnGruenClick(Sender: TObject); begin pnGruen.Brush.color := clgreen; pnRot.Brush.color := clblack; pnGelb.Brush.color := clblack; end; procedure TForm1.btnGelb1Click(Sender: TObject); begin pnGelb.Brush.color := clyellow; pnGruen.Brush.color := clNone; end; procedure TForm1.btnSchaltungClick(Sender: TObject); begin if ((pnRot.Brush.color = clRed) and (pnGelb.Brush.color = clBlack) and (pnGruen.Brush.color = clBlack)) then begin pnGelb.Brush.color := clyellow; pnRot.Brush.color := clred; pnGruen.Brush.color := clblack; end else if ((pnRot.Brush.color = clred) and (pnGelb.Brush.color = clyellow) and (pnGruen.Brush.color = clblack)) then begin pnGelb.Brush.color := clblack; pnRot.Brush.color := clblack; pnGruen.Brush.color := clgreen; end else if ((pnRot.Brush.color = clblack) and (pnGelb.Brush.color = clblack) and (pnGruen.Brush.color = clgreen)) then begin pnGelb.Brush.color:=clyellow; pnGruen.Brush.color:=clblack ; pnRot.Brush.color:=clblack; end else if ((pnRot.Brush.color = clblack) and (pnGelb.Brush.color = clyellow) and (pnGruen.Brush.color = clblack)) then begin pnGelb.Brush.color := clblack; pnRot.Brush.color := clred; pnGruen.Brush.color := clblack; end end; procedure TForm1.Timer1Timer(Sender: TObject); begin btnSchaltung.Click end; end. |
Re: ampel programmieren
Zitat:
|
Re: ampel programmieren
Zitat:
|
Re: ampel programmieren
sollte ja normal nicht so schwer sein?
ich hab dir den Code gepostet, wie du ein Auto malen kannst, dass fährt auch, dass ist durch den timer geregelt. Jetzt kannst du dir aus Spaß z.b. Die Form weiß malen, da nen graues Rechteck als Straße drauf und da malst du dann das Auto drauf. Dann hast du dein Ampel sicher irgendwo positioniert nehm ich mal an. Dann kannst du den X-Wert im Timer prüfen ob er an der Position der Ampel ist oder halt kurz davor, wie du willst. Und dann prüfst du ob die Ampel rot ist und wenn sie rot ist, erhöhst du den X-Wert nicht mehr. Ich weiß jetzt nicht, wo da großartig ein Problem sein soll. Wie Luckie schon sagte, schildere mal dein Problem^^ Randabfrage geht ja so ähnlich, also wenn x>Form.width dann x->0? |
Re: ampel programmieren
Zitat:
Und danke für die Antworten an alle, hat mir sehr geholfen. Leider muss ich das bei alten delphi 7.0 betreiben, da das rad 2009 pro nicht kompatibel ist. |
Re: ampel programmieren
Hallo zusammen,
Es handelt sich um Delphi 5!!! ich habe hier eine Ampelkreuzung mit 2 Ampeln dies klappt soweit. Ich bitte um eure hilfe, wie ich das auf 4 Ampeln mit Autos erweitere. Außerdem sollten die Ampeln wie in echt schalten ;). Bitte beachtet das ich ein anfänger bin ;). Poste einfach mal den Quelltext:
Delphi-Quellcode:
unit Unit1;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls; type TForm1 = class(TForm) Shape1: TShape; Shape2: TShape; shpRed1: TShape; shpYellow1: TShape; shpGreen1: TShape; shpYellow2: TShape; shpRed2: TShape; shpGreen2: TShape; Shape9: TShape; Shape10: TShape; Shape11: TShape; Shape12: TShape; Shape13: TShape; Shape14: TShape; Shape15: TShape; Shape16: TShape; Shape17: TShape; Shape18: TShape; Shape19: TShape; Shape20: TShape; Shape21: TShape; Shape22: TShape; Shape23: TShape; Shape24: TShape; Shape25: TShape; Shape26: TShape; Shape27: TShape; Shape28: TShape; Shape29: TShape; Shape30: TShape; Shape32: TShape; Shape33: TShape; Shape34: TShape; Shape35: TShape; Shape36: TShape; Shape37: TShape; Shape38: TShape; Shape39: TShape; Shape31: TShape; Shape40: TShape; Shape41: TShape; Shape42: TShape; Shape43: TShape; Shape44: TShape; Shape45: TShape; Shape46: TShape; Shape47: TShape; Shape48: TShape; Shape49: TShape; Shape50: TShape; Shape51: TShape; Shape52: TShape; Shape53: TShape; Shape54: TShape; Shape55: TShape; Shape56: TShape; Shape57: TShape; Shape59: TShape; Shape60: TShape; Shape61: TShape; Shape62: TShape; Shape63: TShape; Shape64: TShape; Shape65: TShape; Shape66: TShape; Shape67: TShape; Shape68: TShape; Button1: TButton; Timer1: TTimer; procedure shpRed2MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure Timer1Timer(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.shpRed2MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin Close; end; procedure TForm1.Timer1Timer(Sender: TObject); begin if shpGreen2.Brush.Color = clblack then begin Timer1.interval := 3000; shpRed2.Brush.Color := clred; shpYellow2.Brush.Color := clblack; shpGreen2.Brush.Color := clnone; shpRed1.Brush.Color := clred; shpYellow1.Brush.Color := clblack; shpGreen1.Brush.Color := clnone; end else if shpYellow2.Brush.Color = clblack then begin Timer1.interval := 3000; shpRed2.Brush.Color := clred; shpYellow2.Brush.Color := clyellow; shpGreen2.Brush.Color := clnone; shpRed1.Brush.Color := clred; shpYellow1.Brush.Color := clyellow; shpGreen1.Brush.Color := clnone; end else if shpRed2.Brush.Color = clred then begin Timer1.interval := 3000; shpRed2.Brush.Color := clnone; shpYellow2.Brush.Color := clnone; shpGreen2.Brush.Color := cllime; shpRed1.Brush.Color := clnone; shpYellow1.Brush.Color := clnone; shpGreen1.Brush.Color := cllime; end else if shpGreen2.Brush.Color = cllime then begin Timer1.interval := 3000; shpRed2.Brush.Color := clblack; shpYellow2.Brush.Color := clyellow; shpGreen2.Brush.Color := clblack; shpRed1.Brush.Color := clblack; shpYellow1.Brush.Color := clyellow; shpGreen1.Brush.Color := clblack; end end; end. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:11 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz