Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void run() {
- while (this.neust){ //äußere Schleife (Stoppt nur bei exit)
- while (this.unendlich){ //innere Schleife (Stoppt wenn Ballkontakt == False
- for(int i=80;i<720;i++){ //Schleife um den Ball fon links nach rechts zu bewegen
- if (this.pause == true){ //Schleifenvariable i bleibt bei Pause konstant (Ball bleibt stehen)
- i = i-1;
- }
- if (this.pause == false){ //wenn Pause nicht True ist, läuft die Schleife normal durch
- this.paused = "";
- if (this.ballkontakt == false){ //wenn Ballkontakt == true ist wird die innere Schleife gestoppt
- this.neustart = false;
- break;
- }
- if (this.x==80){ //Ball kommt links an
- this.linksYmax = linksY + 100; //Werte für den linken Spielerbalken werden aktualisiert
- this.linksYmin = linksY + 1; //Werte für den linken Spielerbalken werden aktualisiert
- this.counter = this.counter+1;
- if (this.counter == 2){ //Geschwindigkeitsanstieg nach entsprechenden Ballwechseln (nicht nach Zeit!)
- if (this.speed == 1){
- this.speed = this.speed+1;
- }
- this.speed = this.speed-1;
- this.counter = 1;
- }
- if (this.linksYmin < this.y & this.linksYmax > this.y) //wenn Ball zwischen dem Linken Minimum und Linken Maximum des Linken Spielerbalkens auftrifft ist Ballkontakt == true (Schläger getroffen)
- this.ballkontakt = true;
- else //Wenn Ballkontakt == fale wird die Innere Schleife gestoppt
- this.ballkontakt = false;
- if (this.linksYmin < this.y & this.linksYmax > this.y){ //Position des Aufpralls auf den Spielerbalken wird bestimmt und demnach der Winkel des Balls bestimmt
- //Desto weiter außen der ball auf dem Spielerbalken aufkommt, desto größer is der Flugwinkel
- if (this.linksYmin < this.y & this.linksYmin+20 > this.y ){
- this.winkel = 0.6;
- }
- if (this.linksYmin+20 < this.y & this.linksYmin+43 > this.y ){
- this.winkel = 0.3;
- }
- if (this.linksYmin+43 < this.y & this.linksYmin+57 > this.y ){
- this.winkel = 0.0;
- }
- if (this.linksYmin+57 < this.y & this.linksYmin+80 > this.y ){
- this.winkel = 0.3;
- }
- if (this.linksYmin+80 < this.y & this.linksYmax > this.y ){
- this.winkel = 0.6;
- }
- }
- }
- if (this.pause == false){
- if (this.y<=0){ //Wenn der Ball die obere Kante erreicht wird der Winkel negiert (ins negative umgekehrt)
- this.runter = true;
- }
- if (this.y>=490){//Wenn der Ball die untere Kante erreicht wird der Winkel negiert (ins positive umgekehrt)
- this.runter = false;
- }
- if (this.runter == true){
- this.y = this.y+this.winkel; //Ball wandern einen Punkt entsprechend des Winkels nach unten
- }
- if (this.runter == false){
- this.y = this.y-this.winkel; //Ball wandern einen Punkt entsprechend des Winkels nach unten
- }
- this.x = this.x+1; //Ball wandert ein Punkt nach rechts
- }
- repaint();
- try {
- Thread.sleep(this.speed); //Nach dem Durchlauf Sleep um das ganze auf dem Bildschrim darzustellen
- }
- catch (InterruptedException e) { /** */ }
- if (this.x == 710){ //Ball nach rechts (ähnlich wie links)
- for(int q=80;q<710;q++){
- if (this.pause == true){ //Schleife wird "angehalten)
- q = q-1;
- }
- if (this.pause == false){ //wenn keine Pause
- this.paused = "";
- //else { this.paused = "- Pause -";
- if (this.ballkontakt == false){ //Bei Ballokontakt == false wird innere Schleife angehalten
- this.neustart = false;
- this.punkteerhalt = true;
- break;
- }
- if (this.x==710){ //Ball kommt rechts an
- //Winkel usw. wie bei Links
- this.rechtsYmax = rechtsY+101;
- this.rechtsYmin = rechtsY-1;
- if (this.rechtsYmin < this.y & this.rechtsYmax > this.y)
- this.ballkontakt = true;
- else
- this.ballkontakt = false;
- //if (this.x==490) this.ba2 = false;
- if (this.rechtsYmin < this.y & this.rechtsYmax > this.y){
- if (this.rechtsYmin < this.y & this.rechtsYmin+22 > this.y ){
- this.winkel = 0.6;
- }
- if (this.rechtsYmin+22 < this.y & this.rechtsYmin+45 > this.y ){
- this.winkel = 0.3;
- }
- if (this.rechtsYmin+45 < this.y & this.rechtsYmin+55 > this.y ){
- this.winkel = 0.0;
- }
- if (this.rechtsYmin+55 < this.y & this.rechtsYmin+78 > this.y ){
- this.winkel = 0.3;
- }
- if (this.rechtsYmin+78 < this.y & this.rechtsYmax > this.y ){
- this.winkel = 0.6;
- }
- }
- }
- if (this.pause == false){
- if (this.y<=0){
- this.runter = true;
- }
- if (this.y>=490){
- this.runter = false;
- }
- if (this.runter == true){
- this.y = this.y+this.winkel;
- }
- if (this.runter == false){
- this.y = this.y-this.winkel;
- }
- this.x = this.x-1;
- }
- repaint();
- try {
- Thread.sleep(this.speed);
- }
- catch (InterruptedException e) { /** */ }
- }
- }
- }
- }
- }
- if (this.ballkontakt == false){
- this.unendlich = false;
- this.next = "Neustart mit 'N'";
- repaint();
- }
- }
- if (this.neustart==true){
- this.unendlich=true;
- this.ballkontakt = true;
- this.x=240;
- this.y=50;
- linksY=200;
- rechtsY=200;
- this.speed = 5;
- this.winkel = 0.7;
- this.runden = this.runden+1;
- this.next="";
- if (this.punkteerhalt==false){
- this.punkteB++;
- }
- if (this.punkteerhalt==true){
- this.punkteA++;
- }
- this.punkteerhalt = false;
- }
- }
- }
Add Comment
Please, Sign In to add comment