![]() |
Ping Pong mit Hindernissen - FUNKTIONIERT NICHT!
Hey.
Müssen in der Schule ein Projekt machen und ich habe nicht so die Ahnung von Delphi :) Könnte mir deshalb bitte jemand helfen?? Hier mein bisheriger Quellcode. Es funktioniert alles so weit, jedoch prallt der Ball nicht an den Hindernissen ab.
Delphi-Quellcode:
unit U_PingPong;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, jpeg, ExtCtrls, mSpielfeld, mBall, mbalken, mhindernis, msum; type TFPingPong = class(TForm) Image1: TImage; BStart: TButton; BQuit: TButton; RadioButton1: TRadioButton; RadioButton2: TRadioButton; RadioButton3: TRadioButton; procedure BStartClick(Sender: TObject); procedure Formdestroy(Sender: TObject); procedure RadioButton1Click(Sender: TObject); procedure RadioButton2Click(Sender: TObject); procedure RadioButton3Click(Sender: TObject); procedure BQuitClick(Sender: TObject); private mBildschirm:bildschirm; mball:ball; mbalken:balken; mhindernis:hindernis; h:integer; w:zahl; { Private declarations } public { Public declarations } end; var FPingPong: TFPingPong; implementation {$R *.dfm} procedure TFPingPong.BStartClick(Sender: TObject); begin mbildschirm:=bildschirm.init; mbalken:=balken.init; mBall:=ball.init; mhindernis:=hindernis.init; h:=0; repeat begin warte(w); mball.bewege; mbalken.bewege; end; until (mball.gibx > 1001); h:=mball.gibpunkte; showmessage('deine punkte:' + inttostr(h)); mBildschirm.gibfrei; end; procedure TFPingPong.Formdestroy(Sender: TObject); begin application.Terminate; end; procedure TFPingPong.RadioButton1Click(Sender: TObject); begin w:=2; end; procedure TFPingPong.RadioButton2Click(Sender: TObject); begin w:=1.5; end; procedure TFPingPong.RadioButton3Click(Sender: TObject); begin w:=1; end; procedure TFPingPong.BQuitClick(Sender: TObject); begin FPingPong.close; end; end.
Delphi-Quellcode:
unit mHindernis;
interface uses msum; type Hindernis = class private derStift:Buntstift; a,b:integer; protected public constructor init; procedure zeichne; //procedure loeschen; function gibhgrenze1:zahl; function gibvgrenze1:zahl; function gibhgrenze2:zahl; function gibvgrenze2:zahl; function getroffen:boolean; // destructor gibfrei; published end; implementation constructor hindernis.init; begin randomize; a:=random(900); b:=random(610) ; derstift:=buntstift.init; self.zeichne; end; procedure hindernis.zeichne; begin derstift.bewegebis(a,b) ; derstift.zeichnerechteck(100,100) ; end; function hindernis.gibhgrenze1:zahl; begin result:=b; end; function hindernis.gibvgrenze1:zahl; begin result:=a; end; function hindernis.gibhgrenze2:zahl; begin result:=b+100; end; function hindernis.gibvgrenze2:zahl; begin result:=a+100; end; function hindernis.getroffen:boolean; begin result:=(b<=derstift.hposition)and(b>=derstift.hposition-100) and(a<=derstift.vposition)and(a>=derstift.vposition-100) end; end.
Delphi-Quellcode:
unit mBall;
interface uses mSuM, mSpielfeld, mbalken, mhindernis; type Ball = class private hatStift:Buntstift; ersteshindernis:hindernis; meinbalken:balken; g:integer; protected public constructor init; procedure zeichne; procedure loeschen; procedure bewege; function gibrichtung:zahl; function gibx:zahl; function gibpunkte:integer; destructor gibfrei; published end; implementation constructor Ball.init; begin randomize; g:=0; meinbalken:=balken.init; ersteshindernis:=hindernis.init; hatStift:=Buntstift.init; hatstift.bewegeBis(510,370); hatstift.drehebis(random(360)); end; procedure Ball.zeichne; begin hatStift.setzeFuellMuster(Gefuellt); hatStift.zeichneKreis(8); end; procedure Ball.loeschen; begin hatstift.radiere; hatStift.setzeFuellMuster(Gefuellt); hatStift.bewegeBis(hatStift.hPosition,hatStift.vPosition); hatStift.zeichneKreis(8); hatStift.normal; end; procedure Ball.bewege; begin self.loeschen; hatStift.bewegeUm(1) ; if (hatStift.hPosition >1000) and (hatstift.vPosition > meinbalken.yposition) and (hatstift.vPosition < meinbalken.yposition+60) then begin g:=g+1 ; hatstift.dreheBis(540-self.gibrichtung) ; end; if hatstift.hPosition < 0 then hatstift.drehebis(540-self.gibrichtung); if hatstift.vposition > 710 then hatstift.drehebis(360-self.gibrichtung) ; if hatstift.vposition < 10 then hatstift.drehebis(360-self.gibrichtung); //hindernisse if (hatstift.hPosition = ersteshindernis.gibhgrenze1) and (hatstift.vposition > ersteshindernis.gibvgrenze1) and (hatstift.vposition < ersteshindernis.gibvgrenze2) then hatstift.drehebis(360-self.gibrichtung); if (hatstift.hPosition = ersteshindernis.gibhgrenze2) and (hatstift.vposition > ersteshindernis.gibvgrenze1) and (hatstift.vposition < ersteshindernis.gibvgrenze2) then hatstift.drehebis(360-self.gibrichtung); if (hatstift.vPosition = ersteshindernis.gibvgrenze1) and (hatstift.hposition > ersteshindernis.gibhgrenze1) and (hatstift.hposition < ersteshindernis.gibhgrenze2) then hatstift.drehebis(540-self.gibrichtung); if (hatstift.vPosition = ersteshindernis.gibvgrenze2) and (hatstift.hposition > ersteshindernis.gibvgrenze1) and (hatstift.hposition < ersteshindernis.gibvgrenze2) then hatstift.drehebis(540-self.gibrichtung); self.zeichne; end; function ball.gibrichtung:zahl; begin result:=hatstift.winkel; end; function ball.gibx:zahl; begin result:=hatstift.hposition; end; function ball.gibpunkte:integer; begin result:=g; end; destructor ball.gibfrei; begin self.loeschen; hatstift.gibfrei; meinbalken.gibfrei; end; end.
Delphi-Quellcode:
Vielen Dank!unit mSpielfeld; interface uses mSuM; type Spielfeld = class private hatStift:Buntstift; meinBildschirm:Bildschirm; protected public constructor init; procedure zeichne; procedure loeschen; destructor gibfrei; published end; implementation constructor Spielfeld.init; begin meinBildschirm:=Bildschirm.init; hatStift:= buntstift.init; hatstift.bewegeBis(10,70); self.zeichne; end; procedure Spielfeld.zeichne; begin hatstift.zeichneRechteck(500,700); end; procedure Spielfeld.loeschen; begin hatStift.radiere; self.zeichne; hatStift.normal; end; destructor Spielfeld.gibfrei; begin self.loeschen; hatstift.gibFrei; meinBildschirm.gibFrei; end; end. |
Re: Ping Pong mit Hindernissen - FUNKTIONIERT NICHT!
Ohje, das siet irgentwie aus wie mSuM... ich glaube nicht das dir da hier irgendjemand wirklich helfen kann....
Das sollte man aber dazu sagen das das mSuM ist! |
Re: Ping Pong mit Hindernissen - FUNKTIONIERT NICHT!
Zitat:
Nein, mal im Ernst. Was ist "mSuM" |
Re: Ping Pong mit Hindernissen - FUNKTIONIERT NICHT!
Zitat:
Zitat:
Bug |
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:57 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-2025 by Thomas Breitkreuz