Java - Ayuda con rmi

 
Vista:

Ayuda con rmi

Publicado por Ayuda con rmi (15 intervenciones) el 15/03/2021 16:47:10
Hola. Buenas tardes para todos.
Estoy haciendo un juego implementando RMI y MVC y me surgio un problema con el boton "agregar jugador".
Cuando abro solo un cliente anda bien, agrega a los jugadores de forma correcta. Pero al abrir dos falla, agrega solo a 1 jugador y le reparte seis cartas. Nose cual sera el problema ya que nunca trabaje con RMI, soy novata con eso.
Si alguien me puede ayudar para darme cuenta de que esta pasando se lo agradeceria.

Les dejo las clases:

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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
import java.io.Serializable;
import java.util.ArrayList;
 
import Cartas.Cartas;
import Cartas.Mazo;
import Cartas.Palos;
 
public class Jugador implements Serializable {
 
public String nombre;
public int escoba=0;
public int sietes=0;
public int oros=0;
public int sieteOro=0;
public int cartas=0;
public int puntos=0;
protected boolean estado;
public ArrayList<Cartas> mazo_jugador = new ArrayList<>(); // Mazo donde juntara las cartas que levanta
public ArrayList<Cartas> cartasEnMano = new ArrayList<>(); //Cartas que va a tener en la mano
 
 
public Jugador (String nombre){
this.nombre=nombre;
this.puntos=0;
this.escoba=0;
//this.estado=true;
 
}
 
public int getPuntos() {
return this.puntos;
}
 
public void setPuntos() {
this.puntos++;
}
public void sieteOro() {
for (int i=0;i<mazo_jugador.size();i++) {
//mazo_jugador.get(i).getPalo();
if (mazo_jugador.get(i).numero==7 && mazo_jugador.get(i).getPalo().equals(Palos.ORO)) {
this.puntos++;
 
 
}
}
}
 
 
public void sietes() {
for (int i=0;i<mazo_jugador.size();i++) {
if(mazo_jugador.get(i).numero==7) {
this.sietes++;
}
}
if (this.sietes>=2) {
this.puntos++;
}
}
 
 
public void agregarCarta(Cartas carta){
if (carta!=null) {
cartasEnMano.add(carta); //Cuando reparten agrega carta a cartasEnMano (3 cartas)
}
}
 
 
public String getNombre() {
return nombre;
}
 
public void escoba() {
this.puntos++;// TODO Auto-generated method stub
 
}
 
 
}
 
 
 
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.rmi.Remote;
 
 
import Cartas.Cartas;
import Cartas.Mazo;
import Cartas.Palos;
import Modelo.Jugador;
import ar.edu.unlu.rmimvc.observer.ObservableRemoto;
 
public class Juego extends ObservableRemoto implements IJuego{
 
 
 
 
public ArrayList<Jugador> jugadores = new ArrayList<>(); //Lista de jugadores
public static ArrayList<Cartas> mesa = new ArrayList<>(); //Cartas en mesa
public Mazo mazoCarta = new Mazo(); //Mazo
private static int jugadorActual=0;
//private int jugadorMano=0;
public static int ronda=0;
private int estado;
public static final int INICIANDO_JUEGO = 0;
public static final int JUGANDO = 1; //Controladores de estado
public static final int FINALIZADO = 2;
public static int contador=0;
public static int contador2=0;
public static int reparte=0;
 
 
 
 
 
 
public Juego() {
estado=INICIANDO_JUEGO;
jugadorActual = 0;
ronda = 0;
//notificarObservadores(1);
}
 
@Override
public void iniciar() throws RemoteException {
estado=INICIANDO_JUEGO;
jugadorActual=0;
ronda=0;
notificarObservadores(1);
}
 
 
@Override
public void jugando() throws RemoteException { //Para cuando este jugando
int cont=1;
estado=JUGANDO;
repartirMesa();
repartirJugadores();
jugadorActual=0;
ronda=0;
notificarObservadores(4);
}
 
 
@Override
public void agregarJugador (String nombre) throws RemoteException {
 
jugadores.add(new Jugador(nombre));
notificarObservadores(2);
}
 
@Override
public ArrayList<Jugador> getJugadores() throws RemoteException{
return jugadores;
}
 
public ArrayList<Cartas> getMesa() throws RemoteException{
return mesa;
}
 
}
 
 
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;
import java.util.Scanner;
 
 
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
 
import Cartas.Cartas;
import Modelo.IJuego;
import Modelo.Juego;
import Modelo.Jugador;
import Vista.ControlVista;
import Vista.VistaConsola;
import Vista.VistaGrafica;
import ar.edu.unlu.rmimvc.cliente.IControladorRemoto;
import ar.edu.unlu.rmimvc.observer.IObservableRemoto;
 
 
 
 
public class ControladorJuego implements IControladorRemoto {
 
public static final int INICIANDO_JUEGO = Juego.INICIANDO_JUEGO;
public static final int JUGANDO = Juego.JUGANDO; // Controladores de estado
public static final int FINALIZADO = Juego.FINALIZADO;
public static int eleccionVista;
 
 
 
private IJuego miJuego;
private ControlVista miVista;
 
public ControladorJuego(ControlVista miVista/*, Juego juego*/) {
//this.miJuego = juego;
this.miVista = miVista;
//juego.addObserver(this);
 
}
 
public void agregarJugador(String nombre) throws RemoteException {
miJuego.agregarJugador(nombre);
}
 
public static void iniciarJuego() throws RemoteException{
//miJuego.addObserver(this);
//miJuego.iniciar();
}
 
 
 
 
public static void main(String args[]) throws RemoteException {
//vistaPrincipal();
/*System.out.println("Elige vista");
System.out.println("");
System.out.println("1. Vista consola");
System.out.println("2. Vista grafica");
Scanner sc = new Scanner(System.in);
int eleccionVista = sc.nextInt();
if (eleccionVista==1) {
Juego jue = new Juego();
ControlVista vista = new VistaConsola();
ControladorJuego c = new ControladorJuego(vista);
jue.iniciar();}
else {
if(eleccionVista==2) {
Juego jue= new Juego();
ControlVista vista = new VistaGrafica();
ControladorJuego c = new ControladorJuego(vista);
jue.iniciar();
}
}*/
}
 
 
 
public String getJugadores() throws RemoteException {
return miJuego.mostrarJugadores();
 
}
 
public ArrayList<Cartas> getMesa() throws RemoteException {
return miJuego.getMesa();
}
 
public void mostrarJugadores() throws RemoteException {
miVista.mostrarJugadores();
//miVista.menu();
}
 
public void mostrarJugador() throws RemoteException {
miVista.mostrarJugador();
miVista.menuJugador();
}
 
public String getCartasMesa() throws RemoteException {
return miJuego.mostrarMesa();
}
 
public String getCartasEnMano(Jugador j) throws RemoteException{
return miJuego.mostrarCartasEnMano(j);
}
 
public void mostrarCartasEnMano() throws RemoteException {
System.out.println("Cartas en mano");
miVista.mostrarCartasEnMano();
}
 
public void mostrarMesa() throws RemoteException {
System.out.println("Cartas en mesa");
miVista.mostrarMesa();
}
 
public void tirarCarta(int op, Jugador j) throws RemoteException{
miJuego.tirarCarta(op, j);
 
}
 
public void seleccionarCartasMesa(int op, Jugador j) throws RemoteException {
miJuego.seleccionarCartasMesa(op, j);
}
 
public void seleccionarCartasMazo(int op, Jugador j) throws RemoteException{
miJuego.seleccionarCartasMazo(op, j);
}
 
public String mostrarCartasEnMano(Jugador j) throws RemoteException{
return miJuego.mostrarCartasEnMano(j);
}
 
public Jugador getJugador()throws RemoteException {
return miJuego.getJugador();
}
 
public void turnosJugador() throws RemoteException {
miJuego.turnosJugador();
}
 
public int mostrarContador() throws RemoteException{
return miJuego.mostrarContador();
}
 
public void devolverCartasMesa(Jugador j) throws RemoteException {
miJuego.devolverCartasMesa(j);
}
 
public void devolverCartasMazo(Jugador j)throws RemoteException {
miJuego.devolverCartasMazo(j);
}
 
public boolean controlCartaJugadores() throws RemoteException {
return miJuego.controlCartaJugadores();
}
 
public void verificarCartas() throws RemoteException{
miJuego.verificarCartas();
}
 
 
 
public void getMesa(Jugador j) throws RemoteException {
miJuego.agarrarMesa(j);
 
}
 
@Override
public void actualizar(IObservableRemoto modelo, Object queCambio) throws RemoteException{
int cambio = (int) queCambio;
switch (cambio) {
case 1:
//miVista.menu();
break;
case 2:
System.out.println("Jugador agregado con exito");
break;
case 3:
break;
case 4:
break;
}}
 
 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;
import java.util.Scanner;
 
import javax.swing.*;
import javax.swing.border.EmptyBorder;
 
import Controlador.ControladorJuego;
import Modelo.Juego;
import Modelo.Jugador;
//import Modelo.Jugador;
 
 
 
 
public class VistaGrafica extends JFrame implements ControlVista{
 
private JPanel contentPane;
private JTextField txtAgregarJugador;
private JButton boton1;
private JButton boton2;
private static JPanel panel;
private static JPanel panel2;
private static JTextArea textArea;
private static ControladorJuego miControl;
private static Juego miJuego;
private static int indice=0;
private static int indice2=0;
private static int r=0;
private static int r2=0;
private static JFrame frame;
private JLabel turno;
public Image fondo;
 
 
 
 
 
public void menu() throws RemoteException{
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(400, 50, 700, 500);
frame.setTitle("Escoba de 15");
frame.setLayout(null);
JPanel contentPane = new JPanel();
contentPane.setBounds(0,0,700,500);
contentPane.setBackground(Color.black);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setVisible(true);
 
frame.getContentPane().add(contentPane);
 
 
 
panel = new JPanel();
panel.setBounds(0,0,700, 500);
panel.setBackground(Color.LIGHT_GRAY);
panel.setBorder(new EmptyBorder(5, 5, 5, 5));
 
 
 
 
JLabel imagenMenu = new JLabel("MENU");
imagenMenu.setFont(new Font("Curlz MT",Font.PLAIN,70));
imagenMenu.setBounds(250,20,200,200);
imagenMenu.setForeground(Color.pink);
contentPane.add(imagenMenu);
 
JLabel imagenCartas = new JLabel();
imagenCartas.setBounds(0,300,200,200);
ImageIcon imagen3 = new ImageIcon("cartas2.jpg");
imagenCartas.setIcon(new ImageIcon(imagen3.getImage().getScaledInstance(imagenCartas.getWidth(),imagenCartas.getHeight(),Image.SCALE_SMOOTH)));
//contentPane.add(imagenCartas);
 
 
 
 
 
 
panel2 = new JPanel();
panel2.setBounds(0,0,700,500);
panel2.setBackground(Color.pink);
panel2.setBorder(new EmptyBorder(5, 5, 5, 5));
 
 
 
JTextField txtAgregarJugador = new JTextField();
//txtAgregarJugador.setBounds(new Rectangle(0, 0, 25, 23));
//txtAgregarJugador.setEditable(true);
txtAgregarJugador.setBounds(250, 200, 179, 33);
txtAgregarJugador.setHorizontalAlignment(SwingConstants.CENTER);
txtAgregarJugador.setBackground(new Color(192, 192, 192));
//txtAgregarJugador.setEnabled(false);
txtAgregarJugador.setFont(new Font("Arial", Font.ITALIC, 13));
txtAgregarJugador.setText("Nombre jugador");
txtAgregarJugador.setToolTipText("Agregar jugador");
txtAgregarJugador.setColumns(10);
contentPane.add(txtAgregarJugador);
 
 
JButton boton1 = new JButton("Agregar jugador");
//boton1.setForeground(new Color(255, 0, 255));
boton1.setBackground(new Color(218, 112, 214));
boton1.setBounds(new Rectangle(250, 250, 179, 31));
//boton1.setFont(new Font("Trebuchet MS", Font.PLAIN, 11));
contentPane.setLayout(null);
contentPane.add(boton1);
boton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
try {
miControl.agregarJugador(txtAgregarJugador.getText());
txtAgregarJugador.setText(null);
} catch (RemoteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
 
 
}
 
 
// textArea.setText(txtAgregarJugador.getText()+"");
 
 
 
});
 
textArea = new JTextArea(12,30);
//textArea.setForeground(new Color(255, 105, 180));
//textArea.setToolTipText("mostrarJugadores");
//textArea.setBounds(0,0, 100, 100);
textArea.setEditable(false);
//contentPane.add(textArea);
 
JButton boton2 = new JButton("Iniciar juego");
boton2.setBackground(new Color(218, 112, 214));
//boton2.setForeground(new Color(255, 0, 255));
boton2.setBounds(550, 400, 108, 33);
contentPane.add(boton2);
boton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
contentPane.setVisible(false);
frame.setBounds(400, 50, 700, 600);
frame.setContentPane(panel);
frame.setTitle("Jugando");
frame.setVisible(true);
panel.setVisible(true);
panel.setLayout(null);
 
try {
miControl.jugando() ;
menuJugador();
mostrarMesa();
} catch (RemoteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
 
 
});
 
frame.setVisible(true);
 
 
 
}
 
 
 
 
 
 
public void menuJugador() throws RemoteException {
JLabel cartaNum = new JLabel();
cartaNum.setBounds(420,250,120,120);
 
 
ImageIcon imagen = new ImageIcon("tapa.jpg");
JLabel btn = new JLabel();
btn.setBounds(270,350,120,180);
 
turno = new JLabel("Turno de: "+miControl.getJugador().getNombre());
 
turno.setBounds(0,0,200,20);
panel.add(turno);
 
JButton boton = new JButton("Siguiente");
boton.setBounds(420,360,100,30);
boton.setBackground(new Color(218, 112, 214));
 
 
JButton boton3 = new JButton("Tirar");
boton3.setBounds(420,410,100,30);
boton3.setBackground(new Color(218, 112, 214));
 
JButton boton4 = new JButton("Agrupar");
boton4.setBounds(420,460,100,30);
boton4.setBackground(new Color(218, 112, 214));
 
JButton boton5 = new JButton("Formar 15");
boton5.setBounds(540,410,100,30);
boton5.setBackground(Color.magenta);
 
 
 
 
 
 
 
 
btn.setIcon(new ImageIcon(imagen.getImage().getScaledInstance(btn.getWidth(),btn.getHeight(),Image.SCALE_SMOOTH)));
 
panel.add(btn);
panel.add(boton);
panel.add(boton3);
panel.add(boton4);
panel.add(boton5);
panel.add(cartaNum);
 
turno.setText("Turno de: "+miControl.getJugador().getNombre());
boton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
if (indice < miControl.getJugador().cartasEnMano.size()) {
r=indice;
ImageIcon imagen = new ImageIcon(miControl.getJugador().cartasEnMano.get(indice)+".jpg");
cartaNum.setText("Carta numero: "+ indice);
btn.setIcon(new ImageIcon(imagen.getImage().getScaledInstance(btn.getWidth(),btn.getHeight(),Image.SCALE_SMOOTH)));
indice++;
 
} else {
indice=0;
r=0;
 
}
}
 
catch (RemoteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
 
}
} );
 
boton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
miControl.tirarCarta(r,miControl.getJugador());
} catch (RemoteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
indice=0;
r=0;
cartaNum.setText("");
try {
turno.setText("Turno de: "+miControl.getJugador().getNombre());
} catch (RemoteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
ImageIcon imagen = new ImageIcon("tapa.jpg");
btn.setIcon(new ImageIcon(imagen.getImage().getScaledInstance(btn.getWidth(),btn.getHeight(),Image.SCALE_SMOOTH)));
 
 
}
 
 
 
 
});
 
boton4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
miControl.seleccionarCartasMazo(r, miControl.getJugador());
} catch (RemoteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
indice=0;
r=0;
cartaNum.setText("");
/*ImageIcon imagen = new ImageIcon("tapa.jpg");
btn.setIcon(new ImageIcon(imagen.getImage().getScaledInstance(btn.getWidth(),btn.getHeight(),Image.SCALE_SMOOTH)));
miControl.verificarCartas();
turno.setText("Turno de: "+miControl.getJugador().getNombre());*/
}
});
boton5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ImageIcon imagen = new ImageIcon("tapa.jpg");
btn.setIcon(new ImageIcon(imagen.getImage().getScaledInstance(btn.getWidth(),btn.getHeight(),Image.SCALE_SMOOTH)));
try {
miControl.verificarCartas();
} catch (RemoteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
turno.setText("Turno de: "+miControl.getJugador().getNombre());
} catch (RemoteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
 
}});
 
 
};
public void mostrarJugadores(){
System.out.println("todavia nada");
};
 
 
public void mostrarMesa() throws RemoteException {
 
JLabel cartaNum = new JLabel();
cartaNum.setBounds(0,100,120,120);
 
ImageIcon imagen2 = new ImageIcon(miControl.getMesa().get(indice2)+".jpg");
JLabel btn2 = new JLabel();
btn2.setBounds(270,20,120,180);
 
JButton boton5 = new JButton("Siguiente");
boton5.setBounds(420,70,100,30);
boton5.setBackground(new Color(218, 112, 214));
 
 
JButton boton6 = new JButton("Agrupar");
boton6.setBounds(420,120,100,30);
boton6.setBackground(new Color(218, 112, 214));
 
btn2.setIcon(new ImageIcon(imagen2.getImage().getScaledInstance(btn2.getWidth(),btn2.getHeight(),Image.SCALE_SMOOTH)));
 
panel.add(btn2);
panel.add(boton5);
panel.add(boton6);
boton5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
if (indice2 < miControl.getMesa().size()) {
r2=indice2;
ImageIcon imagen2 = new ImageIcon(miControl.getMesa().get(indice2)+".jpg");
cartaNum.setText("Carta numero: "+ indice2);
btn2.setIcon(new ImageIcon(imagen2.getImage().getScaledInstance(btn2.getWidth(),btn2.getHeight(),Image.SCALE_SMOOTH)));
indice2++;
} else {
indice2=0;
r2=0;
}
} catch (RemoteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
 
 
 
}
});
 
boton6.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
/*ImageIcon imagen2 = new ImageIcon("tapa.jpg");
btn2.setIcon(new ImageIcon(imagen2.getImage().getScaledInstance(btn2.getWidth(),btn2.getHeight(),Image.SCALE_SMOOTH)));*/
try {
miControl.seleccionarCartasMesa(r2, miControl.getJugador());
} catch (RemoteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
indice2=0;
r2=0;
}
});
}
 
 
 
import java.rmi.RemoteException;
 
import Controlador.ControladorJuego;
 
public interface ControlVista {
void menu() throws RemoteException;
void setControlador(ControladorJuego controlador);
void menuJugador() throws RemoteException;
void mostrarJugadores() throws RemoteException ;
void mostrarMesa() throws RemoteException ;
void mostrarCartasEnMano() ;
void mostrarJugador() ;
void menuCartasAgrupadas();
void menuNoforman15();
void jugadorAgregado();
void menuSumarPuntos();
void iniciar() throws RemoteException ;
 
 
 
}
 
 
public interface IJuego extends IObservableRemoto {
 
void iniciar() throws RemoteException;
 
void jugando() throws RemoteException;
 
void agregarJugador(String nombre) throws RemoteException;
 
ArrayList<Jugador> getJugadores() throws RemoteException;
 
int getEstado() throws RemoteException;
 
void finaliza() throws RemoteException;
 
void repartirJugadores() throws RemoteException;
 
void repartirMesa() throws RemoteException ;
 
String mostrarMesa() throws RemoteException;
 
String mostrarCartasEnMano(Jugador j) throws RemoteException ;
 
void tirarCarta(int op, Jugador j) throws RemoteException;
 
 
 
 
boolean controlCartaJugadores() throws RemoteException;
 
String mostrarJugadores() throws RemoteException;
 
void turnosJugador() throws RemoteException;
 
Jugador getJugador() throws RemoteException;
 
int jugadorActual() throws RemoteException;
 
void seleccionarCartasMesa(int op, Jugador j) throws RemoteException;
 
void seleccionarCartasMazo(int op, Jugador j) throws RemoteException;
 
int mostrarContador() throws RemoteException ;
 
void verificarCartas() throws RemoteException;
 
void devolverCartasMesa(Jugador j) throws RemoteException;
 
void devolverCartasMazo(Jugador j) throws RemoteException;
 
int getCartaActual() throws RemoteException;
 
void agarrarMesa(Jugador j) throws RemoteException;
 
void getOros() throws RemoteException;
 
void getContarCartas()throws RemoteException ;
 
void contarPuntos() throws RemoteException;
 
String mostrarGanador() throws RemoteException;
 
boolean consultarMazo() throws RemoteException;
 
void actualizarARepartirCartas() throws RemoteException;
 
ArrayList<Cartas> getMesa() throws RemoteException;
 
}
 
import java.rmi.RemoteException;
import java.util.ArrayList;
 
import javax.swing.JOptionPane;
 
import Modelo.IJuego;
import Modelo.Juego;
import ar.edu.unlu.rmimvc.RMIMVCException;
import ar.edu.unlu.rmimvc.Util;
import ar.edu.unlu.rmimvc.servidor.Servidor;
 
public class AppServidor {
 
public static void main(String[] args) throws RemoteException {
ArrayList<String> ips = Util.getIpDisponibles();
String ip = (String) JOptionPane.showInputDialog(
null,
"Seleccione la IP en la que escuchará peticiones el servidor", "IP del servidor",
JOptionPane.QUESTION_MESSAGE,
null,
ips.toArray(),
null
);
String port = (String) JOptionPane.showInputDialog(
null,
"Seleccione el puerto en el que escuchará peticiones el servidor", "Puerto del servidor",
JOptionPane.QUESTION_MESSAGE,
null,
null,
8888
);
 
Juego modelo = new Juego();
System.out.println("Juego creado");
Servidor servidor = new Servidor(ip, Integer.parseInt(port));
try {
servidor.iniciar(modelo);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RMIMVCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
 
}
 
 
import java.util.ArrayList;
 
 
 
import java.rmi.RemoteException;
import java.util.ArrayList;
 
import javax.swing.JOptionPane;
import Controlador.ControladorJuego;
import Vista.ControlVista;
import Vista.VistaGrafica;
import ar.edu.unlu.rmimvc.RMIMVCException;
import ar.edu.unlu.rmimvc.cliente.Cliente;
import ar.edu.unlu.rmimvc.Util;
import Modelo.IJuego;
import Modelo.Juego;
 
 
 
 
//import cliente.Cliente;
 
public class AppCliente {
 
public IJuego miJuego;
 
public static void main(String[] args) throws RemoteException {
ArrayList<String> ips = Util.getIpDisponibles();;
String ip = (String) JOptionPane.showInputDialog(
null,
"Seleccione la IP en la que escuchará peticiones el cliente", "IP del cliente",
JOptionPane.QUESTION_MESSAGE,
null,
ips.toArray(),
null
);
String port = (String) JOptionPane.showInputDialog(
null,
"Seleccione el puerto en el que escuchará peticiones el cliente", "Puerto del cliente",
JOptionPane.QUESTION_MESSAGE,
null,
null,
9999
);
String ipServidor = (String) JOptionPane.showInputDialog(
null,
"Seleccione la IP en la corre el servidor", "IP del servidor",
JOptionPane.QUESTION_MESSAGE,
null,
null,
null
);
String portServidor = (String) JOptionPane.showInputDialog(
null,
"Seleccione el puerto en el que corre el servidor", "Puerto del servidor",
JOptionPane.QUESTION_MESSAGE,
null,
null,
8888
);
ControlVista vista = new VistaGrafica();
ControladorJuego controlador = new ControladorJuego(vista);
Cliente c = new Cliente(ip, Integer.parseInt(port), ipServidor, Integer.parseInt(portServidor));
vista.setControlador(controlador);
vista.iniciar();
try {
c.iniciar(controlador);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RMIMVCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}




Claramente las interfaces tienen metodos que no escribi porque sino se haria muy larga la publicacion y el problema puntual esta en agregarjugador
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