=Interfaz.java =
1 /**
2 *@ Andrea Forero andreita_9009@hotmail.com
3 *@ Claudia Leon claudialeon18@hotmail.com
4 *@ Erika Santana eesantana61@hotmail.com
5 **/
6
7
8
9
10 import java.awt.Color;
11 import java.awt.Frame;
12 import java.io.BufferedReader;
13 import java.io.FileInputStream;
14 import java.io.FileNotFoundException;
15 import java.io.IOException;
16 import java.io.InputStreamReader;
17 import java.io.ObjectInputStream;
18 import java.util.ArrayList;
19 import java.util.Iterator;
20
21 public class Interfaz {
22 public static void main (String []args) {
23 Frame marco = new Frame("Fish");
24 Lienzo lienzo = new Lienzo();
25 marco.add(lienzo);
26 ArrayList listaPuntajes = null;
27 BufferedReader teclado = new BufferedReader(new InputStreamReader (System.in));
28 String nombreJugador = "";
29 try{
30 System.out.print("Nombre jugador: ");
31 nombreJugador = teclado.readLine();
32 }
33 catch (IOException e) {
34 }
35 Puntaje p = new Puntaje (170,450,20,10);
36 p.setNombre (nombreJugador);
37 try {
38 ObjectInputStream archivo = new ObjectInputStream(new FileInputStream(Constantes.nombreArchivo));
39 listaPuntajes = (ArrayList)archivo.readObject();
40 System.err.println("Leyendo los puntajes listaPuntajes=" + listaPuntajes);
41 archivo.close();
42
43 } catch (FileNotFoundException e) {
44 System.err.println("Archivo no encontrado");
45 listaPuntajes = new ArrayList();
46 } catch (IOException e) {
47 e.printStackTrace();
48 } catch (ClassNotFoundException e) {
49 System.err.println("Clase no encontrada");
50 e.printStackTrace();
51 }
52 listaPuntajes.add(p);
53 GestionVentana gestionVentana = new GestionVentana(listaPuntajes);
54 marco.addWindowListener(gestionVentana);
55 System.out.println("la lista de jugadores");
56 for(Iterator iter = listaPuntajes.iterator();iter.hasNext();){
57 Puntaje p_ = (Puntaje)iter.next();
58 System.out.println(p_.getNombre()+"\t"+ p_.getCantidad());
59 }
60
61
62
63
64 LineVer [] linever = {
65 new LineVer(30,50,8,195)/*0*/,new LineVer(562,45,8,210)/*5*/,new LineVer(185,45,8,70),/*6*/
66 new LineVer(450,45,8,70)/*7*/,new LineVer(160,150,8,180)/*12*/,new LineVer(450,150,8,180),/*13*/
67 new LineVer(280,160,8,60)/*17*/,new LineVer(220,270,8,60)/*18*/,new LineVer(380,270,8,60),/*19*/
68 new LineVer(562,300,8,145)/*20*/,new LineVer(30,310,8,138)/*29*/,new LineVer(270,275,8,50),/*30*/
69 new LineVer(340,275,8,50)/*31*/,new LineVer(145,448,8,30)/*34*/,new LineVer(50,445,8,30)/*35*/
70 };
71 LineHo [] lineho ={
72 new LineHo(320,45,250,8)/*1*/,new LineHo(30,180,50,8)/*2*/,new LineHo(30,240,50,8),/*3*/
73 new LineHo(30,45,240,8)/*4*/,new LineHo(520,250,50,8)/*8*/, new LineHo(520,190,50,8),/*9*/
74 new LineHo(250,100,150,8)/*10*/,new LineHo(250,160,150,8)/*11*/, new LineHo(160,240,50,8),/*14*/
75 new LineHo(400,240,50,8)/*15*/, new LineHo(280,220,80,8)/*16*/, new LineHo(330,440,240,8),/*21*/
76 new LineHo(520,360,50,8)/*22*/,new LineHo(165,390,270,8)/*24*/,new LineHo(523,300,39,8),/*25*/
77 new LineHo(30,440,248,8)/*26*/,new LineHo(30,305,50,8)/*27*/,new LineHo(30,360,50,8),/*28*/
78 new LineHo(270,325,78,8)/*32*/, new LineHo(50,470,100,8)/*33*/
79 };
80 PerlaVida[] perlavida = {
81 new PerlaVida(180,200,16,16),/*2*/new PerlaVida(200,195,10,10)/*3*/,
82 new PerlaVida(170,350,16,16)/*4*/,new PerlaVida(190,340,10,10),/*5*/
83 new PerlaVida(460,110,16,16)/*10*/,new PerlaVida(480,105,10,10)/*11*/,
84 };
85 PerlaObjetivo [] perlaobjetivo ={
86 new PerlaObjetivo(50,140,16,16)/*0*/, new PerlaObjetivo(65,130,10,10)/*1*/, new PerlaObjetivo(210,70,16,16),/*2*/
87 new PerlaObjetivo(225,65,10,10)/*3*/, new PerlaObjetivo(515,70,16,16)/*4*/,new PerlaObjetivo(530,65,10,10),/*5*/
88 new PerlaObjetivo(300,120,16,16)/*6*/,new PerlaObjetivo(315,115,10,10)/*7*/, new PerlaObjetivo(310,190,16,16),/*8*/
89 new PerlaObjetivo(325,184,10,10)/*9*/,new PerlaObjetivo(300,295,16,16)/*10*/,new PerlaObjetivo(315,290,10,10),/*11*/
90 new PerlaObjetivo(300,360,16,16)/*12*/,new PerlaObjetivo(310,350,10,10)/*13*/,new PerlaObjetivo(50,410,16,16),/*14*/
91 new PerlaObjetivo(65,400,10,10)/*15*/,new PerlaObjetivo(520,390,16,16)/*16*/, new PerlaObjetivo(535,380,10,10),/*17*/
92 new PerlaObjetivo(375,420,16,16)/*18*/,new PerlaObjetivo(390,410,10,10)/*19*/, new PerlaObjetivo(45,210,16,16),/*20*/
93 new PerlaObjetivo(60,200,10,10)/*21*/,new PerlaObjetivo(420,255,10,10)/*22*/,new PerlaObjetivo(400,260,16,16),/*23*/
94 new PerlaObjetivo(525,328,16,16)/*12r*/,new PerlaObjetivo(540,320,10,10)/*13r*/
95 };
96 PerlaMuerte [] perlamuerte = {
97 new PerlaMuerte(160,110,16,16)/*0*/,new PerlaMuerte(175,105,10,10)/*1*/,new PerlaMuerte(170,260,16,16),/*2*/
98 new PerlaMuerte(185,255,10,10)/*3*/,new PerlaMuerte(200,420,16,16)/*4*/,new PerlaMuerte(215,415,10,10),/*5*/
99 new PerlaMuerte(45,325,16,16)/*6*/,new PerlaMuerte(60,320,10,10)/*7*/, new PerlaMuerte(526,215,16,16),/*8*/
100 new PerlaMuerte(540,205,10,10)/*9*/,new PerlaMuerte(400,70,16,16)/*10*/,new PerlaMuerte(420,65,10,10),/*11*/
101 new PerlaMuerte(400,350,16,16)/*12*/,new PerlaMuerte(420,345,10,10)/*13*/
102
103 };
104 Punt [] punt = {
105 new Punt(90,90,15,15)/*0*/, new Punt(500,90,15,15),/*1*/
106 new Punt(90,380,15,15) /*2*/,new Punt(500,380,15,15)/*3*/
107 };
108 Vid [] vid = {
109 new Vid(65,455,20,10)/*0*/, new Vid(95,455,20,10)/*1*/, new Vid(120,455,20,10)/*2*/
110 };
111
112 Fish f= new Fish(50,260,30,25,new Color(255,120,0), Color.black,new Color(255,120,0));
113 Tiburon t= new Tiburon(600,260,60,25,lienzo,f,linever);
114
115 for (int i = 0; i < linever.length; i++) {
116 lienzo.add(linever[i]);
117 }
118 for (int i = 0; i < lineho.length; i++) {
119 lienzo.add(lineho[i]);
120 }
121 for (int i = 0; i < perlavida.length; i++) {
122 lienzo.add(perlavida[i]);
123 }
124 for (int i = 0; i < perlaobjetivo.length; i++) {
125 lienzo.add(perlaobjetivo[i]);
126 }
127 for (int i = 0; i < perlamuerte.length; i++) {
128 lienzo.add(perlamuerte[i]);
129 }
130 for (int i = 0; i < punt.length; i++) {
131 lienzo.add(punt[i]);
132 }
133 for (int i = 0; i < vid.length; i++) {
134 lienzo.add(vid[i]);
135 }
136 lienzo.add(f);
137 lienzo.add(t);
138 lienzo.add(p);
139 Thread hilo = new Thread(t);
140 hilo.start();
141 EscuchaTeclas escucha = new EscuchaTeclas(lienzo, f,perlaobjetivo ,perlamuerte ,perlavida ,linever ,lineho ,punt ,p ,vid);
142 // EscuchaTeclas(Lienzo l, Fish f,PerlaObjetivo p[],PerlaMuerte p1[],PerlaVida p2[] ,LineVer li[],LineHo li2[],Punt pun[],Puntaje puntaj,Vid vida)
143 marco.addKeyListener(escucha);
144 marco.setBackground (new Color(0,200,250));
145 marco.setSize(620,520);
146 marco.setVisible(true);
147 }
148
149 }
CategoryJava | CategoryProgramacion
