Guest User

Untitled

a guest
Jul 11th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.38 KB | None | 0 0
  1. void run() {
  2. while (this.neust){ //äußere Schleife (Stoppt nur bei exit)
  3. while (this.unendlich){ //innere Schleife (Stoppt wenn Ballkontakt == False
  4. for(int i=80;i<720;i++){ //Schleife um den Ball fon links nach rechts zu bewegen
  5. if (this.pause == true){ //Schleifenvariable i bleibt bei Pause konstant (Ball bleibt stehen)
  6. i = i-1;
  7.  
  8. }
  9. if (this.pause == false){ //wenn Pause nicht True ist, läuft die Schleife normal durch
  10. this.paused = "";
  11. if (this.ballkontakt == false){ //wenn Ballkontakt == true ist wird die innere Schleife gestoppt
  12. this.neustart = false;
  13. break;
  14. }
  15. if (this.x==80){ //Ball kommt links an
  16.  
  17.  
  18. this.linksYmax = linksY + 100; //Werte für den linken Spielerbalken werden aktualisiert
  19. this.linksYmin = linksY + 1; //Werte für den linken Spielerbalken werden aktualisiert
  20. this.counter = this.counter+1;
  21.  
  22.  
  23. if (this.counter == 2){ //Geschwindigkeitsanstieg nach entsprechenden Ballwechseln (nicht nach Zeit!)
  24. if (this.speed == 1){
  25. this.speed = this.speed+1;
  26. }
  27. this.speed = this.speed-1;
  28. this.counter = 1;
  29. }
  30.  
  31.  
  32. 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)
  33. this.ballkontakt = true;
  34. else //Wenn Ballkontakt == fale wird die Innere Schleife gestoppt
  35. this.ballkontakt = false;
  36. if (this.linksYmin < this.y & this.linksYmax > this.y){ //Position des Aufpralls auf den Spielerbalken wird bestimmt und demnach der Winkel des Balls bestimmt
  37.  
  38. //Desto weiter außen der ball auf dem Spielerbalken aufkommt, desto größer is der Flugwinkel
  39.  
  40. if (this.linksYmin < this.y & this.linksYmin+20 > this.y ){
  41. this.winkel = 0.6;
  42. }
  43. if (this.linksYmin+20 < this.y & this.linksYmin+43 > this.y ){
  44. this.winkel = 0.3;
  45. }
  46. if (this.linksYmin+43 < this.y & this.linksYmin+57 > this.y ){
  47. this.winkel = 0.0;
  48. }
  49. if (this.linksYmin+57 < this.y & this.linksYmin+80 > this.y ){
  50. this.winkel = 0.3;
  51. }
  52. if (this.linksYmin+80 < this.y & this.linksYmax > this.y ){
  53. this.winkel = 0.6;
  54. }
  55. }
  56.  
  57. }
  58. if (this.pause == false){
  59. if (this.y<=0){ //Wenn der Ball die obere Kante erreicht wird der Winkel negiert (ins negative umgekehrt)
  60. this.runter = true;
  61. }
  62. if (this.y>=490){//Wenn der Ball die untere Kante erreicht wird der Winkel negiert (ins positive umgekehrt)
  63. this.runter = false;
  64. }
  65. if (this.runter == true){
  66. this.y = this.y+this.winkel; //Ball wandern einen Punkt entsprechend des Winkels nach unten
  67. }
  68. if (this.runter == false){
  69. this.y = this.y-this.winkel; //Ball wandern einen Punkt entsprechend des Winkels nach unten
  70. }
  71.  
  72. this.x = this.x+1; //Ball wandert ein Punkt nach rechts
  73. }
  74. repaint();
  75. try {
  76. Thread.sleep(this.speed); //Nach dem Durchlauf Sleep um das ganze auf dem Bildschrim darzustellen
  77. }
  78. catch (InterruptedException e) { /** */ }
  79.  
  80.  
  81. if (this.x == 710){ //Ball nach rechts (ähnlich wie links)
  82. for(int q=80;q<710;q++){
  83. if (this.pause == true){ //Schleife wird "angehalten)
  84. q = q-1;
  85. }
  86. if (this.pause == false){ //wenn keine Pause
  87.  
  88. this.paused = "";
  89. //else { this.paused = "- Pause -";
  90. if (this.ballkontakt == false){ //Bei Ballokontakt == false wird innere Schleife angehalten
  91. this.neustart = false;
  92. this.punkteerhalt = true;
  93. break;
  94. }
  95. if (this.x==710){ //Ball kommt rechts an
  96.  
  97. //Winkel usw. wie bei Links
  98.  
  99. this.rechtsYmax = rechtsY+101;
  100. this.rechtsYmin = rechtsY-1;
  101. if (this.rechtsYmin < this.y & this.rechtsYmax > this.y)
  102. this.ballkontakt = true;
  103. else
  104. this.ballkontakt = false;
  105. //if (this.x==490) this.ba2 = false;
  106. if (this.rechtsYmin < this.y & this.rechtsYmax > this.y){
  107. if (this.rechtsYmin < this.y & this.rechtsYmin+22 > this.y ){
  108. this.winkel = 0.6;
  109. }
  110. if (this.rechtsYmin+22 < this.y & this.rechtsYmin+45 > this.y ){
  111. this.winkel = 0.3;
  112. }
  113. if (this.rechtsYmin+45 < this.y & this.rechtsYmin+55 > this.y ){
  114. this.winkel = 0.0;
  115. }
  116. if (this.rechtsYmin+55 < this.y & this.rechtsYmin+78 > this.y ){
  117. this.winkel = 0.3;
  118. }
  119. if (this.rechtsYmin+78 < this.y & this.rechtsYmax > this.y ){
  120. this.winkel = 0.6;
  121. }
  122. }
  123. }
  124.  
  125. if (this.pause == false){
  126. if (this.y<=0){
  127. this.runter = true;
  128. }
  129. if (this.y>=490){
  130. this.runter = false;
  131. }
  132.  
  133. if (this.runter == true){
  134. this.y = this.y+this.winkel;
  135. }
  136. if (this.runter == false){
  137. this.y = this.y-this.winkel;
  138. }
  139. this.x = this.x-1;
  140. }
  141. repaint();
  142. try {
  143. Thread.sleep(this.speed);
  144. }
  145. catch (InterruptedException e) { /** */ }
  146. }
  147. }
  148. }
  149. }
  150. }
  151. if (this.ballkontakt == false){
  152. this.unendlich = false;
  153. this.next = "Neustart mit 'N'";
  154. repaint();
  155. }
  156. }
  157. if (this.neustart==true){
  158. this.unendlich=true;
  159. this.ballkontakt = true;
  160. this.x=240;
  161. this.y=50;
  162. linksY=200;
  163. rechtsY=200;
  164. this.speed = 5;
  165. this.winkel = 0.7;
  166. this.runden = this.runden+1;
  167. this.next="";
  168.  
  169.  
  170.  
  171.  
  172. if (this.punkteerhalt==false){
  173. this.punkteB++;
  174. }
  175. if (this.punkteerhalt==true){
  176. this.punkteA++;
  177. }
  178. this.punkteerhalt = false;
  179. }
  180. }
  181. }
Add Comment
Please, Sign In to add comment