- Finished HighScoreDialog.java. Now the player can play the game repeatedly.
This commit is contained in:
@@ -13,85 +13,102 @@ public class MainFrame extends JFrame {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Referee referee;
|
||||
|
||||
public static void main(String[] args) {
|
||||
MainFrame mainFrame = new MainFrame();
|
||||
mainFrame.playGame();
|
||||
}
|
||||
|
||||
|
||||
private BoardPanel bp;
|
||||
private MessagePanel mp;
|
||||
private final Referee referee;
|
||||
private TileSelectionPanel tp;
|
||||
ScorePanel sp;
|
||||
|
||||
public MainFrame() {
|
||||
super("CS8803 Project 4");
|
||||
referee = new Referee();
|
||||
referee = new Referee(this);
|
||||
|
||||
init();
|
||||
|
||||
setDefaultCloseOperation(MainFrame.EXIT_ON_CLOSE);
|
||||
|
||||
setVisible(true);
|
||||
pack();
|
||||
setLocationRelativeTo(null);
|
||||
setVisible(true);
|
||||
|
||||
}
|
||||
|
||||
public ScorePanel getScorePanel() {
|
||||
return sp;
|
||||
}
|
||||
|
||||
public void updateBoard() {
|
||||
bp.updateIcons();
|
||||
}
|
||||
|
||||
public void updateMessage(String message) {
|
||||
mp.updateMessage(message);
|
||||
}
|
||||
|
||||
private void init() {
|
||||
ScorePanel sp = new ScorePanel(referee);
|
||||
referee.setScorePanel(sp);
|
||||
|
||||
TileSelectionPanel tp = new TileSelectionPanel(referee.getHumanPlayer());
|
||||
BoardPanel bp = new BoardPanel(referee,tp);
|
||||
sp = new ScorePanel(referee);
|
||||
|
||||
tp = new TileSelectionPanel(referee.getHumanPlayer());
|
||||
bp = new BoardPanel(referee, tp);
|
||||
referee.setBoardPanel(bp);
|
||||
|
||||
MessagePanel mp = new MessagePanel(referee);
|
||||
referee.setMessagePanel(mp);
|
||||
|
||||
//The outer wrapper allows the game board to be resized vertically.
|
||||
|
||||
mp = new MessagePanel(referee);
|
||||
|
||||
// The outer wrapper allows the game board to be resized vertically.
|
||||
JPanel vWrapper = new JPanel();
|
||||
vWrapper.setLayout(new BoxLayout(vWrapper,BoxLayout.Y_AXIS));
|
||||
|
||||
//The inner wrappers allow each sub-panel to be independently resized horizontally.
|
||||
vWrapper.setLayout(new BoxLayout(vWrapper, BoxLayout.Y_AXIS));
|
||||
|
||||
// The inner wrappers allow each sub-panel to be independently resized
|
||||
// horizontally.
|
||||
JPanel hWrapperTop = new JPanel();
|
||||
hWrapperTop.setLayout(new BoxLayout(hWrapperTop,BoxLayout.X_AXIS));
|
||||
hWrapperTop.setLayout(new BoxLayout(hWrapperTop, BoxLayout.X_AXIS));
|
||||
JPanel hWrapperMid = new JPanel();
|
||||
hWrapperMid.setLayout(new BoxLayout(hWrapperMid,BoxLayout.X_AXIS));
|
||||
hWrapperMid.setLayout(new BoxLayout(hWrapperMid, BoxLayout.X_AXIS));
|
||||
JPanel hWrapperBottom = new JPanel();
|
||||
hWrapperBottom.setLayout(new BorderLayout());
|
||||
|
||||
//Top horizontal-box wrapper contains message panel, score panel
|
||||
|
||||
// Top horizontal-box wrapper contains message panel, score panel
|
||||
hWrapperTop.add(Box.createHorizontalGlue());
|
||||
hWrapperTop.add(mp);
|
||||
hWrapperTop.add(sp);
|
||||
hWrapperTop.add(Box.createHorizontalGlue());
|
||||
|
||||
//Mid horizontal box wrapper contains board panel
|
||||
|
||||
// Mid horizontal box wrapper contains board panel
|
||||
hWrapperMid.add(Box.createHorizontalGlue());
|
||||
|
||||
|
||||
JPanel bpContainer = new JPanel();
|
||||
bpContainer.add(bp);
|
||||
hWrapperMid.add(bpContainer);
|
||||
hWrapperMid.add(Box.createHorizontalGlue());
|
||||
|
||||
//Bottom horizontal box wrapper contains tile panel
|
||||
hWrapperBottom.add(tp,BorderLayout.NORTH);
|
||||
|
||||
//the outter wrapper contains the 3 inner wrappers: top, mid, bottom
|
||||
|
||||
// Bottom horizontal box wrapper contains tile panel
|
||||
hWrapperBottom.add(tp, BorderLayout.NORTH);
|
||||
|
||||
// the outter wrapper contains the 3 inner wrappers: top, mid, bottom
|
||||
vWrapper.add(hWrapperTop);
|
||||
vWrapper.add(hWrapperMid);
|
||||
vWrapper.add(hWrapperBottom);
|
||||
|
||||
//The main JFrame contains a the outer (vertical) wrapper, in the center of a BorderLayout.
|
||||
|
||||
// The main JFrame contains a the outer (vertical) wrapper, in the
|
||||
// center of a BorderLayout.
|
||||
setLayout(new BorderLayout());
|
||||
add(vWrapper,BorderLayout.CENTER);
|
||||
|
||||
//To ensure correct size, pre-populate the score and message panels with text.
|
||||
add(vWrapper, BorderLayout.CENTER);
|
||||
|
||||
// To ensure correct size, pre-populate the score and message panels
|
||||
// with text.
|
||||
sp.updateScore(0);
|
||||
mp.updateMessage("Loading new game...");
|
||||
|
||||
|
||||
pack();
|
||||
|
||||
//Finally, update the border to show the initially selected tile color.
|
||||
|
||||
// Finally, update the border to show the initially selected tile color.
|
||||
tp.updateBorders();
|
||||
}
|
||||
|
||||
|
||||
private void playGame() {
|
||||
new Thread(referee).start();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user