Java - ¡¡JUEGO SIMON DICE!!

 
Vista:

¡¡JUEGO SIMON DICE!!

Publicado por Melissa (6 intervenciones) el 28/05/2005 22:32:30
POR FAVOR, NECESITO QUE ME AYUDEN, TENGO QUE REALIZAR ESTE JUEGO, PERO NO HE PODIDO.
<br>¿ES NECESARIO TRABAJAR CON THREADS PARA ESTE JUEGO?
<br>no he usado threads en mi programa, pero tal vez por eso no funcione y quisiera saber si los tengo que usar.
<br>POR QUE HASTA AHORA NO SE COMO HACER QUE DESPUES DE MOSTRAR LA SECUENCIA DE NUMEROS, EL USUARIO PUEDA PRESIONAR LOS BOTONES, SINO QUE SOLAMENTE PUEDO PRESIONAR LOS BOTONES CUANDO YA TERMINO LA SECUENCIA DE TODOS LOS NIVELES, Y NO EN CADA NIVEL.
<br>
<br>por favor, si alguien tiene la respuesta o un pedazo de codigo de SIMON DICE que me pudiera ayudar lo agradeceria mucho.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:¡¡JUEGO SIMON DICE!!

Publicado por Wilfredo Vargas Almendras (314 intervenciones) el 31/05/2005 03:44:19
No conozco el juego, seria bueno que lo plantees y publiques lo que tienes en codigo, creo poder ayudarte.....
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:¡¡JUEGO SIMON DICE!!

Publicado por Melissa (6 intervenciones) el 31/05/2005 04:09:53
Hola Wilfredo. Soy Melissa, yo soy nueva en Java, apenas lo estoy viendo, pero como proyecto final, la maestra nos pidio realizar este juego. Se trata se mostrar una secuencia se botones, y que el usuario los seleccione en el orden mostrado, si gana, va subiendo de nivel y de secuencia de botones.

Mira a continuacion esta lo que llevo del programa, pero no funciona bien. Como es la primera vez que manejo graficos, aun no se como funcionan. Tengo el problema de que cuando muestro la secuencia del primer nivel, despues el programa no me deja seleccionar el boton, sino que automaticamente me dice que pierdo.

La verdad, no se si es porque no tengo bien la logica del programa, o por que debo utilizar Threads (hilos).

Espero que me puedas ayudar. Muchas gracias.

// PROYECTO FINAL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.Math.*;
import javax.swing.Timer.*;
import java.io.*;
 
public class SimonDice extends Frame{
 
	Button boton1, boton2, boton3, boton4, start;
	Button juego, record;
	Checkbox caja1, caja2;
	List lista, lista2;
	Frame ventana;
	Label titulo, titulo2;
	int num=0;
 
	public SimonDice(){
 
		initComponentes();
	}
 
	public void initComponentes(){
 
		ventana = new Frame();
		ventana.setLayout(null);
		ventana.setBounds(10,10,700,500);
		ventana.setBackground(Color.gray);
 
		titulo2 = new Label("INICIANDO JUEGO",Label.CENTER);
		titulo2.setFont(new Font("Arial",Font.BOLD,30));
		titulo2.setForeground(Color.yellow);
		titulo2.setBounds(55,30,600,50);
 
 
		ventana.addWindowListener(new java.awt.event.WindowAdapter(){
			public void windowClosing(java.awt.event.WindowEvent evt){
				ventana.hide();
				show();
			}
		});
 
 
		setLayout (null);
		setBounds(10,10,600,400);
		setBackground(Color.LIGHT_GRAY);
 
		titulo = new Label("JUEGO SIMON DICE", Label.CENTER);
		titulo.setFont(new Font("Arial",Font.BOLD, 30));
		titulo.setForeground(Color.red);
		titulo.setBounds(5,30,600,50);
		add(titulo);
 
		Font f = new Font("Splash",Font.BOLD,12);
		setFont(f);
 
		caja1 = new Checkbox("Colores Fuertes");
		caja1.setBounds(50,160,130,40);
		add(caja1);
 
		caja2 = new Checkbox("Colores Pasteles");
		caja2.setBounds(50,230,130,40);
		add(caja2);
 
		caja1.addMouseListener(new MouseAdapter(){
			public void mouseClicked(MouseEvent evt){
				colorFuerte(evt);
			}
		});
 
		caja2.addMouseListener(new MouseAdapter(){
			public void mouseClicked(MouseEvent evt){
				colorPastel(evt);
			}
		});
 
		lista = new List();
		lista.setBounds(200,160,80,70);
 
		lista2 = new List();
		lista2.setBounds(200,230,80,70);
 
		start = new Button("START");
		start.setBackground(Color.black);
		start.setForeground(Color.white);
		start.setBounds(317,100,80,50);
 
 
		start.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent evt){
				Comenzar(evt);
			}
		});
 
		ActionListener al = new ActionListener(){
			public void actionPerformed(ActionEvent evt){
				click(evt);
			}
		};
 
 
		boton1 = new Button();
		boton1.setBounds(180,180,180,140);
 
		boton2 = new Button();
		boton2.setBounds(360,180,180,140);
 
		boton3 = new Button();
		boton3.setBounds(180,320,180,140);
 
		boton4 = new Button();
		boton4.setBounds(360,320,180,140);
 
		boton1.addActionListener(al);
		boton2.addActionListener(al);
		boton3.addActionListener(al);
		boton4.addActionListener(al);
 
		juego = new Button("JUGAR");
		juego.setBackground(Color.red);
		juego.setForeground(Color.yellow);
		juego.setBounds(380,150,90,60);
		juego.setEnabled(false);
		juego.setVisible(true);
		add(juego);
 
		juego.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent evt){
				nuevaVentana(evt);
			}
		});
 
 
		record = new Button("RECORD");
		record.setBackground(Color.blue);
		record.setForeground(Color.yellow);
		record.setBounds(380,250,90,60);
		add(record);
 
 
		addWindowListener(new java.awt.event.WindowAdapter(){
			public void windowClosing(java.awt.event.WindowEvent evt){
				System.exit(0);
			}
		});
 
	}//initComponentes
 
	private void colorFuerte(MouseEvent evt){
		if(!caja1.getState())
		{
			caja1.setState(false);
			caja2.setEnabled(true);
			lista.setVisible(false);
		}//if
		else
		{
			caja2.setEnabled(false);
			caja1.setEnabled(true);
			lista.removeAll();
			lista.add("Azul");
			lista.add("Rojo");
			lista.add("Amarillo");
			lista.add("Verde");
			lista.setForeground(Color.blue);
			lista.setBackground(Color.yellow);
			lista.setVisible(true);
			add(lista);
			juego.setEnabled(true);
 
			boton1.setBackground(Color.blue);
			boton2.setBackground(Color.red);
			boton3.setBackground(Color.yellow);
			boton4.setBackground(Color.green);
		}
	}//colorFuerte
 
 
	private void colorPastel(MouseEvent evt){
		if(!caja2.getState())
		{
			caja2.setState(false);
			caja1.setEnabled(true);
			lista2.setVisible(false);
		}//if
		else
		{
			caja1.setEnabled(false);
			caja2.setEnabled(true);
			lista2.removeAll();
			lista2.add("Azulito");
			lista2.add("Rosita");
			lista2.add("Anaranjadito");
			lista2.add("Moradito");
			lista2.setForeground(Color.magenta);
			lista2.setBackground(Color.cyan);
			lista2.setVisible(true);
			add(lista2);
			juego.setEnabled(true);
 
 
			boton1.setBackground(Color.cyan);
			boton2.setBackground(Color.pink);
			boton3.setBackground(Color.orange);
			boton4.setBackground(Color.magenta);
		}
	}//colorPastel
 
 
 
	public void nuevaVentana(ActionEvent evt){
 
		ventana.add(titulo2);
		ventana.add(start);
		ventana.add(boton1);
		ventana.add(boton2);
		ventana.add(boton3);
		ventana.add(boton4);
		ventana.show();
 
	}
 
 
	public void setDelay(int delay){
 
		long t = System.currentTimeMillis() + delay;
		while(System.currentTimeMillis() < t);
	}//setDelay
 
 
	private void Ejecucion (int nivel, int []vector)
	{
 
		final double inferior=1;
		final double superior=5;
		double r=0;
 
			for(int x=1; x<=nivel; x++)
			{
				r = (int) ((superior-inferior)*Math.random()+inferior);
 
				if(r==1)
					boton1.setBackground(Color.white);
					setDelay(200);
					if(caja1.getState())
						boton1.setBackground(Color.blue);
					if(caja2.getState())
						boton1.setBackground(Color.cyan);
 
				if(r==2)
					boton2.setBackground(Color.white);
					setDelay(200);
					if(caja1.getState())
						boton2.setBackground(Color.red);
					if(caja2.getState())
						boton2.setBackground(Color.pink);
 
				if(r==3)
					boton3.setBackground(Color.white);
					setDelay(200);
					if(caja1.getState())
						boton3.setBackground(Color.yellow);
					if(caja2.getState())
						boton3.setBackground(Color.orange);
 
				if(r==4)
					boton4.setBackground(Color.white);
					setDelay(200);
					if(caja1.getState())
						boton4.setBackground(Color.green);
					if(caja2.getState())
						boton4.setBackground(Color.magenta);
 
				vector[x] = (int) r;
 
			}//for
			setDelay(600);
 
	}//Ejecucion
 
	public void click(ActionEvent evt){
 
		Object obj = evt.getSource();
 
		if(obj==boton1) num=1;
		if(obj==boton2) num=2;
		if(obj==boton3) num=3;
		if(obj==boton4) num=4;
	}
 
	public int Eleccion(){
		int op;
		return op=num;
	}
 
 
	private boolean Jugar(int nivel, int []vector){
 
		boolean ban=true;
		int opcion=0;
 
		JOptionPane.showMessageDialog(null,"NIVEL: "+ nivel);
 
		Ejecucion(nivel,vector);
 
		JOptionPane.showMessageDialog(null,"ES TU TURNO");
 
 
 
		for(int y=1; y<=nivel; y++)
		{
 
			opcion=Eleccion();
			setDelay(500);
 
			if(opcion!=vector[y])
			{
				ban=false;
				y=nivel;
			}//if
		}//for
 
		return ban;
 
	}//Jugar
 
 
 
	private void Comenzar(ActionEvent evt){
 
		int [] vector = new int[21];
		int nivel=1;
 
		for(int z=1; z<=20; z++)
			vector[z]=0;
 
		boolean b=true;
 
 
		setDelay(600);
 
		do{
 
			b=Jugar(nivel,vector);
			nivel++;
 
		}while(b);
 
 
		if(b)
			JOptionPane.showMessageDialog(null,"GANASTE");
		else
			JOptionPane.showMessageDialog(null,"PERDISTE");
 
 
	}//Comenzar
 
 
	public static void main(String[] args){
		new SimonDice().show();
	}//main
 
}//clase SimonDice
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar

RE:¡¡JUEGO SIMON DICE!!

Publicado por Wilfredo Vargas Almendras (314 intervenciones) el 31/05/2005 04:27:17
Hola, ya vi tu programa, pero aun no entiendo la logica del programa, cuando se gana el juego, es decir como se lleva a cabo el juego, cuando se suve de nivel?, Quisiera que publiques una descripcion del juego mas detallada.......
Me aparece la ventana del START, Inicio y pues se hace click sobre algun boton y luego cuando me dice "tu turno", en seguida me dice que perdi, cuando pierdo?
entiendo que quieres corregir ese error, pero antes necesito entender el problema...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:¡¡JUEGO SIMON DICE!!

Publicado por Melissa (6 intervenciones) el 31/05/2005 06:29:32
Te mando el problema y explicacion por correo.
Lo que pasa es que excedi los 10000 caracteres.
Espero que lo puedas checar. (esta en .txt)
Si no te llega me dices en el foro, por favor.
Gracias.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:¡¡JUEGO SIMON DICE!!

Publicado por Sergio (24 intervenciones) el 31/05/2005 10:44:53
puedes utilizar esta funcion de pausa:

public void pausa(long timeMillis){
long inic=System.currentTimeMillis();

while(inic+timeMillis>System.currentTimeMillis());
}

No lo he probado, pero supongo que funcionará.
El metodo System.currentTimeMillis() devuelve el tiempo en milisegundos desde que se inicio el programa.
Lo unico que tienes que hacer es meterlo despues de la pulsación de cada boton.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:¡¡JUEGO SIMON DICE!!

Publicado por Melissa (6 intervenciones) el 31/05/2005 16:23:13
Muchas Gracias, voy a probar, espero que funcione.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:¡¡JUEGO SIMON DICE!!

Publicado por sergio (24 intervenciones) el 31/05/2005 16:49:34
Me temo que si te va a tocar crear un thread para pausar el juego, ya que el metodo que te di antes no cuela porque espera pero no recoje los eventos.
tampoco seria muy dificil:

1
2
3
4
5
6
7
8
9
10
public void pausa(int milis){
new Thread(new Runnable(){
public void run(){
try{
sleep(milis);
}catch(InterruptedException ie){}
}//fin run
}//fin Runnable
).start();
}//fin pausa
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:¡¡JUEGO SIMON DICE!!

Publicado por Melissa (6 intervenciones) el 31/05/2005 17:44:30
Mira aqui esta mi codigo, por mas que trato no funciona. Le agregue lo que me dijiste, pero ni aun asi, tal vez, no lo puse donde debia ponerlo.
Pero de todos modos, espero que lo puedas ver. Hay muchos metodos que deshabilite, es que lo he cambiado muchas veces, le puse hilos, pero ahora se los quite.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
// PROYECTO FINAL
 
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.Math.*;
import javax.swing.Timer.*;
import java.io.*;
 
public class SimonDice extends Frame{
 
	Button boton1, boton2, boton3, boton4, start;
	Button juego, record;  // Alta;
	Checkbox caja1, caja2;
	List lista, lista2;
	Frame ventana;
	Label titulo, titulo2, puntaje, high;
	int num=0;				//es el contador que cuenta los botones seleccionados
	int []v;				//vector de los botones seleccionados
	int puntos=0;			//lleva el control de los puntos ganados
	int champ=0;			//es el contador de los ganadores
	int nivel=0;			//lleva el control de los niveles
	int [] vector;			//guarda la secuencia de numeros mostrados
	boolean ban=true;		//bandera para saber si ha ganado o perdido
 
	public SimonDice(){		//es el contructor
 
		vector = new int[21];
		v= new int [21];
		initComponentes();	//inicializa los componentes graficos
	}
 
 
/*****************************************************************************/
 
	public void initComponentes(){
 
		ventana = new Frame();
		ventana.setLayout(null);
		ventana.setBounds(10,10,700,500);
		ventana.setBackground(Color.gray);
 
		titulo2 = new Label("INICIANDO JUEGO",Label.CENTER);
		titulo2.setFont(new Font("Arial",Font.BOLD,30));
		titulo2.setForeground(Color.yellow);
		titulo2.setBounds(55,30,600,50);
 
 
		ventana.addWindowListener(new java.awt.event.WindowAdapter(){
			public void windowClosing(java.awt.event.WindowEvent evt){
				ventana.hide();
				show();
			}
		});
 
 
		setLayout (null);
		setBounds(10,10,600,400);
		setBackground(Color.LIGHT_GRAY);
 
		titulo = new Label("JUEGO SIMON DICE", Label.CENTER);
		titulo.setFont(new Font("Arial",Font.BOLD, 30));
		titulo.setForeground(Color.red);
		titulo.setBounds(5,30,600,50);
		add(titulo);
 
		Font f = new Font("Splash",Font.BOLD,12);
		setFont(f);
 
		caja1 = new Checkbox("Colores Fuertes");
		caja1.setBounds(50,160,130,40);
		add(caja1);
 
		caja2 = new Checkbox("Colores Pasteles");
		caja2.setBounds(50,230,130,40);
		add(caja2);
 
		caja1.addMouseListener(new MouseAdapter(){
			public void mouseClicked(MouseEvent evt){
				colorFuerte(evt);
			}
		});
 
		caja2.addMouseListener(new MouseAdapter(){
			public void mouseClicked(MouseEvent evt){
				colorPastel(evt);
			}
		});
 
		lista = new List();
		lista.setBounds(200,160,80,70);
 
		lista2 = new List();
		lista2.setBounds(200,230,80,70);
 
		start = new Button("START");
		start.setBackground(Color.black);
		start.setForeground(Color.white);
		start.setBounds(317,100,80,50);
 
 
 
		start.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent evt){
				Comenzar(evt);
			}
		});
 
 
 
		ActionListener al = new ActionListener(){
			public void actionPerformed(ActionEvent evt){
				click(evt);
			}
		};
 
 
		boton1 = new Button();
		boton1.setBounds(180,180,180,140);
 
		boton2 = new Button();
		boton2.setBounds(360,180,180,140);
 
		boton3 = new Button();
		boton3.setBounds(180,320,180,140);
 
		boton4 = new Button();
		boton4.setBounds(360,320,180,140);
 
		boton1.addActionListener(al);
		boton2.addActionListener(al);
		boton3.addActionListener(al);
		boton4.addActionListener(al);
 
		juego = new Button("JUGAR");
		juego.setBackground(Color.red);
		juego.setForeground(Color.yellow);
		juego.setBounds(380,150,90,60);
		juego.setEnabled(false);
		juego.setVisible(true);
		add(juego);
 
 
 
		juego.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent evt){
				nuevaVentana(evt);
			}
		});
 
 
 
		record = new Button("RECORD");
		record.setBackground(Color.blue);
		record.setForeground(Color.yellow);
		record.setBounds(380,250,90,60);
		add(record);
 
		high= new Label();
		high.setFont(new Font("Arial",Font.BOLD, 18));
		high.setForeground(Color.yellow);
		high.setBounds(25,350,200,40);
		high.setText("HIGH:     " + 2100);
 
		puntaje= new Label();
		puntaje.setFont(new Font("Arial",Font.BOLD, 18));
		puntaje.setForeground(Color.white);
		puntaje.setBounds(25,380,200,40);
		puntaje.setText("SCORE: " + puntos);
 
		addWindowListener(new java.awt.event.WindowAdapter(){
			public void windowClosing(java.awt.event.WindowEvent evt){
				System.exit(0);
			}
		});
 
	}//initComponentes
 
 
 
 
 
	private void colorFuerte(MouseEvent evt){
		if(!caja1.getState())
		{
			caja1.setState(false);
			caja2.setEnabled(true);
			lista.setVisible(false);
		}//if
		else
		{
			caja2.setEnabled(false);
			caja1.setEnabled(true);
			lista.removeAll();
			lista.add("Azul");
			lista.add("Rojo");
			lista.add("Amarillo");
			lista.add("Verde");
			lista.setForeground(Color.blue);
			lista.setBackground(Color.yellow);
			lista.setVisible(true);
			add(lista);
			juego.setEnabled(true);
 
			boton1.setBackground(Color.blue);
			boton2.setBackground(Color.red);
			boton3.setBackground(Color.yellow);
			boton4.setBackground(Color.green);
		}
	}//colorFuerte
 
 
	private void colorPastel(MouseEvent evt){
		if(!caja2.getState())
		{
			caja2.setState(false);
			caja1.setEnabled(true);
			lista2.setVisible(false);
		}//if
		else
		{
			caja1.setEnabled(false);
			caja2.setEnabled(true);
			lista2.removeAll();
			lista2.add("Azulito");
			lista2.add("Rosita");
			lista2.add("Anaranjadito");
			lista2.add("Moradito");
			lista2.setForeground(Color.magenta);
			lista2.setBackground(Color.cyan);
			lista2.setVisible(true);
			add(lista2);
			juego.setEnabled(true);
 
 
			boton1.setBackground(Color.cyan);
			boton2.setBackground(Color.pink);
			boton3.setBackground(Color.orange);
			boton4.setBackground(Color.magenta);
		}
	}//colorPastel
 
 
	public void nuevaVentana(ActionEvent evt){
 
		ventana.show();
		ventana.add(titulo2);
		ventana.add(start);
		ventana.add(boton1);
		ventana.add(boton2);
		ventana.add(boton3);
		ventana.add(boton4);
		ventana.add(high);
		ventana.add(puntaje);
	}
 
 
 
	public void setDelay(int delay){
 
		long t = System.currentTimeMillis() + delay;
		while(System.currentTimeMillis() < t);
	}//setDelay
 
 
 
	private void Ejecucion()
	{
		final double inferior=1;
		final double superior=5;
		double r=0;
 
 
		for(int x=1; x<=nivel; x++)
		{
			r = (int) ((superior-inferior)*Math.random()+inferior);
 
				if(r==1)
					boton1.setBackground(Color.white);
					setDelay(200);
					if(caja1.getState())
			  			boton1.setBackground(Color.blue);
			  		if(caja2.getState())
			  			boton1.setBackground(Color.cyan);
 
				if(r==2)
					boton2.setBackground(Color.white);
					setDelay(200);
					if(caja1.getState())
			  			boton2.setBackground(Color.red);
			  		if(caja2.getState())
			  			boton2.setBackground(Color.pink);
 
				if(r==3)
					boton3.setBackground(Color.white);
					setDelay(200);
					if(caja1.getState())
			  			boton3.setBackground(Color.yellow);
			  		if(caja2.getState())
			  			boton3.setBackground(Color.orange);
 
				if(r==4)
					boton4.setBackground(Color.white);
					setDelay(200);
					if(caja1.getState())
			  			boton4.setBackground(Color.green);
			  		if(caja2.getState())
			  			boton4.setBackground(Color.magenta);
 
				vector[x] = (int) r;
 
			}//for
	}//Ejecucion
 
 
	public void pausa(final int milis){
		new Thread(new Runnable(){
			public void run(){
				try{ Thread.sleep(milis); }
				catch(InterruptedException ie){}
			}//fin run 
		}//fin Runnable 
		).start();
	}//fin pausa 
 
	public void click(ActionEvent evt){
 
		Object obj = evt.getSource();
		num++;
 
		if(obj==boton1) v[num]=1;
		if(obj==boton2) v[num]=2;
		if(obj==boton3) v[num]=3;
		if(obj==boton4) v[num]=4;
 
	    pausa(600);
 
	}//click	
 
 
	private boolean Jugar(){
 
		boolean ba=true;
 
		setDelay(600);
		JOptionPane.showMessageDialog(null,"NIVEL: "+ nivel);
	    setDelay(600);
 
			Ejecucion();
 
			setDelay(1000);
		    JOptionPane.showMessageDialog(null,"ES TU TURNO");
 
		    setDelay(1000);
 
		    for(int y=1; y<=nivel; y++)
			{
 
 
				setDelay(600);
 
				if(v[y]!=vector[y])
 
				{	;
					JOptionPane.showMessageDialog(null,"PERDISTE");
					ban=false;
					y=nivel+1;
				}//if
				else
				{ ban=true;
				  puntos= puntos + (nivel*100);
				  puntaje.setText("SCORE: " + puntos);
				}
 
			}//for
 
 
		return ba=ban;
 
	}//Jugar
 
 
	private void Comenzar(ActionEvent evt){
 
		puntos=0;
		nivel=0;
		num=0;
 
		for(int z=1; z<=20; z++)
		{	vector[z]=0;
			v[z]=0;
		}
 
		boolean b=true;
 
 
		setDelay(600);
 
		do{ nivel++;
			b=Jugar();
		}while(b);
 
 
		if(b)
		{
			JOptionPane.showMessageDialog(null,"GANASTE");
	//		ventana.add(Alta);
		}//if	
 
 
	}//Comenzar
 
 
 
//ES EL MAIN
 
	public static void main(String[] args) throws IOException{
		new SimonDice().show();
	}//main
 
}//clase SimonDice
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:¡¡JUEGO SIMON DICE!!

Publicado por Sergio (24 intervenciones) el 31/05/2005 23:54:25
cambia todos los setDelay por pausa a ver si es eso lo que te da conflicto
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:¡¡JUEGO SIMON DICE!!

Publicado por Melissa (6 intervenciones) el 01/06/2005 00:12:48
no funciono, los cambie, pero ahora menos me deja pulsar el boton
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:¡¡JUEGO SIMON DICE!!

Publicado por javier lopez (1 intervención) el 10/04/2012 07:03:11
melisa si te salio el simon dice?
porqe ami no me sale :(
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar