-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoardPanel.java
More file actions
103 lines (88 loc) · 2.83 KB
/
Copy pathBoardPanel.java
File metadata and controls
103 lines (88 loc) · 2.83 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
import javax.imageio.ImageIO;
import javax.swing.*;
import java.io.IOException;
import java.awt.image.BufferedImage;
import java.awt.*;
/**
* A panel that displays the Game Board
*
* @Team MAGA
* @Author Gajun Young - 16440714
* @Author Royal Thomas - 16326926
* @Author Richard Otroshchenko - 16353416
*/
public class BoardPanel extends JPanel{
private static final long serialVersionUID = 1L;
private BufferedImage boardImage, die, die2; //Image of the board
private Weapons weapons;
private Players players;
private Players dummies;
//private Tokens tokens = new Tokens(); (test)
public BoardPanel(Players players, Weapons weapons, Players dummies){
this.weapons = weapons;
this.players = players;
this.dummies = dummies;
//Check if image input is available [Exceptions]
try {
boardImage = ImageIO.read(this.getClass().getResource("Board.jpg"));
}catch (IOException ex) {
System.out.println("Couldn't find image...." + ex);
}
//Set the size of the panel
setPreferredSize(new Dimension(boardImage.getHeight(), boardImage.getWidth()));
}
//Sets the board with different players & weapons
public void set(Players players, Weapons weapons, Players dummies) {
this.weapons = weapons;
this.players = players;
this.dummies = dummies;
}
//This takes the roll value as input, and draws the correct die image accordingly
public void drawDice(int roll1, int roll2){
try {
if(roll1 == 0){ //Used to hide the die image
die = null;
}else {
die = ImageIO.read(this.getClass().getResource("die" + roll1 + ".jpg"));
}
if(roll2 == 0){ //Used to hide the die image
die2 = null;
}else {
die2 = ImageIO.read(this.getClass().getResource("die" + roll2 + ".jpg"));
}
}catch(IOException ex) {
System.out.println("Couldn't find image...." + ex);
}
}
@Override
/**
* A paint component to draw tokens onto the board
*/
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 =(Graphics2D) g;
g2.drawImage(boardImage, 0, 0, boardImage.getHeight(), boardImage.getWidth(), this);
/* TileGrid grid = new TileGrid();
grid.drawGrid(g); //(test)
*/
for(Weapon weapon: weapons) {
weapon.drawWeapon(g2);
}
for(Player player: players) {
player.getToken().drawToken(g2);
}
//Draws dummies
for(Player dummy: dummies) {
dummy.getToken().drawToken(g2);
}
if(die != null){ //This is used to help ensure the die is only on-screen when needed.
g2.drawImage(die, 290, 255, die.getHeight()-90, die.getWidth()-90, this);
g2.drawImage(die2, 290, 335, die.getHeight()-90, die.getWidth()-90, this);
}
/* (test)
for(Token tok: tokens) {
tok.drawToken(g2);
}
*/
}
}