-The rest of the game engine. I screwed up the commit last time.

This commit is contained in:
Marshall
2012-03-31 14:18:08 -04:00
parent 2954041e89
commit 521fac6e08
45 changed files with 1006 additions and 0 deletions

120
src/view/BoardPanel.java Normal file
View File

@@ -0,0 +1,120 @@
package view;
import java.awt.GridLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.net.URL;
import javax.security.auth.Refreshable;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import model.Board;
import model.Referee;
public class BoardPanel extends JPanel implements Refreshable {
private class BoardPanelMouseListener implements MouseListener {
private final int col;
private final int row;
public BoardPanelMouseListener(int r, int c) {
row = r;
col = c;
}
@Override
public void mouseClicked(MouseEvent e) {
referee.getPlayer().setCell(row, col);
}
@Override
public void mouseEntered(MouseEvent arg0) {
// Nothing.
}
@Override
public void mouseExited(MouseEvent arg0) {
// Nothing.
}
@Override
public void mousePressed(MouseEvent arg0) {
// Nothing.
}
@Override
public void mouseReleased(MouseEvent arg0) {
// Nothing.
}
}
public static final URL BLUE_ICON = ClassLoader
.getSystemResource("img/blue.png");
public static final URL GREEN_ICON = ClassLoader
.getSystemResource("img/green.png");
public static final URL NONE_ICON = ClassLoader
.getSystemResource("img/none.png");
public static final URL RED_ICON = ClassLoader
.getSystemResource("img/red.png");
public static final URL YELLOW_ICON = ClassLoader
.getSystemResource("img/yellow.png");
/**
*
*/
private static final long serialVersionUID = 1L;
private final JLabel[][] board = new JLabel[Board.NUM_ROWS][Board.NUM_COLS];
private final Referee referee;
// private final ImageIcon[][] icons = new
// ImageIcon[Board.NUM_ROWS][Board.NUM_COLS];
public BoardPanel(Referee ref) {
referee = ref;
setLayout(new GridLayout(Board.NUM_ROWS, Board.NUM_COLS));
for (int r = 0; r < Board.NUM_ROWS; r++) {
for (int c = 0; c < Board.NUM_COLS; c++) {
board[r][c] = new JLabel(new ImageIcon(NONE_ICON));
board[r][c].addMouseListener(new BoardPanelMouseListener(r, c));
add(board[r][c]);
}
}
refresh();
}
@Override
public boolean isCurrent() {
return true;
}
@Override
public void refresh() {
for (int r = 0; r < Board.NUM_ROWS; r++) {
for (int c = 0; c < Board.NUM_COLS; c++) {
switch (referee.getTile(r, c)) {
case BLUE:
board[r][c].setIcon(new ImageIcon(BLUE_ICON));
break;
case GREEN:
board[r][c].setIcon(new ImageIcon(GREEN_ICON));
break;
case RED:
board[r][c].setIcon(new ImageIcon(RED_ICON));
break;
case YELLOW:
board[r][c].setIcon(new ImageIcon(YELLOW_ICON));
break;
default:
board[r][c].setIcon(new ImageIcon(NONE_ICON));
}
}
}
repaint();
}
}