| Autor |
Beitrag |
jaenicke
      
Beiträge: 19346
Erhaltene Danke: 1754
W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
|
Verfasst: Fr 06.02.09 18:14
ultraz06 hat folgendes geschrieben : | | da müsste die wahscheinlichkeit 90% sein , dann habe ich das in nen timer geschrieben aber es kommt nix |
Sind xrosa und yrosa denn richtig initialisiert?
Oder kann es sein, dass das irgendwo sofort wieder überzeichnet wird?
Sonst häng am besten das Projekt einmal an, eigentlich sieht das sonst richtig aus.
DeddyH hat folgendes geschrieben : | | Nimm Dir doch einfach eine TImagelist, pack die Bilder da rein und lasse Dir für das nächste Bild einen zufälligen Index generieren, dann ist das erste Problem schonmal vom Tisch. |
Dass das Konzept insgesamt nicht sinnvoll ist, ist klar, aber das wurde glaube ich auch schon in einem der Threads gesagt. 
|
|
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1
|
Verfasst: Fr 06.02.09 18:38
Ich komm bei dieser Logik nicht mehr mit, vielleicht bin ich zu blöd, ich weiß es nicht.
|
|
ultraz06 
      
Beiträge: 84
|
Verfasst: Fr 06.02.09 18:42
ok 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: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls;
type TForm1 = class(TForm) Timer1: TTimer; paintbox1: TPaintBox; Label1: TLabel; Image1: TImage; Image2: TImage; Image3: TImage; Image4: TImage; Image5: TImage; Image6: TImage; Image7: TImage; Timer2: TTimer; Timer3: TTimer; Label3: TLabel; procedure FormCreate(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure paintbox1Paint(Sender: TObject); procedure Zeichnen; procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure paintbox1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure punkte; procedure paintbox1Click(Sender: TObject); procedure munition; procedure MaximizeAndScale; procedure Timer2Timer(Sender: TObject); procedure Timer3Timer(Sender: TObject); procedure FormActivate(Sender: TObject); private
public end; const crMyCursor =5; var key:word; Form1: TForm1; Hg:TBitmap; schwarz:tbitmap; rosa:tbitmap; gelb:tbitmap; rot:tbitmap; blau:tbitmap; lila:tbitmap; gruen:TBitmap; Puffer:TBitmap; xgruen,ygruen,xblau,yblau,xrot,yrot,ylila,xlila,xgelb,ygelb,yschwarz,xschwarz, yrosa,xrosa, x,y:integer; gruenSichtbar: Boolean = true; schwarzsichtbar:boolean=true; rosasichtbar:boolean=true; i:integer; muni:integer; anz:integer; blausichtbar:boolean=true; rotsichtbar:boolean=true; lilasichtbar:boolean=true; gelbsichtbar:boolean=true; CountDown : double; Time : TTime; implementation
{$R *.dfm} procedure TForm1.FormActivate(Sender: TObject); begin Cursor := crMyCursor; Screen.Cursors[crMyCursor] := LoadCursor(HInstance, 'MYCURSOR'); CountDown := StrToTime('00:00:10'); label3.Caption:='00:10'; end;
procedure tform1.munition; begin
anz:=anz-1;
Image1.Visible := anz >= 5; Image2.Visible := anz >= 4; Image3.Visible := anz >= 3; Image4.Visible := anz >= 2; Image5.Visible := anz >= 1;
end;
procedure tform1.paintbox1Click(Sender: TObject); begin munition ; end;
procedure TForm1.FormCreate(Sender: TObject); begin randomize; xgruen:=paintbox1.width; ygruen:=0; xschwarz:=0; yschwarz:=200; xrosa:=0; yrosa:=0; xgelb:=paintbox1.width; ygelb:=100; yrot:=50; xrot:=0; yblau:=400; xblau:=0; xlila:=0; ylila:=paintbox1.Height-200; gelb:=tbitmap.create; rosa:=tbitmap.create; schwarz:=TBitmap.Create; gruen:=TBitmap.Create; lila:=tbitmap.create; rot:=tbitmap.create; Hg:=TBitmap.Create; blau:=tbitmap.create; gelb.LoadFromFile('gelb.bmp'); lila.LoadFromFile('lila.bmp'); rosa.LoadFromFile('rosa.bmp'); schwarz.LoadFromFile('schwarz.bmp'); rot.loadfromfile('rot.bmp'); blau.loadfromfile('hellblau.bmp'); Hg.LoadFromFile('Hg.bmp'); gruen.LoadFromFile('grün.bmp'); gelb.width:=84; gelb.Height:=84; lila.Width:=200; lila.height:=200; rosa.width:=50; rosa.Height:=50; schwarz.Width:=100; schwarz.height:=100; rot.Width:=48; rot.height:=50; blau.Width:=100; blau.Height:=100; gruen.Width:=100; gruen.Height:=100; rosa.Transparent:=true; schwarz.Transparent:=true; lila.Transparent:=true; gelb.Transparent:=true; gruen.Transparent:=true; blau.Transparent:=true; rot.Transparent:=true; Puffer:=TBitmap.Create; Puffer.Width:=paintbox1.width; Puffer.height:=paintbox1.Height; hg.width:=paintbox1.width; hg.Height:=paintbox1.Height; punkte; anz:=5 ; end;
procedure TForm1.Zeichnen; begin
Puffer.Canvas.Draw(0,0,Hg); if not rosasichtbar and (Random(100) >= 10) then begin rosasichtbar := True; Puffer.Canvas.Draw(xrosa, yrosa, rosa); end; PaintBox1.Canvas.Draw(0,0,Puffer); end;
procedure TForm1.MaximizeAndScale; var sWidth: Double; sHeight: Double; begin sWidth := Screen.MonitorFromWindow(Handle).Width / Width; sHeight := Screen.MonitorFromWindow(Handle).Height / Height; if sWidth < sHeight then begin ScaleBy(Round(Screen.MonitorFromWindow(Handle).Width * 1.02), Width); end else begin ScaleBy(Round(Screen.MonitorFromWindow(Handle).Height * 1.02), Height); end; WindowState := wsMaximized; end;
procedure tform1.punkte; begin if gelbsichtbar= false then label1.caption:=inttostr(i); if lilasichtbar= false then label1.caption:=inttostr(i); if gruenSichtbar= false then label1.caption:=inttostr(i); if blausichtbar=false then label1.caption:=inttostr(i); if rotsichtbar =false then label1.caption:=inttostr(i); if rosasichtbar=false then label1.caption:=inttostr(i); if schwarzsichtbar =false then label1.caption:=inttostr(i); end;
procedure TForm1.Timer1Timer(Sender: TObject); begin punkte; xgruen:=xgruen-5; xblau:=xblau+10; xrosa:=xrosa+5; xschwarz:=xschwarz+8; xrot:=xrot+3; xlila:=xlila+15; xgelb:=xgelb-10; Zeichnen; end ;
procedure TForm1.paintbox1Paint(Sender: TObject); begin Zeichnen; end;
procedure TForm1.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin Zeichnen; end;
procedure TForm1.paintbox1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin if anz<=0 then if Button = mbRight then begin Image1.Visible := true; Image2.Visible :=true; Image3.Visible := true ; Image4.Visible := true; Image5.Visible:=true; anz:=5; end; if anz>0 then if button=mbleft then if (X >= xblau) and (X <= xblau + blau.Width) and (Y >= yblau) and (Y <= yblau + blau.Height) then begin blausichtbar := false; i:=i+10 ; CountDown := CountDown + (1 / 86400)*5; end; if anz>0 then if button=mbleft then if (X >= xgelb) and (X <= xgelb + gelb.Width) and (Y >= ygelb) and (Y <= ygelb + gelb.Height) then begin gelbsichtbar := false; i:=i+10 ; CountDown := CountDown + (1 / 86400)*5; end;
if anz>0 then if button=mbleft then if (X >= xgruen) and (X <= xgruen + gruen.Width) and (Y >= ygruen) and (Y <= ygruen + gruen.Height) then begin gruensichtbar := false; i:=i+10 ; CountDown := CountDown + (1 / 86400)*5; end; if anz>0 then if button=mbleft then if (X >= xrot) and (X <= xrot + rot.Width) and (Y >= yrot) and (Y <= yrot + rot.Height) then begin rotsichtbar := false; i:=i+100 ; CountDown := CountDown + (1 / 86400)*5; 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 ; CountDown := CountDown + (1 / 86400)*6;
end; if anz>0 then if button=mbleft then if (X >= xschwarz) and (X <= xschwarz + schwarz.Width) and (Y >= yschwarz) and (Y <= yschwarz + schwarz.Height) then begin schwarzsichtbar := false; i:=i+100 ; CountDown := CountDown + (1 / 86400)*5; end; if anz>0 then if button=mbleft then if (X >= xrosa) and (X <= xrosa + rosa.Width) and (Y >= yrosa) and (Y <= yrosa + rosa.Height) then begin rosasichtbar := false; i:=i+50 ; CountDown := CountDown + (1 / 86400)*6;
end; end;
procedure TForm1.Timer2Timer(Sender: TObject); begin Zeichnen; end;
procedure TForm1.Timer3Timer(Sender: TObject); begin countDown := CountDown - (1 / 86400);
if CountDown <= 0 then begin Timer3.Enabled := False; ShowMessage('Game Over'); end else Label3.Caption := FormatDateTime('nn:ss', CountDown); end;
end. |
|
|
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1
|
Verfasst: Fr 06.02.09 20:31
Glaubst Du im Ernst, dass sich jemand die Mühe macht, bei dieser Menge von gruselig formatiertem Code die dahinterstehende Logik verstehen zu wollen? Ich will Dich ja nicht niedermachen, aber ich empfinde das als Zumutung, tut mir leid.
|
|
jaenicke
      
Beiträge: 19346
Erhaltene Danke: 1754
W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
|
Verfasst: Fr 06.02.09 22:14
Poste bitte das gesamte Projekt als Anhang, normalerweise könnte ich ja einen Quelltext auch schnell überblicken, und DeddyH sicher auch, aber bei der Formatierung (kann man ja gar nicht so nennen  ) und dazu tausend lokalen Variablen ist das so unübersichtlich, dass ich es höchstens mal ausprobieren kann.
|
|
Webo
      
Beiträge: 577
Erhaltene Danke: 14
Win 7, Debian
C# (Visual Studio 2013), PHP, C, C++ (Eclipse, KDevelop)
|
Verfasst: Sa 07.02.09 08:53
Zum Thema Quellcode: Lies dir mal folgende Anleitung durch www.delphi-treff.de/delphi-styleguide/ . Als ich das erste mal Quellcode von mir anderen gegeben hatte, haben dir mir das sofort aufgezwungen, weil meine Formatierung am Anfang auch .. ähm, durcheinander war.
Wende mal die genannten Tipps auf deinen Quellcode an und du wirst sehen, es ist gleich viel mehr Übersichtlichkeit mit drin. Dann entstehen auch solche Fehler mit begin und end nicht.
_________________ Man kann nur das aus dem Ärmel schütteln, was man auch vorher reingesteckt hat.
|
|
ultraz06 
      
Beiträge: 84
|
Verfasst: Sa 07.02.09 14:16
musste das hintergrundbild verkleinern da sonst die uploadgröße von 2 mb überschritten worden wäre
Einloggen, um Attachments anzusehen!
|
|
jaenicke
      
Beiträge: 19346
Erhaltene Danke: 1754
W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
|
Verfasst: Sa 07.02.09 14:47
Du rufst zeichnen ja ständig wieder neu auf. Und deshalb überschreibst du dann sofort den Ballon wieder, denn gezeichnet wird er so zwar nicht immer, aber nur in dem Moment, wenn du ihn sichtbar machst, danach nicht mehr. Wie wäre es so: Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9:
| procedure TForm1.Zeichnen; begin Puffer.Canvas.Draw(0,0,Hg); if not rosasichtbar and (Random(100) >= 10) then rosasichtbar := True; if rosasichtbar then Puffer.Canvas.Draw(xrosa, yrosa, rosa); PaintBox1.Canvas.Draw(0,0,Puffer); end; |
Dann benutzt du relative Verzeichnisse ( gelb.LoadFromFile('gelb.bmp');), das ist falsch:
www.delphi-library.d...ewtopic.php?p=499701
Bei mir geht das Fenster nur über einen Teil des Bildschirms, und das ohne Rand, das sieht nicht gut aus. Außerdem sehe ich keine Möglichkeit zum Beenden.
Den Quelltext könnte man locker halb so lang schreiben um das selbe zu machen. Du wiederholst ja Teile des Quelltextes für jeden Ballon einzeln... (aber das ist ja vor allem Mehrarbeit für dich^^)
|
|
ultraz06 
      
Beiträge: 84
|
Verfasst: Sa 07.02.09 15:22
joa stimmt^^
aber wie kann ich nun jeden ballon über die 2 mins unterschiedlich erscheinen lassen
alles nach dem muster von rosa?
|
|
|