Pong-Code erklären

Status
Nicht offen für weitere Antworten.
Hab ein kleines Pong Programm programmiert, funktioniert so naja :)
Ich muss das Programm morgen vorstellen bzw ein kleinen Ausschnitt!!
Habt ihr eine Idee welchen TEILCode ich erklären sollte?
Welcher sehr wichtig erscheint & könnnt ihr mir posten was der Code bringt bzw wie ihr das erklären würdet;).. Nehme bissel professionelle, als eine schlechte Note zu kassieren :)!!!

Java:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
 
public class PongBkai2010 extends javax.swing.JFrame {
    
	private Graphics grp = null;
	private boolean running = true;
	private Thread hrt = null;
	private Image bfoto  = null;
	private Graphics2D abbildung = null;



    private Kugel kug = null;
    
    int x = 0;
    int y = 0;

    public PongBkai2010() {
        initComponents();
        initGame();
    }
    
    public void initGame(){if (!running){
        while(true) {
            try{
                Thread.currentThread().sleep(100);
            }catch(InterruptedException ie){
        
            }
        }
    }
    
    grp = jPanel1.getGraphics();
    bfoto = createImage(480,400);
    abbildung = (Graphics2D)bfoto.getGraphics();
    kug = new Kugel(150,150, 1, 1);
    hrt  = new Thread(new Game());
    hrt.start();
    }
    
 
    private void initComponents() {
        jPanel1 = new javax.swing.JPanel();
 
        setTitle("BKAI-2 Pong v0.6 Beta");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });
 
  
        jPanel1.setPreferredSize(new java.awt.Dimension(480, 400));
        jPanel1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanel1MouseClicked(evt);
            }
        });
        jPanel1.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                jPanel1MouseMoved(evt);
            }
        });
 
        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
 
        pack();
    }
    
    private void jPanel1MouseMoved(java.awt.event.MouseEvent evt) {
        
        y = evt.getY();
        
    }
    
    private void jPanel1MouseClicked(java.awt.event.MouseEvent evt) {
        
        running = running ^ true;
    }
    
    private void exitForm(java.awt.event.WindowEvent evt) {
        System.exit(0);
    }
    
 
    public static void main(String args[]) {
        new PongBkai2010().show();
    }
    
    private void tobfoto(){
        grp.drawImage(bfoto,0,0,480,400,this);
    }
    
    private void drawKugel(){
        
        kug.koordinate.x += 2 * kug.xflugrichtung;
        kug.koordinate.y += 2 * kug.yflugrichtung;
        
        if (( ( kug.koordinate.x >= 430 ) || ( kug.koordinate.x <= 450 ) ) &&  ( Math.abs(y - kug.koordinate.y ) < 26 )){ //Treffer!
            
            if( kug.koordinate.x + 5 > 430 )
                kug.xflugrichtung *= -1;
        }
        
        if (kug.koordinate.x + 5 < 23)
            kug.xflugrichtung *= -1;
        
        if( kug.koordinate.y + 4 > 400 )
            kug.yflugrichtung *= -1;
        else if (kug.koordinate.y + 4 < 14)
            kug.yflugrichtung *= -1;
	
	
        
        //kugelaussehen

	abbildung.setBackground(Color.black);
	abbildung.setColor (Color.green);
        abbildung.fillOval(kug.koordinate.x - 4, kug.koordinate.y - 4, 9,9);
        
    }
    
    private void drawPlayer(){
        abbildung.fillRect( 420 , ( ( y < 400 ) && (y > 10) ) ? y : (y == 358) ? 420 : 9,  12, 25);
    }
    
    private void drawComputer(){
        abbildung.fillRect(10, kug.koordinate.y - 9 , 12,25);
    }
    
class Game implements Runnable{
        
        public void run(){
            
            while(true){ 
                
                if (!running){
                    while(!running) {
                        try{
                            Thread.currentThread().sleep(100);
                        }catch(InterruptedException ie){
                    
                        }
                    }
                } else {
                    
                    while(running){
                        
                       abbildung.clearRect(0,0,480,400);
                        
                        
                        drawPlayer();
                        
                        drawKugel();
                        
                        drawComputer();
		
                        
                        tobfoto();
                        
                        try{
                            Thread.currentThread().sleep(10);
                        }catch(InterruptedException ie){
                            
                       
			}
                    }
                }
            }
        }
        
    }
    
    class Kugel{
        
        public Point koordinate = null;
        public int xflugrichtung = 0; 
        public int yflugrichtung = 0; 
        
        public Kugel(int x, int y, int xr, int yr){
            koordinate = new Point(x,y);
            xflugrichtung = xr;
            yflugrichtung = yr;
            
        }
        
    }
    
    
    private javax.swing.JPanel jPanel1;
    
}
 
Zuletzt bearbeitet von einem Moderator:

Quaxli

Top Contributor
Dir ist schon klar, daß das klingt wie: "Ich hab einen Pong-Code im Netz gefunden und gebe den jetzt als mein eigenes Programm aus"? :autsch:
 
Ne nicht ganz richtig...
möchte nur ne Hilfe haben, welchen Teilcode ihr erklären würdet und wie?
halt z.B. die größe Paddles oder die Bewegung des Computers... und wie?
Ich möchte nur das mir geholfen wird und keine lange Diskussion führen thx :)
 
wo ist das problem -.-?
b2t pls :(
Biete auch GGL z.B. Steamaccount Cs 1.6
- Rapidshare o. Uploaded 1monat
oder 10€ Paysafecard
 
Zuletzt bearbeitet:
Status
Nicht offen für weitere Antworten.

Neue Themen


Oben