-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplayBoard.java
167 lines (124 loc) · 4.5 KB
/
displayBoard.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
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
//group 4
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.*;
public class displayBoard implements ActionListener{
public JFrame UIframe;
public JPanel boardPanel;
public JPanel backPanel;
public JPanel buttonPanel;
public JLabel inputNameLabel;
public int row = 16;
public int col = 17;
public JButton[][] step;
public JButton rollDice, saveGame, mainui, exit;
public JLabel valueLabel = new JLabel("Dice Value: - ");
public JLabel turnOrder = new JLabel("Turn: " + Player.player1Name);
public int diceValue, playerTurn;
public Icon endgoal = new ImageIcon(displayBoard.class.getResource("/images/endgoal.png"));
//public String[] names;
public displayBoard(JFrame frame, JPanel p) {
UIframe = frame;
backPanel = p;
backPanel.removeAll();
backPanel.revalidate();
backPanel.repaint();
//String[] names = {"King", "Knight", "Rook", "Bishop"};
rollDice = new JButton("Roll Dice");
saveGame = new JButton("Save Game");
mainui = new JButton("Main Menu");
exit = new JButton("Exit Game");
backPanel.setLayout(new BorderLayout());
buttonPanel = new JPanel();
buttonPanel.add(turnOrder);
buttonPanel.add(valueLabel);
buttonPanel.add(rollDice);
rollDice.setEnabled(true);
rollDice.addActionListener(this);
buttonPanel.add(saveGame);
saveGame.addActionListener(this);
buttonPanel.add(mainui);
mainui.addActionListener(this);
buttonPanel.add(exit);
exit.addActionListener(this);
backPanel.add(buttonPanel, BorderLayout.SOUTH);
boardPanel = new JPanel(new GridLayout(row, col));
step = new JButton[row][col];
//this nested for loop sets the board don't mess with it please
for (int i = 0; i < row; i++){
for (int j = 0; j < col; j++){
step[i][j] = new JButton("");
step[i][j].setBackground(Color.WHITE);
step[i][j].setBorderPainted(false);
step[i][j].setSize(10,10);
step[i][j].setEnabled(false);
boardPanel.add(step[i][j]);
}
}
new setBoard(boardPanel, step); //sets the empty pieces
new boardPieces(boardPanel, step); //sets pawns to starting position and barricade to its original position
backPanel.add(boardPanel, BorderLayout.CENTER);
/*while(String.valueOf(step[0][8].getIcon())==String.valueOf(endgoal))
{
//this loop goes on till someone wins the game/reaches the endgoal point
for(int i = 0; i < names.length; i++)
{
turnOrder.setText("turn: "+names[i]+" ");
rollDice.setEnabled(true);
rollDice.addActionListener(this);
}
}*/
}
@Override
public void actionPerformed(ActionEvent e) {
Object selected = e.getSource();
if(selected.equals(mainui)) {
int reply = JOptionPane.showConfirmDialog(
UIframe,
"Are you sure you want to go the Main Menu?",
"An Insane Question",
JOptionPane.YES_NO_OPTION);
if (reply == JOptionPane.YES_OPTION)
{
//direct to mainUI()
new mainUI(UIframe, backPanel);
}
}
if(selected.equals(exit)) {
//Direct to exit game
new exitGame(UIframe);
}
if(selected.equals(rollDice)) {
playerTurn++;
if(playerTurn > 4) {
playerTurn = 1;
}
Random x = new Random();
diceValue = x.nextInt(6) + 1;
valueLabel.setText("Dice Value: "+String.valueOf(diceValue)+" ");
//valueLabel.setText("Dice Value: "+String.valueOf(endgoal)+" ");
//rollDice.setEnabled(false);
if( playerTurn ==(1)){
turnOrder.setText("Turn: "+ Player.player1Name);
}
else if( playerTurn == (2)){
turnOrder.setText("Turn: "+ Player.player2Name);
}
else if( playerTurn == (3)){
turnOrder.setText("Turn: "+ Player.player3Name);
}
else if( playerTurn == (4)){
turnOrder.setText("Turn: "+ Player.player4Name);
}
//turnOrder.setText("Turn: Player "+playerTurn);
rollDice.setEnabled(false);
new movePawn(UIframe,step,rollDice,diceValue,playerTurn,valueLabel,turnOrder,backPanel);
}
if(selected.equals(saveGame)) {
JOptionPane.showMessageDialog(UIframe, "This feature will be added in the future Release.",
"Info", JOptionPane.WARNING_MESSAGE);
}
}
}