-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCarta.java
More file actions
115 lines (94 loc) · 2.23 KB
/
Carta.java
File metadata and controls
115 lines (94 loc) · 2.23 KB
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
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
public class Carta extends JPanel implements MouseListener {
private String nombre;
private Image frente,
dorso;
private boolean encontrada,
estado;
private Image img;
private Tablero tab;
public Carta(String nombre, Image img, Tablero tab){
super();
this.nombre=nombre;
this.frente=new ImageIcon(img).getImage();
this.dorso=new ImageIcon("bla.jpg").getImage();
this.encontrada=false;
this.estado=false;
this.setPreferredSize(new Dimension(300,200));
this.addMouseListener(this);
this.tab=tab;
}
public void paintComponent(Graphics g){
super.paintComponent(g);
this.pintaCarta(g);
}
public void pintaCarta(Graphics g) {
g.drawImage(this.estado ? this.frente : this.dorso, 0, 0, 300, 200 ,this);
}
public String getNombre(){
return this.nombre;
}
public boolean equals(Carta carta) {
return (this.nombre.equals(carta.getNombre())) ? true : false;
}
public boolean abrir() {
if(this.estado==false) {
this.estado=true;
this.repaint();
return this.estado;
}else {
this.repaint();
return false;
}
}
public boolean cerrar() {
if(this.estado && !this.encontrada) {
this.estado=false;
this.repaint();
return true;
}else {
this.repaint();
return false;
}
}
public void parEncontrado() {
this.encontrada=true;
}
public String toString() {
return this.nombre;
}
@Override
public void mouseClicked(MouseEvent e) {
if(this.tab.getCarta1()==null){
this.tab.setCarta1(this);
this.abrir();
}else if(this.tab.getCarta2()==null){
this.tab.setCarta2(this);
this.abrir();
}else{
this.tab.comparaCartas();
this.tab.setCarta1(null);
this.tab.setCarta2(null);
this.abrir();
this.tab.setCarta1(this);
}
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
}