- Added support for the player model inside Referee.java; high scores should now persist over a single execution of the program. - Refactored PlayerModel.java to support game logging. All games are now logged so that we can track overall progress. - Added scaffolding to allow saving and importing of PlayerModel.java. It is not yet functional, but it will be with two function implementations and then the appropriate calls.
82 lines
2.1 KiB
Java
82 lines
2.1 KiB
Java
package view;
|
|
|
|
import java.awt.Color;
|
|
import java.awt.FlowLayout;
|
|
|
|
import javax.swing.BorderFactory;
|
|
import javax.swing.ImageIcon;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.SwingUtilities;
|
|
|
|
|
|
import controller.TSPMouseListener;
|
|
|
|
import model.Board.TileColor;
|
|
import model.comPlayer.HumanPlayer;
|
|
|
|
public class TileSelectionPanel extends JPanel {
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
private final JLabel blue = new JLabel(new ImageIcon(BoardPanel.BLUE_ICON));
|
|
private final JLabel green = new JLabel(
|
|
new ImageIcon(BoardPanel.GREEN_ICON));
|
|
private final JLabel red = new JLabel(new ImageIcon(BoardPanel.RED_ICON));
|
|
private final JLabel yellow = new JLabel(new ImageIcon(
|
|
BoardPanel.YELLOW_ICON));
|
|
private final HumanPlayer pc;
|
|
|
|
public TileSelectionPanel(HumanPlayer pc) {
|
|
this.pc = pc;
|
|
|
|
initLayout();
|
|
initActions();
|
|
}
|
|
|
|
public void updateBorders() {
|
|
SwingUtilities.invokeLater(new Runnable() {
|
|
public void run() {
|
|
TileColor tile = pc.getColor();
|
|
|
|
blue.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
|
|
green.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
|
|
red.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
|
|
yellow.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
|
|
|
|
switch (tile) {
|
|
case GREEN:
|
|
green.setBorder(BorderFactory
|
|
.createLineBorder(Color.RED, 3));
|
|
break;
|
|
case RED:
|
|
red.setBorder(BorderFactory.createLineBorder(Color.RED, 3));
|
|
break;
|
|
case YELLOW:
|
|
yellow.setBorder(BorderFactory.createLineBorder(Color.RED,
|
|
3));
|
|
break;
|
|
default:
|
|
blue.setBorder(BorderFactory.createLineBorder(Color.RED, 3));
|
|
break;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
private void initActions() {
|
|
blue.addMouseListener(new TSPMouseListener(pc, this, TileColor.BLUE));
|
|
green.addMouseListener(new TSPMouseListener(pc, this, TileColor.GREEN));
|
|
red.addMouseListener(new TSPMouseListener(pc, this, TileColor.RED));
|
|
yellow.addMouseListener(new TSPMouseListener(pc, this, TileColor.YELLOW));
|
|
}
|
|
|
|
private void initLayout() {
|
|
setLayout(new FlowLayout());
|
|
add(blue);
|
|
add(green);
|
|
add(red);
|
|
add(yellow);
|
|
}
|
|
}
|