-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoardLayout.java
More file actions
75 lines (59 loc) · 1.82 KB
/
BoardLayout.java
File metadata and controls
75 lines (59 loc) · 1.82 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
package views.layouts;
import models.Board;
import models.Game;
import models.Player;
import models.card.*;
import views.GameView;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Observable;
import java.util.Observer;
public class BoardLayout extends JPanel implements Observer, MouseListener {
private Player player;
private Board board;
public BoardLayout(Player player, Board board) {
this.board = board;
this.player = player;
board.addObserver(this);
setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
setBackground(new Color(207, 204, 141));
setLayout(new FlowLayout(FlowLayout.CENTER));
for(Card card: board.getMinions()) {
CardBoardLayout cardLayout = new CardBoardLayout(player, card);
add(cardLayout);
}
addMouseListener(this);
}
@Override
public void update(Observable observable, Object o) {
Board board = (Board) o;
removeAll();
for (Card card: board.getMinions()) {
add(new CardBoardLayout(player, card));
}
repaint();
revalidate();
}
@Override
public void mouseClicked(MouseEvent mouseEvent) {
CardLayout cardLayout = GameView.getInstance().getSelectedCard();
if(cardLayout != null){
Game.getInstance().getCurrentPlayer().playCard(cardLayout.getCard());
GameView.getInstance().setSelectedCard(null);
}
}
@Override
public void mousePressed(MouseEvent mouseEvent) {
}
@Override
public void mouseReleased(MouseEvent mouseEvent) {
}
@Override
public void mouseEntered(MouseEvent mouseEvent) {
}
@Override
public void mouseExited(MouseEvent mouseEvent) {
}
}