-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCarta.java
77 lines (64 loc) · 1.98 KB
/
Carta.java
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.ArrayList;
import java.util.Random;
import javax.swing.*;
import java.net.URL;
/**
*
* @author abel
*/
public class Carta {
JPanel mesa;
ArrayList cartas;
String grupo;
int numero;
int x=10;int fx=1;
int y=10;int fy=-1;
Random random=new Random();
JLabel label;
public Carta(ArrayList cartas,String grupo,int numero){
super();
derecha=true;
this.mesa=mesa;
this.cartas=cartas;
this.grupo=grupo;
this.numero=numero;
label=new JLabel();
String aux="";
if (grupo.equals("oro")) aux=" (4)";
if (grupo.equals("espada")) aux=" (3)";
if (grupo.equals("copa")) aux=" (2)";
try {
label.setIcon(new javax.swing.ImageIcon(new URL("http://www.cartas.22web.org/"+numero+aux+".jpg")));
} catch (Exception ex) {ex.printStackTrace(); }
cartas.add(this);
}
public boolean derecha;
public String significa="";
public boolean equals(Object x){
if (!(x instanceof Carta)) return false;
Carta aux=(Carta)x;
return (grupo.equals(aux.grupo)&&numero==aux.numero);
}
public boolean derecha(){return derecha;}
public void setDerecha(boolean derecha){this.derecha=derecha;}
public String significado() {return significa;}
public void setSignificado(String significa){this.significa=significa;}
public void voltea(){
String aux="";
if (grupo.equals("oro")) aux=" (4)";
if (grupo.equals("espada")) aux=" (3)";
if (grupo.equals("copa")) aux=" (2)";
if (!derecha())
try {
label.setIcon(new javax.swing.ImageIcon(new URL("http://www.cartas.22web.org/"+numero+aux+".jpg")));
} catch (Exception ex) {ex.printStackTrace();}
else try {
label.setIcon(new javax.swing.ImageIcon(new URL("http://www.cartas.22web.org/"+numero+aux+".jpg")));
} catch (Exception ex) {ex.printStackTrace(); }
}
}