AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Projekte Ping Pong mit Hindernissen - FUNKTIONIERT NICHT!
Thema durchsuchen
Ansicht
Themen-Optionen

Ping Pong mit Hindernissen - FUNKTIONIERT NICHT!

Ein Thema von ChrisDOOF · begonnen am 27. Okt 2008 · letzter Beitrag vom 28. Okt 2008
Antwort Antwort
ChrisDOOF
Registriert seit: 27. Okt 2008
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:

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.
Vielen Dank!
 
Teekeks

 
FreePascal / Lazarus
 
#2
  Alt 28. Okt 2008, 15:08
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!
Peter
  Mit Zitat antworten Zitat
angos

 
Delphi 11 Alexandria
 
#3
  Alt 28. Okt 2008, 15:20
Zitat von Teekeks:
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!
wer oder was ist mSuM, und muss ich Angst davor haben?
Nein, mal im Ernst. Was ist "mSuM"
Ansgar
  Mit Zitat antworten Zitat
Benutzerbild von BUG
BUG
 
#4
  Alt 28. Okt 2008, 15:29
Zitat von angos:
Nein, mal im Ernst. Was ist "mSuM"
Das hier:
Zitat von HamLet:
Also, wir lernen Delphi mit ner Lernreihe, die sich "Delphi Netto" nennt. Diese Reihe basiert auf mSum, einer großen Unit, die englische Befehle auf Deutsch übersetzt und wir quasi damit programmieren lernen. Ich würd das auch lieber auf Englisch machen, aber naja, Schule halt... Unser Lehrer sagt immer, dass wir mit mSum nur die Struktur verstehen lernen müssen, denn eigentlich sind ja alle Programmiersprachen gleich...
MfG,
Bug
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:18 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz