Main.java

Categorías: CategoryJava | CategoryProgramacion

   1 /**
   2  *@author Elkin Andrey Garzón Alarcón...Geek Master
   3  *@author Ingrid Lorena Guerrero Mayorga...
   4  *@author Jefferson Fabian Idarraga Idarraga Pinilla...
   5  */
   6 package pinguinogg;
   7 
   8 import java.awt.FlowLayout;
   9 import java.awt.Frame;
  10 import java.awt.Label;
  11 import java.io.BufferedReader;
  12 import java.io.FileInputStream;
  13 import java.io.FileNotFoundException;
  14 import java.io.IOException;
  15 import java.io.InputStream;
  16 import java.io.InputStreamReader;
  17 import java.io.ObjectInputStream;
  18 import java.util.TreeMap;
  19 import java.util.logging.Level;
  20 import java.util.logging.Logger;
  21 import javax.swing.JButton;
  22 import javax.swing.JOptionPane;
  23 import pinguinogg.EscuchaVentana;
  24 import pinguinogg.Formulario;
  25 import pinguinogg.PuntajeVidas;
  26 import sun.audio.AudioPlayer;
  27 import sun.audio.AudioStream;
  28 
  29 //public
  30 public class Main {
  31 
  32     private static Ladrillo[][] ladrillos;
  33     private static Cabeza[][] cabeza;
  34     private static PuntajeVidas[][] puntajeVidaseses;
  35 
  36 //    private static Cañon cañon;
  37     //  private static Bala bala;
  38     public static void main(String[] args) throws FileNotFoundException, IOException {
  39         TreeMap<Integer, PuntajeVidas> listaPuntajes = new TreeMap<Integer, PuntajeVidas>();
  40         try {
  41             ObjectInputStream archivo = new ObjectInputStream(new FileInputStream("PinguinoGG.dat"));
  42             listaPuntajes = (TreeMap<Integer, PuntajeVidas>) archivo.readObject();
  43             archivo.close();
  44 
  45         } catch (ClassNotFoundException ex) {
  46             Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
  47         } catch (FileNotFoundException e) {
  48             listaPuntajes = new TreeMap<Integer, PuntajeVidas>();
  49         } catch (IOException e) {
  50             System.err.println("Error al leer archivo");
  51         }
  52         /**
  53          *Se introduce el sonido de fondo
  54          *
  55          */
  56         InputStream in = new FileInputStream("fondo.mid");
  57         AudioStream as = new AudioStream(in);
  58         AudioPlayer.player.start(as);
  59 
  60 
  61 
  62         /**
  63          * se agrega la ventana del formulario
  64          */
  65         Lienzo lienzo = new Lienzo();
  66         PuntajeVidas puntaje = new PuntajeVidas(50, 50, 50, 50, "Nombre");
  67         Cronometro cronometro = new Cronometro(0, 0, 180, 75, lienzo, new EscuchaVentana(listaPuntajes, puntaje), listaPuntajes, puntaje);
  68 
  69         /**
  70          * MUESTRA LA VENTANA PARA QUE EL JUGADOR DIGITE SU NOMBRE,
  71          * ADEMAS AGRAGA EL NOMBRE CON SU RESPECTIVO PUNTAJE
  72          */
  73 
  74         String nombreJugador = JOptionPane.showInputDialog("Digite su nombre");
  75         PuntajeVidas puntaje2 = new PuntajeVidas(0, 0, 500, 50, nombreJugador);
  76         lienzo.add(puntaje);
  77         
  78         /*
  79          * se agrega el cornometro
  80          */
  81         Thread hiloCronometro = new Thread(cronometro);
  82         Configuracion configuracion = new Configuracion();
  83         Formulario formulario1 = new Formulario(configuracion, cronometro);
  84         formulario1.setVisible(true);
  85 
  86 
  87 
  88         //HAY ESTA LO DEL PROFE
  89         /**
  90          * sacar la ventana de pedir usuario
  91          */
  92         Frame marco = new Frame("pinguinogg");
  93         Cañon cañon;
  94         cañon = new Cañon(100, 600, 100, 140);
  95         marco.setSize(1035, 800);
  96 
  97         marco.add(lienzo);
  98 
  99 
 100         //HAY ESTA BN
 101         BufferedReader lector = new BufferedReader(new InputStreamReader(System.in));
 102         /**
 103          * PINTA LOS LADRILLOS
 104          *
 105          */
 106         ladrillos = new Ladrillo[7][7];
 107         for (int i = 0; i < ladrillos.length; i++) {
 108             for (int j = 0; j < ladrillos[i].length; j++) {
 109                 ladrillos[i][j] = new Ladrillo(i * 200, j * 100, 200, 100);
 110                 lienzo.add(ladrillos[i][j]);
 111             }
 112 
 113         }
 114         /**
 115          * MUESTRA EL PUNTAJE
 116          *
 117          */
 118         Frame marcoPuntajes = new Frame("puntaje");
 119         marcoPuntajes.setVisible(true);
 120         marcoPuntajes.setSize(200, 500);
 121         marcoPuntajes.setLayout(new FlowLayout());
 122         marcoPuntajes.repaint();
 123 
 124        
 125 
 126         /**
 127          * BOTON PARA SALIR DEL PUNTAJE
 128          *
 129          */
 130         JButton salir = new JButton("Salir");
 131         salir.addActionListener(new EscuchaBotonCerrar(marcoPuntajes));
 132         marcoPuntajes.add(salir);
 133 
 134         /**
 135          * MUESTRA QUE SI SE ESTA "PINTANDO" EL PUNTAJE EN EL LIENZO Y
 136          *Q LO AGREGA A LA LISTA
 137          */
 138         System.out.println("------------ Puntajes -----------");
 139         for (PuntajeVidas p : listaPuntajes.values()) {
 140             marcoPuntajes.add(new Label(p + " "));
 141 
 142             //System.err.print(""+p);
 143 
 144         }
 145         /*
 146          * AGREGA LAS CABEZAS AL LIENZO
 147          */
 148 
 149         cabeza = new Cabeza[10][1];
 150         for (int i = 0; i < cabeza.length; i++) {
 151             for (int j = 0; j < cabeza[i].length; j++) {
 152                 cabeza[i][j] = new Cabeza(i * 100, j * 100, 100, 100, lienzo, puntaje);
 153                 lienzo.add(cabeza[i][j]);
 154                 Thread hiloCabeza = new Thread(cabeza[i][j]);
 155                 hiloCabeza.start();
 156             }
 157 
 158         }
 159 
 160         /*
 161          * AGREGA EL CAÑON Y LOS BLOQUES
 162          */
 163         lienzo.add(cañon);
 164         Bloque[] bloques = {
 165             new Bloque(-20, 700, 20, 20),
 166             new Bloque(1035, 700, 20, 20)
 167         };
 168         for (int i = 0; i < bloques.length; i++) {
 169             lienzo.add(bloques[i]);
 170         }
 171         /*
 172          *AGREGA LOS EVENTOS
 173          */
 174         marco.addWindowListener(new EscuchaVentana(listaPuntajes, puntaje));
 175 
 176         marco.addKeyListener(new Escuchateclas(cañon, lienzo, bloques, cabeza, puntaje));
 177         lienzo.addMouseMotionListener(new EscuchaMoverMouse(cañon, lienzo));
 178         lienzo.addMouseListener(new EscuchaMouse(cañon, lienzo, bloques, cabeza, puntaje));
 179         marco.setVisible(true);
 180 
 181 
 182 
 183 
 184 
 185 
 186 
 187     }
 188 }

Java/Programas/PinguinoGg/Main.java (last edited 2010-10-28 11:58:11 by LorenaGuerrero)