Autor Beitrag
ultraz06
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 84



BeitragVerfasst: So 01.02.09 16:05 
hi ;)
ich will in meinem spiel mein timer.interval währed der laufzeit erhöhen.
es soll so aussehen das ich einen countdown von 2 minuten und 30 sekunden runterlaufen lassen will, aber wenn ich auf einen ballon klicke soll das interval erhöht werden. so dann soll die erhöhunh in dem label angezeigt werden.
also der startwert in dem label ist 00:02:30, sagen wir ich klicke auf einen ballon dann soll die zeit erhöt werden,
also z.b dann auf 2:35 um 5 sek erhöht.
aber wie kann ich das umsetzen?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
procedure TForm1.FormActivate(Sender: TObject);
begin
Cursor := crMyCursor;
Screen.Cursors[crMyCursor] := LoadCursor(HInstance, 'MYCURSOR');
Label3.Caption:='00:02:30'; // Label mit der Startzeit setzen
CountDown :=StrToTime(Label3.Caption) ; // String in Zeit wandeln
time:=Now; // aktuelle Zeit merken
timer3.Enabled:=true;
end;



procedure TForm1.Timer3Timer(Sender: TObject);
begin
Label3.Caption:=FormatDateTime('nn:ss',CountDown-(Now-Time));
end;



if anz>0 then if button=mbleft then
 if (X >= xlila) and (X <= xlila + lila.Width)
    and (Y >= ylila) and (Y <= ylila + lila.Height)
    then begin
              lilasichtbar := false;
               i:=i+5  ;
              timer3.interval:=timer3.interval+50; // hier soll die erhöhung des timers ausgegeben werden, aber es wird nicht in dem label übernohmen
Jann1k
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 866
Erhaltene Danke: 43

Win 7
TurboDelphi, Visual Studio 2010
BeitragVerfasst: So 01.02.09 16:12 
Mach es anders: Lass das Timerintervall auf 1000ms und zieh dann jedesmal von deiner Zeit eine Sekunde ab, bist du bei 0 angelangt ist die Zeit vorbei.
ultraz06 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 84



BeitragVerfasst: So 01.02.09 16:17 
ja so wollte ich es auch erst machen, aber da ging das mit der darstellung 00:00:00 nicht da sind ja dann nur sekunden.
wenn ich das nun so mache wie kann ich dann die zeit im label erhöhen?
ultraz06 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 84



BeitragVerfasst: Mo 02.02.09 12:22 
kann mir keiner helfen oO?
martin300
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 186
Erhaltene Danke: 2



BeitragVerfasst: Mo 02.02.09 12:43 
Hallo,
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TFormX.Button1Click(Sender: TObject);
begin
  label1.caption := '90';
  timer1.Enabled := true;
end;

procedure TFormX.Button2Click(Sender: TObject);
begin
  label1.Caption:= inttostr(strtoint(label1.Caption) + 5);
end;

procedure TFormX.Timer1Timer(Sender: TObject);
begin
  label1.Caption :=  inttostr(strtoint(label1.Caption) -1);
end;


Bei dem Beispiel gibt es 2 Buttons, ein Label und den Timer.
Die vier Zeilen müssen nur in das jeweilige Ereignis kopiert werden.
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Mo 02.02.09 12:56 
Jetzt noch das Ganze in eine Variable stopfen, und nicht die Caption des Labels als Datenspeicher missbrauchen.. ;)
Zusätzlich noch ein FormatDateTime drüber, damit man auch die gewünschte 00:00:00 Form hat und fertig.

_________________
PROGRAMMER: A device for converting coffee into software.
ultraz06 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 84



BeitragVerfasst: Mo 02.02.09 14:04 
wenn ich das so mache
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
if anz>0 then if button=mbleft then
 if (X >= xlila) and (X <= xlila + lila.Width)
    and (Y >= ylila) and (Y <= ylila + lila.Height)
    then begin
              lilasichtbar := false;
               i:=i+5  ;
              label3.Caption:= inttostr(strtoint(label3.Caption) + 5);

kommt das 02:00 kein gültiger integerwert ist
was ist da falsch?
ultraz06 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 84



BeitragVerfasst: Mo 02.02.09 14:12 
es könnte dran liegen das
ausblenden Delphi-Quelltext
1:
2:
Label3.Caption:='00:02:30'; // Label mit der Startzeit setzen
CountDown :=StrToTime(Label3.Caption)
Boldar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: Mo 02.02.09 14:45 
liest du eigentloich die posts oben? DU SOLLST DIE ZEIT IN EINER VARIABLE SPEICHERN!!!
ultraz06 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 84



BeitragVerfasst: Mo 02.02.09 14:49 
ja habe ich gelesen ;)
aber ivch weiß nicht wie ich das format von 00:00 in eine variable speichern soll.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mo 02.02.09 15:01 
Zum Beispiel so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
type
  TForm1 = class(TForm)
    // ... //
  private
    { Private-Deklarationen }
    CountDown: Double;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  CountDown := StrToTime('00:02:00');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  CountDown := CountDown - (1 / 86400);     // 1 Sekunde abziehen (86400 Sekunden = 1 Tag)
  Label1.Caption := TimeToStr(CountDown);
end;

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
ultraz06 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 84



BeitragVerfasst: Mo 02.02.09 15:10 
ja schön und gut aber wie kann da nach dem ich meinen ballon abgeschossen habe, die zeit neu aufs label trasnferieren
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mo 02.02.09 15:13 
Wo ist das Problem? Einfach (5 / 86400) bzw. (1 / 86400) * 5 dazuaddieren.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
ultraz06 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 84



BeitragVerfasst: Mo 02.02.09 17:01 
ok jetzt habe ichs ;)
aber jetzt habe ich das problem das , wenn der countdown 0 ist eine message erscheinen soll
aber iwie zählt er dann von 0 wieder hoch und bleibt nicht auf 0
ausblenden Delphi-Quelltext
1:
2:
if countdown = strtotime('00:00:00') then
      begin timer3.Enabled:=false;  showmessage ('Game Over');    end;
;
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Mo 02.02.09 17:20 
du machst hier einen exakten Vergleich auf zwei Float werte.. das ist nicht gut, weil diese fast nie genau übereinstimmen.
versuchs mit <=
Außerdem machst du ja schon wieder diese überflüssige umwandlung StrToTime.
Solange kein Datum mit im Spiel ist, kannst du einfach <= 0 prüfen.

_________________
PROGRAMMER: A device for converting coffee into software.
ultraz06 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 84



BeitragVerfasst: Mo 02.02.09 17:36 
es geht trotzdem nicht :(
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.FormActivate(Sender: TObject);
begin
Cursor := crMyCursor;
Screen.Cursors[crMyCursor] := LoadCursor(HInstance, 'MYCURSOR');
CountDown := StrToTime('00:00:10');  // String in Zeit wandeln
label3.Caption:='00:10';
if countdown <= 0 then
      begin timer3.Enabled:=false;  showmessage ('Game Over');    end;
end;

es zählt wieder hoch
liegt es vllt an der falschen prozedur?
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Mo 02.02.09 17:46 
Denk nochmal drüber nach, was du da tust.. mal davon abgesehen, dass OnActivate das falsche Ereignis dafür ist.
Du setzt Countdown fest auf 10 Sekunden, und prüfst anschließend, ob Countdown kleiner 0 ist. Wie viele Situationen fallen dir ein, wo das gut geht?

_________________
PROGRAMMER: A device for converting coffee into software.
ultraz06 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 84



BeitragVerfasst: Mo 02.02.09 17:50 
also wäre es besser es in die timer routine zuschreiben?
ultraz06 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 84



BeitragVerfasst: Mo 02.02.09 17:58 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.Timer3Timer(Sender: TObject);
begin
CountDown := CountDown - (1 / 86400);     // 1 Sekunde abziehen (86400 Sekunden = 1 Tag)
Label3.Caption := FormatDateTime('nn:ss',countdown);
if countdown <= 0 then
      begin timer3.Enabled:=false;  showmessage ('Game Over');    end;

aber es zählt dann noch ma von 0 auf 1 und zeigt dann erst game over
ultraz06 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 84



BeitragVerfasst: Di 03.02.09 10:50 
ich weiß wirklich nicht weiter