/*
 * TelaJogo.java
 *
 * Created on 27 de Janeiro de 2006, 14:54
 */

package exemplodethreads;

/**
 *
 * @author  Alexandre
 */
import java.awt.*;

public class TelaJogo extends javax.swing.JFrame {
    
    protected int NumAster = 10;
    protected int X = 10, Y = 10;
    protected boolean Tiro = false;
    protected Asteroide aster[] = new Asteroide[ NumAster ];
    
    
    /** Creates new form TelaJogo */
    
    public TelaJogo() {
        initComponents();
        setSize( 400, 300 );
        
        for( int i = 0; i < 10; i ++ ) {
            aster[ i ] = new Asteroide(this.getSize().width, this.getSize().height);
            aster[ i ].start();
        }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                Tecla(evt);
            }
        });

        pack();
    }
    // </editor-fold>//GEN-END:initComponents
    
    private void Tecla(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_Tecla
        switch( evt.getKeyCode()) {
            case 38: // evt.VK_UP
            {
                Y = Y - 2;
                break;
            }
            case 40: // evt.VK_DOWN
            {
                Y = Y + 2;
                break;
            }
            case 37: // evt.VK_LEFT
            {
                X = X - 2;
                break;
            }
            case 39: // evt.VK_RIGHT
            {
                X = X + 2;
                break;
            }
            
        }
        
        repaint();
        
    }//GEN-LAST:event_Tecla
    
    public void update(Graphics g){
	paint(g);
   }

    public void paint( Graphics g ) {
        for( int i = 0; i < 10; i ++) {
            aster[ i ].MostraAsteroide( g );
        }
        
        g.drawRect( X, Y, 20, 20 );
        
        repaint();
    }
    
    /**
     * @param args the command line arguments
     */
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
    
}
